Bils commited on
Commit
3020f35
·
verified ·
1 Parent(s): 94f073d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -43,26 +43,26 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
43
  combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nRefined script and music suggestion:"
44
  result = llama_pipeline(combined_prompt, max_new_tokens=500, do_sample=True, temperature=0.9)
45
 
46
- # Check if the output contains "Music Suggestion:"
47
  generated_text = result[0]["generated_text"]
48
- if "Music Suggestion:" in generated_text:
49
- script, music_suggestion = generated_text.split("Music Suggestion:", 1)
50
- return script.strip(), music_suggestion.strip()
 
 
51
  else:
52
- # Return the full text as the script and indicate no music suggestion was found
53
  return generated_text.strip(), "No specific music suggestion found."
54
  except Exception as e:
55
  return f"Error generating script: {e}", None
56
 
57
-
58
  # ---------------------------------------------------------------------
59
  # Voice-Over Generation Function
60
  # ---------------------------------------------------------------------
61
  @spaces.GPU(duration=300)
62
- def generate_voice(script: str, speaker: str):
63
  try:
64
- # Replace with your chosen TTS model
65
- tts_model = "coqui/XTTS-v2"
66
  processor = AutoProcessor.from_pretrained(tts_model)
67
  model = AutoModelForCausalLM.from_pretrained(tts_model)
68
 
@@ -145,26 +145,38 @@ with gr.Blocks() as demo:
145
  blend_button = gr.Button("Blend Audio")
146
  final_output = gr.Audio(label="Final Promo Audio", type="filepath")
147
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  generate_script_button.click(
149
- fn=lambda user_prompt, llama_model_id, duration: generate_script(user_prompt, llama_model_id, hf_token, duration),
150
  inputs=[user_prompt, llama_model_id, duration],
151
  outputs=[script_output],
152
  )
153
 
154
  generate_voice_button.click(
155
- fn=generate_voice,
156
  inputs=[script_output, speaker],
157
  outputs=[voice_output],
158
  )
159
 
160
  generate_music_button.click(
161
- fn=generate_music,
162
  inputs=[script_output, audio_length],
163
  outputs=[music_output],
164
  )
165
 
166
  blend_button.click(
167
- fn=blend_audio,
168
  inputs=[voice_output, music_output, ducking],
169
  outputs=[final_output],
170
  )
 
43
  combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nRefined script and music suggestion:"
44
  result = llama_pipeline(combined_prompt, max_new_tokens=500, do_sample=True, temperature=0.9)
45
 
46
+ # Extract the script and music suggestion
47
  generated_text = result[0]["generated_text"]
48
+ if "Music suggestion:" in generated_text:
49
+ parts = generated_text.split("Music suggestion:", 1)
50
+ script = parts[0].strip()
51
+ music_suggestion = parts[1].strip()
52
+ return script, music_suggestion
53
  else:
 
54
  return generated_text.strip(), "No specific music suggestion found."
55
  except Exception as e:
56
  return f"Error generating script: {e}", None
57
 
 
58
  # ---------------------------------------------------------------------
59
  # Voice-Over Generation Function
60
  # ---------------------------------------------------------------------
61
  @spaces.GPU(duration=300)
62
+ def generate_voice(script: str, speaker: str = "default"):
63
  try:
64
+ # Replace with a real TTS model
65
+ tts_model = "tts_models/en/ljspeech/tacotron2-DDC"
66
  processor = AutoProcessor.from_pretrained(tts_model)
67
  model = AutoModelForCausalLM.from_pretrained(tts_model)
68
 
 
145
  blend_button = gr.Button("Blend Audio")
146
  final_output = gr.Audio(label="Final Promo Audio", type="filepath")
147
 
148
+ def step_generate_script(user_prompt, llama_model_id, duration):
149
+ return generate_script(user_prompt, llama_model_id, hf_token, duration)
150
+
151
+ def step_generate_voice(script, speaker):
152
+ return generate_voice(script, speaker)
153
+
154
+ def step_generate_music(music_suggestion, audio_length):
155
+ return generate_music(music_suggestion, audio_length)
156
+
157
+ def step_blend_audio(voice_path, music_path, ducking):
158
+ return blend_audio(voice_path, music_path, ducking)
159
+
160
  generate_script_button.click(
161
+ fn=step_generate_script,
162
  inputs=[user_prompt, llama_model_id, duration],
163
  outputs=[script_output],
164
  )
165
 
166
  generate_voice_button.click(
167
+ fn=step_generate_voice,
168
  inputs=[script_output, speaker],
169
  outputs=[voice_output],
170
  )
171
 
172
  generate_music_button.click(
173
+ fn=step_generate_music,
174
  inputs=[script_output, audio_length],
175
  outputs=[music_output],
176
  )
177
 
178
  blend_button.click(
179
+ fn=step_blend_audio,
180
  inputs=[voice_output, music_output, ducking],
181
  outputs=[final_output],
182
  )