Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,9 +10,8 @@ from transformers import (
|
|
10 |
)
|
11 |
from scipy.io.wavfile import write
|
12 |
from pydub import AudioSegment
|
13 |
-
from pydub.playback import play
|
14 |
-
import tempfile
|
15 |
from dotenv import load_dotenv
|
|
|
16 |
import spaces
|
17 |
|
18 |
# Load environment variables
|
@@ -117,26 +116,10 @@ def blend_audio(voice_path: str, music_path: str, ducking: bool):
|
|
117 |
# ---------------------------------------------------------------------
|
118 |
# Gradio Interface
|
119 |
# ---------------------------------------------------------------------
|
120 |
-
def process_all(user_prompt, llama_model_id, duration, audio_length, speaker, ducking):
|
121 |
-
script, music_suggestion = generate_script(user_prompt, llama_model_id, hf_token, duration)
|
122 |
-
if "Error" in script:
|
123 |
-
return script, None
|
124 |
-
|
125 |
-
voice_path = generate_voice(script, speaker)
|
126 |
-
if "Error" in voice_path:
|
127 |
-
return voice_path, None
|
128 |
-
|
129 |
-
music_path = generate_music(music_suggestion, audio_length)
|
130 |
-
if "Error" in music_path:
|
131 |
-
return music_path, None
|
132 |
-
|
133 |
-
final_audio = blend_audio(voice_path, music_path, ducking)
|
134 |
-
return f"Script:\n{script}\n\nMusic Suggestion:\n{music_suggestion}", final_audio
|
135 |
-
|
136 |
with gr.Blocks() as demo:
|
137 |
gr.Markdown("""
|
138 |
-
# π§ AI Promo Studio with Script, Voice, Music, and Mixing π
|
139 |
-
Generate
|
140 |
""")
|
141 |
|
142 |
with gr.Row():
|
@@ -147,14 +130,49 @@ with gr.Blocks() as demo:
|
|
147 |
speaker = gr.Textbox(label="Voice Style (optional)", placeholder="E.g., male, female, or neutral.")
|
148 |
ducking = gr.Checkbox(label="Enable Ducking", value=True)
|
149 |
|
150 |
-
|
151 |
script_output = gr.Textbox(label="Generated Script and Music Suggestion")
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
)
|
159 |
|
160 |
gr.Markdown("""
|
@@ -165,4 +183,3 @@ with gr.Blocks() as demo:
|
|
165 |
""")
|
166 |
|
167 |
demo.launch(debug=True)
|
168 |
-
|
|
|
10 |
)
|
11 |
from scipy.io.wavfile import write
|
12 |
from pydub import AudioSegment
|
|
|
|
|
13 |
from dotenv import load_dotenv
|
14 |
+
import tempfile
|
15 |
import spaces
|
16 |
|
17 |
# Load environment variables
|
|
|
116 |
# ---------------------------------------------------------------------
|
117 |
# Gradio Interface
|
118 |
# ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
with gr.Blocks() as demo:
|
120 |
gr.Markdown("""
|
121 |
+
# π§ AI Promo Studio with Step-by-Step Script, Voice, Music, and Mixing π
|
122 |
+
Generate and mix radio promos effortlessly with AI tools!
|
123 |
""")
|
124 |
|
125 |
with gr.Row():
|
|
|
130 |
speaker = gr.Textbox(label="Voice Style (optional)", placeholder="E.g., male, female, or neutral.")
|
131 |
ducking = gr.Checkbox(label="Enable Ducking", value=True)
|
132 |
|
133 |
+
generate_script_button = gr.Button("Generate Script")
|
134 |
script_output = gr.Textbox(label="Generated Script and Music Suggestion")
|
135 |
+
generate_voice_button = gr.Button("Generate Voice")
|
136 |
+
voice_output = gr.Audio(label="Generated Voice", type="filepath")
|
137 |
+
generate_music_button = gr.Button("Generate Music")
|
138 |
+
music_output = gr.Audio(label="Generated Music", type="filepath")
|
139 |
+
blend_button = gr.Button("Blend Audio")
|
140 |
+
final_output = gr.Audio(label="Final Promo Audio", type="filepath")
|
141 |
+
|
142 |
+
def step_generate_script(user_prompt, llama_model_id, duration):
|
143 |
+
return generate_script(user_prompt, llama_model_id, hf_token, duration)
|
144 |
+
|
145 |
+
def step_generate_voice(script, speaker):
|
146 |
+
return generate_voice(script, speaker)
|
147 |
+
|
148 |
+
def step_generate_music(music_suggestion, audio_length):
|
149 |
+
return generate_music(music_suggestion, audio_length)
|
150 |
|
151 |
+
def step_blend_audio(voice_path, music_path, ducking):
|
152 |
+
return blend_audio(voice_path, music_path, ducking)
|
153 |
+
|
154 |
+
generate_script_button.click(
|
155 |
+
fn=step_generate_script,
|
156 |
+
inputs=[user_prompt, llama_model_id, duration],
|
157 |
+
outputs=[script_output],
|
158 |
+
)
|
159 |
+
|
160 |
+
generate_voice_button.click(
|
161 |
+
fn=step_generate_voice,
|
162 |
+
inputs=[script_output, speaker],
|
163 |
+
outputs=[voice_output],
|
164 |
+
)
|
165 |
+
|
166 |
+
generate_music_button.click(
|
167 |
+
fn=step_generate_music,
|
168 |
+
inputs=[script_output, audio_length],
|
169 |
+
outputs=[music_output],
|
170 |
+
)
|
171 |
+
|
172 |
+
blend_button.click(
|
173 |
+
fn=step_blend_audio,
|
174 |
+
inputs=[voice_output, music_output, ducking],
|
175 |
+
outputs=[final_output],
|
176 |
)
|
177 |
|
178 |
gr.Markdown("""
|
|
|
183 |
""")
|
184 |
|
185 |
demo.launch(debug=True)
|
|