Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -45,7 +45,6 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
|
|
45 |
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nRefined script and music suggestion:"
|
46 |
result = llama_pipeline(combined_prompt, max_new_tokens=500, do_sample=True, temperature=0.9)
|
47 |
|
48 |
-
# Parsing the output
|
49 |
generated_text = result[0]["generated_text"]
|
50 |
if "Refined script and music suggestion:" in generated_text:
|
51 |
parts = generated_text.split("Refined script and music suggestion:", 1)[-1].strip()
|
@@ -58,15 +57,13 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
|
|
58 |
except Exception as e:
|
59 |
return f"Error generating script: {e}", None
|
60 |
|
61 |
-
|
62 |
# ---------------------------------------------------------------------
|
63 |
# Voice-Over Generation Function
|
64 |
# ---------------------------------------------------------------------
|
65 |
@spaces.GPU(duration=300)
|
66 |
-
def generate_voice(script: str
|
67 |
try:
|
68 |
-
|
69 |
-
tts_model = "tts_models/en/ljspeech/tacotron2-DDC"
|
70 |
processor = AutoProcessor.from_pretrained(tts_model)
|
71 |
model = AutoModelForCausalLM.from_pretrained(tts_model)
|
72 |
|
@@ -128,63 +125,64 @@ def blend_audio(voice_path: str, music_path: str, ducking: bool):
|
|
128 |
# ---------------------------------------------------------------------
|
129 |
with gr.Blocks() as demo:
|
130 |
gr.Markdown("""
|
131 |
-
# π§ AI Promo Studio with
|
132 |
-
|
133 |
""")
|
134 |
|
135 |
-
with gr.
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
188 |
|
189 |
gr.Markdown("""
|
190 |
<hr>
|
@@ -194,4 +192,3 @@ with gr.Blocks() as demo:
|
|
194 |
""")
|
195 |
|
196 |
demo.launch(debug=True)
|
197 |
-
|
|
|
45 |
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nRefined script and music suggestion:"
|
46 |
result = llama_pipeline(combined_prompt, max_new_tokens=500, do_sample=True, temperature=0.9)
|
47 |
|
|
|
48 |
generated_text = result[0]["generated_text"]
|
49 |
if "Refined script and music suggestion:" in generated_text:
|
50 |
parts = generated_text.split("Refined script and music suggestion:", 1)[-1].strip()
|
|
|
57 |
except Exception as e:
|
58 |
return f"Error generating script: {e}", None
|
59 |
|
|
|
60 |
# ---------------------------------------------------------------------
|
61 |
# Voice-Over Generation Function
|
62 |
# ---------------------------------------------------------------------
|
63 |
@spaces.GPU(duration=300)
|
64 |
+
def generate_voice(script: str):
|
65 |
try:
|
66 |
+
tts_model = "coqui/xtts-en-ljspeech-v2"
|
|
|
67 |
processor = AutoProcessor.from_pretrained(tts_model)
|
68 |
model = AutoModelForCausalLM.from_pretrained(tts_model)
|
69 |
|
|
|
125 |
# ---------------------------------------------------------------------
|
126 |
with gr.Blocks() as demo:
|
127 |
gr.Markdown("""
|
128 |
+
# π§ AI Promo Studio with Pages π
|
129 |
+
Follow a step-by-step process to create amazing promos with AI.
|
130 |
""")
|
131 |
|
132 |
+
with gr.Tabs():
|
133 |
+
# Step 1: Script Generation
|
134 |
+
with gr.Tab("Step 1: Generate Script"):
|
135 |
+
user_prompt = gr.Textbox(label="Promo Idea", placeholder="E.g., A 30-second promo for a morning show.")
|
136 |
+
llama_model_id = gr.Textbox(label="Llama Model ID", value="meta-llama/Meta-Llama-3-8B-Instruct")
|
137 |
+
duration = gr.Slider(label="Duration (seconds)", minimum=15, maximum=60, step=15, value=30)
|
138 |
+
generate_script_button = gr.Button("Generate Script")
|
139 |
+
script_output = gr.Textbox(label="Generated Script")
|
140 |
+
music_suggestion_output = gr.Textbox(label="Music Suggestion")
|
141 |
+
|
142 |
+
generate_script_button.click(
|
143 |
+
fn=generate_script,
|
144 |
+
inputs=[user_prompt, llama_model_id, hf_token, duration],
|
145 |
+
outputs=[script_output, music_suggestion_output],
|
146 |
+
)
|
147 |
+
|
148 |
+
# Step 2: Voice Generation
|
149 |
+
with gr.Tab("Step 2: Generate Voice"):
|
150 |
+
script_input = gr.Textbox(label="Script for Voice", interactive=False)
|
151 |
+
generate_voice_button = gr.Button("Generate Voice")
|
152 |
+
voice_output = gr.Audio(label="Generated Voice", type="filepath")
|
153 |
+
|
154 |
+
generate_voice_button.click(
|
155 |
+
fn=generate_voice,
|
156 |
+
inputs=[script_input],
|
157 |
+
outputs=[voice_output],
|
158 |
+
)
|
159 |
+
|
160 |
+
# Step 3: Music Generation
|
161 |
+
with gr.Tab("Step 3: Generate Music"):
|
162 |
+
music_prompt_input = gr.Textbox(label="Music Suggestion Prompt", interactive=False)
|
163 |
+
audio_length = gr.Slider(label="Music Length (tokens)", minimum=128, maximum=1024, step=64, value=512)
|
164 |
+
generate_music_button = gr.Button("Generate Music")
|
165 |
+
music_output = gr.Audio(label="Generated Music", type="filepath")
|
166 |
+
|
167 |
+
generate_music_button.click(
|
168 |
+
fn=generate_music,
|
169 |
+
inputs=[music_prompt_input, audio_length],
|
170 |
+
outputs=[music_output],
|
171 |
+
)
|
172 |
+
|
173 |
+
# Step 4: Blend Audio
|
174 |
+
with gr.Tab("Step 4: Blend Audio"):
|
175 |
+
voice_path = gr.Audio(label="Voice File", type="filepath")
|
176 |
+
music_path = gr.Audio(label="Music File", type="filepath")
|
177 |
+
ducking = gr.Checkbox(label="Enable Ducking", value=True)
|
178 |
+
blend_button = gr.Button("Blend Audio")
|
179 |
+
final_output = gr.Audio(label="Final Promo Audio", type="filepath")
|
180 |
+
|
181 |
+
blend_button.click(
|
182 |
+
fn=blend_audio,
|
183 |
+
inputs=[voice_path, music_path, ducking],
|
184 |
+
outputs=[final_output],
|
185 |
+
)
|
186 |
|
187 |
gr.Markdown("""
|
188 |
<hr>
|
|
|
192 |
""")
|
193 |
|
194 |
demo.launch(debug=True)
|
|