Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -230,7 +230,7 @@ def generate_audio(script_output, voice1, voice2, num_hosts, temperature, top_p,
|
|
230 |
except Exception as e:
|
231 |
logger.error(f"Error generating speech: {str(e)}")
|
232 |
return None
|
233 |
-
|
234 |
@callback(
|
235 |
Output("script-output", "value"),
|
236 |
Output("audio-output", "children"),
|
@@ -342,31 +342,31 @@ def combined_callback(generate_script_clicks, generate_audio_clicks, advanced_se
|
|
342 |
logger.error(f"Error generating podcast script: {str(e)}")
|
343 |
return f"Error: {str(e)}", dash.no_update, dash.no_update, dash.no_update, "", ""
|
344 |
|
345 |
-
elif trigger_id == "generate-audio-btn":
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
audio_buffer = generate_audio(script_output, voice1, voice2, num_hosts, temperature, top_p, repetition_penalty, max_new_tokens)
|
350 |
-
|
351 |
-
if audio_buffer is not None:
|
352 |
-
# Convert to base64 for audio playback
|
353 |
-
audio_base64 = base64.b64encode(audio_buffer.getvalue()).decode('utf-8')
|
354 |
-
src = f"data:audio/wav;base64,{audio_base64}"
|
355 |
-
|
356 |
-
# Log audio file size
|
357 |
-
logger.info(f"Generated audio file size: {len(audio_base64)} bytes")
|
358 |
|
359 |
-
|
360 |
-
download_link = html.A("Download Audio", href=src, download="generated_audio.wav")
|
361 |
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
elif trigger_id == "advanced-settings-toggle":
|
372 |
return dash.no_update, dash.no_update, not is_advanced_open, dash.no_update, "", ""
|
|
|
230 |
except Exception as e:
|
231 |
logger.error(f"Error generating speech: {str(e)}")
|
232 |
return None
|
233 |
+
|
234 |
@callback(
|
235 |
Output("script-output", "value"),
|
236 |
Output("audio-output", "children"),
|
|
|
342 |
logger.error(f"Error generating podcast script: {str(e)}")
|
343 |
return f"Error: {str(e)}", dash.no_update, dash.no_update, dash.no_update, "", ""
|
344 |
|
345 |
+
elif trigger_id == "generate-audio-btn":
|
346 |
+
if not script_output.strip():
|
347 |
+
return dash.no_update, html.Div("No audio generated yet."), dash.no_update, dash.no_update, "", ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
+
audio_buffer = generate_audio(script_output, voice1, voice2, num_hosts, temperature, top_p, repetition_penalty, max_new_tokens)
|
|
|
350 |
|
351 |
+
if audio_buffer is not None:
|
352 |
+
# Convert to base64 for audio playback
|
353 |
+
audio_base64 = base64.b64encode(audio_buffer.getvalue()).decode('utf-8')
|
354 |
+
src = f"data:audio/wav;base64,{audio_base64}"
|
355 |
+
|
356 |
+
# Log audio file size
|
357 |
+
logger.info(f"Generated audio file size: {len(audio_base64)} bytes")
|
358 |
+
|
359 |
+
# Create a download link for the audio
|
360 |
+
download_link = html.A("Download Audio", href=src, download="generated_audio.wav")
|
361 |
+
|
362 |
+
return dash.no_update, html.Div([
|
363 |
+
html.Audio(src=src, controls=True),
|
364 |
+
html.Br(),
|
365 |
+
download_link
|
366 |
+
]), dash.no_update, dash.no_update, "", ""
|
367 |
+
else:
|
368 |
+
logger.error("Failed to generate audio")
|
369 |
+
return dash.no_update, html.Div("Error generating audio"), dash.no_update, dash.no_update, "", ""
|
370 |
|
371 |
elif trigger_id == "advanced-settings-toggle":
|
372 |
return dash.no_update, dash.no_update, not is_advanced_open, dash.no_update, "", ""
|