Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,14 +43,9 @@ 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=200, do_sample=True, temperature=0.9)
|
45 |
|
46 |
-
generated_text = result[0]["generated_text"]
|
47 |
-
|
48 |
-
|
49 |
-
if "Music Suggestion:" in generated_text:
|
50 |
-
script, music_suggestion = generated_text.split("Music Suggestion:", 1)
|
51 |
-
return script.strip(), music_suggestion.strip()
|
52 |
-
else:
|
53 |
-
return "Error: 'Music Suggestion:' delimiter not found in the generated text.", None
|
54 |
except Exception as e:
|
55 |
return f"Error generating script: {e}", None
|
56 |
|
@@ -60,12 +55,16 @@ def generate_script(user_prompt: str, model_id: str, token: str, duration: int):
|
|
60 |
@spaces.GPU(duration=300)
|
61 |
def generate_voice(script: str, speaker: str):
|
62 |
try:
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
-
|
|
|
66 |
|
67 |
output_path = f"{tempfile.gettempdir()}/generated_voice.wav"
|
68 |
-
|
69 |
return output_path
|
70 |
except Exception as e:
|
71 |
return f"Error generating voice-over: {e}"
|
@@ -141,8 +140,8 @@ with gr.Blocks() as demo:
|
|
141 |
final_output = gr.Audio(label="Final Promo Audio", type="filepath")
|
142 |
|
143 |
generate_script_button.click(
|
144 |
-
fn=generate_script,
|
145 |
-
inputs=[user_prompt, llama_model_id,
|
146 |
outputs=[script_output],
|
147 |
)
|
148 |
|
|
|
43 |
combined_prompt = f"{system_prompt}\nUser concept: {user_prompt}\nRefined script and music suggestion:"
|
44 |
result = llama_pipeline(combined_prompt, max_new_tokens=200, do_sample=True, temperature=0.9)
|
45 |
|
46 |
+
generated_text = result[0]["generated_text"].split("Refined script and music suggestion:")[-1].strip()
|
47 |
+
script, music_suggestion = generated_text.split("Music Suggestion:")
|
48 |
+
return script.strip(), music_suggestion.strip()
|
|
|
|
|
|
|
|
|
|
|
49 |
except Exception as e:
|
50 |
return f"Error generating script: {e}", None
|
51 |
|
|
|
55 |
@spaces.GPU(duration=300)
|
56 |
def generate_voice(script: str, speaker: str):
|
57 |
try:
|
58 |
+
# Replace with your chosen TTS model
|
59 |
+
tts_model = "coqui/XTTS-v2"
|
60 |
+
processor = AutoProcessor.from_pretrained(tts_model)
|
61 |
+
model = AutoModelForCausalLM.from_pretrained(tts_model)
|
62 |
|
63 |
+
inputs = processor(script, return_tensors="pt")
|
64 |
+
speech = model.generate(**inputs)
|
65 |
|
66 |
output_path = f"{tempfile.gettempdir()}/generated_voice.wav"
|
67 |
+
write(output_path, 22050, speech.cpu().numpy())
|
68 |
return output_path
|
69 |
except Exception as e:
|
70 |
return f"Error generating voice-over: {e}"
|
|
|
140 |
final_output = gr.Audio(label="Final Promo Audio", type="filepath")
|
141 |
|
142 |
generate_script_button.click(
|
143 |
+
fn=lambda user_prompt, llama_model_id, duration: generate_script(user_prompt, llama_model_id, hf_token, duration),
|
144 |
+
inputs=[user_prompt, llama_model_id, duration],
|
145 |
outputs=[script_output],
|
146 |
)
|
147 |
|