Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,25 +75,26 @@ model_manager = ModelManager()
|
|
| 75 |
# Core Functions
|
| 76 |
# -------------------------------
|
| 77 |
@spaces.GPU
|
| 78 |
-
def generate_script(user_prompt, model_id, duration
|
| 79 |
try:
|
| 80 |
text_pipeline = model_manager.get_llama_pipeline(model_id, HF_TOKEN)
|
| 81 |
|
| 82 |
-
|
| 83 |
-
1. Voice Script: [
|
| 84 |
2. Sound Design: [3-5 effects]
|
| 85 |
-
3. Music: [
|
| 86 |
|
| 87 |
Concept: {user_prompt}"""
|
| 88 |
|
| 89 |
result = text_pipeline(
|
| 90 |
-
|
| 91 |
max_new_tokens=300,
|
| 92 |
-
temperature=
|
| 93 |
do_sample=True
|
| 94 |
)
|
| 95 |
|
| 96 |
-
|
|
|
|
| 97 |
except Exception as e:
|
| 98 |
return f"Error: {str(e)}", "", ""
|
| 99 |
|
|
@@ -123,7 +124,7 @@ def parse_generated_content(text):
|
|
| 123 |
return sections["Voice Script"].strip(), sections["Sound Design"].strip(), sections["Music"].strip()
|
| 124 |
|
| 125 |
@spaces.GPU
|
| 126 |
-
def generate_voice(script, tts_model
|
| 127 |
try:
|
| 128 |
if not script.strip():
|
| 129 |
return "Error: No script provided"
|
|
@@ -170,53 +171,72 @@ def blend_audio(voice_path, music_path, ducking=True, duck_level=10):
|
|
| 170 |
return f"Error: {str(e)}"
|
| 171 |
|
| 172 |
# -------------------------------
|
| 173 |
-
# Gradio Interface
|
| 174 |
# -------------------------------
|
| 175 |
-
with gr.Blocks(title="AI Radio Studio", css="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
gr.Markdown("""
|
| 177 |
# 🎙️ AI Radio Studio
|
| 178 |
-
*
|
| 179 |
""")
|
| 180 |
|
| 181 |
with gr.Tabs():
|
| 182 |
-
|
| 183 |
-
|
| 184 |
with gr.Row():
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
-
|
| 207 |
-
|
|
|
|
| 208 |
music_preview = gr.Audio(label="Preview", type="filepath")
|
| 209 |
|
| 210 |
-
|
|
|
|
| 211 |
with gr.Row():
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
| 216 |
|
| 217 |
# Footer Section
|
| 218 |
gr.Markdown("""
|
| 219 |
-
<div style="text-align: center; margin-top:
|
| 220 |
<p style="font-size: 0.9em; color: #666;">
|
| 221 |
Created with ❤️ by <a href="https://bilsimaging.com" target="_blank">bilsimaging.com</a>
|
| 222 |
</p>
|
|
|
|
| 75 |
# Core Functions
|
| 76 |
# -------------------------------
|
| 77 |
@spaces.GPU
|
| 78 |
+
def generate_script(user_prompt, model_id, duration):
|
| 79 |
try:
|
| 80 |
text_pipeline = model_manager.get_llama_pipeline(model_id, HF_TOKEN)
|
| 81 |
|
| 82 |
+
system_prompt = f"""Create a {duration}-second audio promo with these elements:
|
| 83 |
+
1. Voice Script: [Clear narration]
|
| 84 |
2. Sound Design: [3-5 effects]
|
| 85 |
+
3. Music: [Genre/tempo]
|
| 86 |
|
| 87 |
Concept: {user_prompt}"""
|
| 88 |
|
| 89 |
result = text_pipeline(
|
| 90 |
+
system_prompt,
|
| 91 |
max_new_tokens=300,
|
| 92 |
+
temperature=0.7,
|
| 93 |
do_sample=True
|
| 94 |
)
|
| 95 |
|
| 96 |
+
generated_text = result[0]["generated_text"]
|
| 97 |
+
return parse_generated_content(generated_text)
|
| 98 |
except Exception as e:
|
| 99 |
return f"Error: {str(e)}", "", ""
|
| 100 |
|
|
|
|
| 124 |
return sections["Voice Script"].strip(), sections["Sound Design"].strip(), sections["Music"].strip()
|
| 125 |
|
| 126 |
@spaces.GPU
|
| 127 |
+
def generate_voice(script, tts_model):
|
| 128 |
try:
|
| 129 |
if not script.strip():
|
| 130 |
return "Error: No script provided"
|
|
|
|
| 171 |
return f"Error: {str(e)}"
|
| 172 |
|
| 173 |
# -------------------------------
|
| 174 |
+
# Gradio Interface (Second UI Version)
|
| 175 |
# -------------------------------
|
| 176 |
+
with gr.Blocks(title="AI Radio Studio", css="""
|
| 177 |
+
.gradio-container {max-width: 800px; margin: auto;}
|
| 178 |
+
.tab-item {padding: 20px; border-radius: 10px;}
|
| 179 |
+
""") as demo:
|
| 180 |
+
|
| 181 |
gr.Markdown("""
|
| 182 |
# 🎙️ AI Radio Studio
|
| 183 |
+
*Professional Audio Production Made Simple*
|
| 184 |
""")
|
| 185 |
|
| 186 |
with gr.Tabs():
|
| 187 |
+
# Concept Tab
|
| 188 |
+
with gr.Tab("🎯 Concept"):
|
| 189 |
with gr.Row():
|
| 190 |
+
with gr.Column():
|
| 191 |
+
concept_input = gr.Textbox(
|
| 192 |
+
label="Your Idea",
|
| 193 |
+
placeholder="Describe your audio project...",
|
| 194 |
+
lines=3
|
| 195 |
+
)
|
| 196 |
+
model_select = gr.Dropdown(
|
| 197 |
+
choices=list(MODEL_CONFIG["llama_models"].values()),
|
| 198 |
+
label="AI Model",
|
| 199 |
+
value="meta-llama/Meta-Llama-3-8B-Instruct"
|
| 200 |
+
)
|
| 201 |
+
duration_select = gr.Slider(15, 60, 30, step=15, label="Duration (seconds)")
|
| 202 |
+
generate_btn = gr.Button("Generate Script", variant="primary")
|
| 203 |
+
|
| 204 |
+
with gr.Column():
|
| 205 |
+
script_output = gr.Textbox(label="Voice Script", interactive=True)
|
| 206 |
+
sound_output = gr.Textbox(label="Sound Design", interactive=True)
|
| 207 |
+
music_output = gr.Textbox(label="Music Suggestions", interactive=True)
|
| 208 |
+
|
| 209 |
+
# Voice Tab
|
| 210 |
+
with gr.Tab("🗣️ Voice"):
|
| 211 |
+
with gr.Row():
|
| 212 |
+
with gr.Column():
|
| 213 |
+
tts_select = gr.Dropdown(
|
| 214 |
+
choices=list(MODEL_CONFIG["tts_models"].values()),
|
| 215 |
+
label="Voice Model",
|
| 216 |
+
value="tts_models/en/ljspeech/tacotron2-DDC"
|
| 217 |
+
)
|
| 218 |
+
voice_btn = gr.Button("Generate Voiceover", variant="primary")
|
| 219 |
+
with gr.Column():
|
| 220 |
+
voice_preview = gr.Audio(label="Preview", type="filepath")
|
| 221 |
|
| 222 |
+
# Music Tab
|
| 223 |
+
with gr.Tab("🎵 Music"):
|
| 224 |
+
music_btn = gr.Button("Generate Music Track", variant="primary")
|
| 225 |
music_preview = gr.Audio(label="Preview", type="filepath")
|
| 226 |
|
| 227 |
+
# Mix Tab
|
| 228 |
+
with gr.Tab("🔊 Mix"):
|
| 229 |
with gr.Row():
|
| 230 |
+
with gr.Column():
|
| 231 |
+
ducking_toggle = gr.Checkbox(True, label="Enable Voice Ducking")
|
| 232 |
+
duck_level = gr.Slider(0, 20, 10, label="Ducking Level (dB)")
|
| 233 |
+
mix_btn = gr.Button("Create Final Mix", variant="primary")
|
| 234 |
+
with gr.Column():
|
| 235 |
+
final_mix = gr.Audio(label="Final Output", type="filepath")
|
| 236 |
|
| 237 |
# Footer Section
|
| 238 |
gr.Markdown("""
|
| 239 |
+
<div style="text-align: center; margin-top: 30px; padding: 15px; border-top: 1px solid #e0e0e0;">
|
| 240 |
<p style="font-size: 0.9em; color: #666;">
|
| 241 |
Created with ❤️ by <a href="https://bilsimaging.com" target="_blank">bilsimaging.com</a>
|
| 242 |
</p>
|