Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,20 +38,23 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
|
|
38 |
|
39 |
system_prompt = (
|
40 |
f"You are an expert radio imaging producer specializing in sound design and music. "
|
41 |
-
f"Based on the user's concept and the selected duration of {duration} seconds,
|
42 |
-
f"
|
|
|
|
|
43 |
)
|
44 |
|
45 |
-
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\
|
46 |
-
result = llama_pipeline(combined_prompt, max_new_tokens=
|
47 |
|
48 |
-
generated_text = result[0]["generated_text"].split("
|
49 |
-
if "Music
|
50 |
-
script,
|
51 |
-
|
52 |
-
|
|
|
53 |
except Exception as e:
|
54 |
-
return f"Error generating script: {e}",
|
55 |
|
56 |
# ---------------------------------------------------------------------
|
57 |
# Voice-Over Generation Function
|
@@ -122,13 +125,14 @@ def blend_audio(voice_path: str, music_path: str, ducking: bool):
|
|
122 |
# ---------------------------------------------------------------------
|
123 |
# Gradio Interface
|
124 |
# ---------------------------------------------------------------------
|
125 |
-
|
126 |
gr.Markdown("""
|
127 |
-
# π§ AI Promo Studio
|
128 |
-
Generate
|
129 |
""")
|
130 |
|
131 |
with gr.Tabs():
|
|
|
132 |
with gr.Tab("Step 1: Generate Script"):
|
133 |
with gr.Row():
|
134 |
user_prompt = gr.Textbox(label="Promo Idea", placeholder="E.g., A 30-second promo for a morning show.")
|
@@ -136,13 +140,14 @@ with gr.Blocks() as demo:
|
|
136 |
duration = gr.Slider(label="Duration (seconds)", minimum=15, maximum=60, step=15, value=30)
|
137 |
|
138 |
generate_script_button = gr.Button("Generate Script")
|
139 |
-
script_output = gr.Textbox(label="Generated Script")
|
140 |
-
|
|
|
141 |
|
142 |
generate_script_button.click(
|
143 |
fn=lambda user_prompt, model_id, duration: generate_script(user_prompt, model_id, hf_token, duration),
|
144 |
inputs=[user_prompt, llama_model_id, duration],
|
145 |
-
outputs=[script_output, music_suggestion_output],
|
146 |
)
|
147 |
|
148 |
with gr.Tab("Step 2: Generate Voice"):
|
|
|
38 |
|
39 |
system_prompt = (
|
40 |
f"You are an expert radio imaging producer specializing in sound design and music. "
|
41 |
+
f"Based on the user's concept and the selected duration of {duration} seconds, generate: "
|
42 |
+
f"1. A concise voice-over script. "
|
43 |
+
f"2. Suggestions for sound design. "
|
44 |
+
f"3. Music styles or track recommendations."
|
45 |
)
|
46 |
|
47 |
+
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nOutput:"
|
48 |
+
result = llama_pipeline(combined_prompt, max_new_tokens=300, do_sample=True, temperature=0.8)
|
49 |
|
50 |
+
generated_text = result[0]["generated_text"].split("Output:")[-1].strip()
|
51 |
+
if "Suggestions:" in generated_text and "Music Recommendations:" in generated_text:
|
52 |
+
script, rest = generated_text.split("Suggestions:", 1)
|
53 |
+
sound_design, music_suggestion = rest.split("Music Recommendations:", 1)
|
54 |
+
return script.strip(), sound_design.strip(), music_suggestion.strip()
|
55 |
+
return "Error: Could not parse output.", "", ""
|
56 |
except Exception as e:
|
57 |
+
return f"Error generating script: {e}", "", ""
|
58 |
|
59 |
# ---------------------------------------------------------------------
|
60 |
# Voice-Over Generation Function
|
|
|
125 |
# ---------------------------------------------------------------------
|
126 |
# Gradio Interface
|
127 |
# ---------------------------------------------------------------------
|
128 |
+
ith gr.Blocks() as demo:
|
129 |
gr.Markdown("""
|
130 |
+
# π§ AI Promo Studio π
|
131 |
+
Generate scripts, sound design, and music suggestions with ease.
|
132 |
""")
|
133 |
|
134 |
with gr.Tabs():
|
135 |
+
# Step 1: Generate Script
|
136 |
with gr.Tab("Step 1: Generate Script"):
|
137 |
with gr.Row():
|
138 |
user_prompt = gr.Textbox(label="Promo Idea", placeholder="E.g., A 30-second promo for a morning show.")
|
|
|
140 |
duration = gr.Slider(label="Duration (seconds)", minimum=15, maximum=60, step=15, value=30)
|
141 |
|
142 |
generate_script_button = gr.Button("Generate Script")
|
143 |
+
script_output = gr.Textbox(label="Generated Voice-Over Script", lines=5)
|
144 |
+
sound_design_output = gr.Textbox(label="Sound Design Ideas", lines=3)
|
145 |
+
music_suggestion_output = gr.Textbox(label="Music Suggestions", lines=3)
|
146 |
|
147 |
generate_script_button.click(
|
148 |
fn=lambda user_prompt, model_id, duration: generate_script(user_prompt, model_id, hf_token, duration),
|
149 |
inputs=[user_prompt, llama_model_id, duration],
|
150 |
+
outputs=[script_output, sound_design_output, music_suggestion_output],
|
151 |
)
|
152 |
|
153 |
with gr.Tab("Step 2: Generate Voice"):
|