Bils commited on
Commit
ced3fa2
·
verified ·
1 Parent(s): 4f8a245

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -41
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, temperature=0.7):
79
  try:
80
  text_pipeline = model_manager.get_llama_pipeline(model_id, HF_TOKEN)
81
 
82
- prompt = f"""Create a {duration}-second audio promo script 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
- prompt,
91
  max_new_tokens=300,
92
- temperature=temperature,
93
  do_sample=True
94
  )
95
 
96
- return parse_generated_content(result[0]["generated_text"])
 
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, speed=1.0):
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=".gradio-container {max-width: 800px !important}") as demo:
 
 
 
 
176
  gr.Markdown("""
177
  # 🎙️ AI Radio Studio
178
- *Create professional audio content in 4 easy steps*
179
  """)
180
 
181
  with gr.Tabs():
182
- with gr.Tab("1️⃣ Concept"):
183
- concept_input = gr.Textbox(label="Your Idea", placeholder="Describe your radio promo...", lines=3)
184
  with gr.Row():
185
- model_select = gr.Dropdown(
186
- choices=list(MODEL_CONFIG["llama_models"].values()),
187
- label="AI Model",
188
- value="meta-llama/Meta-Llama-3-8B-Instruct"
189
- )
190
- duration_select = gr.Slider(15, 60, 30, step=15, label="Duration (sec)")
191
- generate_btn = gr.Button("Generate Script", variant="primary")
192
-
193
- script_output = gr.Textbox(label="Voice Script", interactive=True)
194
- sound_output = gr.Textbox(label="Sound Effects", interactive=True)
195
- music_output = gr.Textbox(label="Music Style", interactive=True)
196
-
197
- with gr.Tab("2️⃣ Voice"):
198
- tts_select = gr.Dropdown(
199
- choices=list(MODEL_CONFIG["tts_models"].values()),
200
- label="Voice Model",
201
- value="tts_models/en/ljspeech/tacotron2-DDC"
202
- )
203
- voice_btn = gr.Button("Generate Voiceover", variant="primary")
204
- voice_preview = gr.Audio(label="Preview", type="filepath")
 
 
 
 
 
 
 
 
 
 
 
205
 
206
- with gr.Tab("3️⃣ Music"):
207
- music_btn = gr.Button("Generate Music", variant="primary")
 
208
  music_preview = gr.Audio(label="Preview", type="filepath")
209
 
210
- with gr.Tab("4️⃣ Mix"):
 
211
  with gr.Row():
212
- ducking_toggle = gr.Checkbox(True, label="Duck Music")
213
- duck_level = gr.Slider(0, 20, 10, label="Duck Level (dB)")
214
- mix_btn = gr.Button("Create Final Mix", variant="primary")
215
- final_mix = gr.Audio(label="Final Output", type="filepath")
 
 
216
 
217
  # Footer Section
218
  gr.Markdown("""
219
- <div style="text-align: center; margin-top: 20px; padding: 15px; border-top: 1px solid #e0e0e0;">
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>