Bils commited on
Commit
9fc7b58
Β·
verified Β·
1 Parent(s): c64dd82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -61
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, speaker: str = "default"):
67
  try:
68
- # Replace with a real TTS model
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 Step-by-Step Script, Voice, Music, and Mixing πŸš€
132
- Generate and mix radio promos effortlessly with AI tools!
133
  """)
134
 
135
- with gr.Row():
136
- user_prompt = gr.Textbox(label="Promo Idea", placeholder="E.g., A 30-second promo for a morning show.")
137
- llama_model_id = gr.Textbox(label="Llama Model ID", value="meta-llama/Meta-Llama-3-8B-Instruct")
138
- duration = gr.Slider(label="Duration (seconds)", minimum=15, maximum=60, step=15, value=30)
139
- audio_length = gr.Slider(label="Music Length (tokens)", minimum=128, maximum=1024, step=64, value=512)
140
- speaker = gr.Textbox(label="Voice Style (optional)", placeholder="E.g., male, female, or neutral.")
141
- ducking = gr.Checkbox(label="Enable Ducking", value=True)
142
-
143
- generate_script_button = gr.Button("Generate Script")
144
- script_output = gr.Textbox(label="Generated Script")
145
- music_suggestion_output = gr.Textbox(label="Music Suggestion")
146
- generate_voice_button = gr.Button("Generate Voice")
147
- voice_output = gr.Audio(label="Generated Voice", type="filepath")
148
- generate_music_button = gr.Button("Generate Music")
149
- music_output = gr.Audio(label="Generated Music", type="filepath")
150
- blend_button = gr.Button("Blend Audio")
151
- final_output = gr.Audio(label="Final Promo Audio", type="filepath")
152
-
153
- def step_generate_script(user_prompt, llama_model_id, duration):
154
- return generate_script(user_prompt, llama_model_id, hf_token, duration)
155
-
156
- def step_generate_voice(script, speaker):
157
- return generate_voice(script, speaker)
158
-
159
- def step_generate_music(music_suggestion, audio_length):
160
- return generate_music(music_suggestion, audio_length)
161
-
162
- def step_blend_audio(voice_path, music_path, ducking):
163
- return blend_audio(voice_path, music_path, ducking)
164
-
165
- generate_script_button.click(
166
- fn=step_generate_script,
167
- inputs=[user_prompt, llama_model_id, duration],
168
- outputs=[script_output, music_suggestion_output],
169
- )
170
-
171
- generate_voice_button.click(
172
- fn=step_generate_voice,
173
- inputs=[script_output, speaker],
174
- outputs=[voice_output],
175
- )
176
-
177
- generate_music_button.click(
178
- fn=step_generate_music,
179
- inputs=[music_suggestion_output, audio_length],
180
- outputs=[music_output],
181
- )
182
-
183
- blend_button.click(
184
- fn=step_blend_audio,
185
- inputs=[voice_output, music_output, ducking],
186
- outputs=[final_output],
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)