bluenevus commited on
Commit
1b51b36
·
verified ·
1 Parent(s): 301b969

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -1
app.py CHANGED
@@ -277,4 +277,52 @@ def combined_callback(generate_script_clicks, generate_audio_clicks, advanced_se
277
  Start a new paragraph only when switching to a different speaker if the number of hosts is not 1.
278
  Maintain natural conversation flow and speech patterns within each monologue.
279
  Use context clues or subtle references to indicate who is speaking without explicit labels if the number of hosts is not 1.
280
- Use speaker names ({host1_name} and/or {host2_
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  Start a new paragraph only when switching to a different speaker if the number of hosts is not 1.
278
  Maintain natural conversation flow and speech patterns within each monologue.
279
  Use context clues or subtle references to indicate who is speaking without explicit labels if the number of hosts is not 1.
280
+ Use speaker names ({host1_name} and/or {host2_name}) sparingly, only when necessary for clarity or emphasis. Avoid starting every line with the other person's name.
281
+ Rely more on context and speech patterns to indicate who is speaking, rather than always stating names.
282
+ Use names primarily for transitions sparingly, definitely with agreements, or to draw attention to a specific point, not as a constant form of address.
283
+ {'Make sure the script is a monologue for one person.' if num_hosts == 1 else f'Ensure the dialogue alternates between two distinct voices, with {host1_name} speaking on odd-numbered lines and {host2_name} on even-numbered lines.'}
284
+ Always include intro with the speaker name and its the podcast name "{podcast_name}" in intoduce the topic of the podcast with "{podcast_topic}".
285
+ Incorporate the podcast name and topic naturally into the intro and outro, and ensure the content stays relevant to the specified topic throughout the script.
286
+ """
287
+
288
+ response = model.generate_content(prompt_template)
289
+ return re.sub(r'[^a-zA-Z0-9\s.,?!<>]', '', response.text), dash.no_update, dash.no_update, dash.no_update
290
+ except Exception as e:
291
+ logger.error(f"Error generating podcast script: {str(e)}")
292
+ return f"Error: {str(e)}", dash.no_update, dash.no_update, dash.no_update
293
+
294
+ elif trigger_id == "generate-audio-btn":
295
+ if not script_output.strip():
296
+ return dash.no_update, html.Div("No audio generated yet."), dash.no_update, dash.no_update
297
+
298
+ final_audio = generate_audio(script_output, voice1, voice2, num_hosts, temperature, top_p, repetition_penalty, max_new_tokens)
299
+
300
+ if final_audio is not None:
301
+ # Convert to base64 for audio playback
302
+ audio_base64 = base64.b64encode(final_audio.tobytes()).decode('utf-8')
303
+ src = f"data:audio/wav;base64,{audio_base64}"
304
+
305
+ # Create a download link for the audio
306
+ download_link = html.A("Download Audio", href=src, download="generated_audio.wav")
307
+
308
+ return dash.no_update, html.Div([
309
+ html.Audio(src=src, controls=True),
310
+ html.Br(),
311
+ download_link
312
+ ]), dash.no_update, dash.no_update
313
+ else:
314
+ return dash.no_update, html.Div("Error generating audio"), dash.no_update, dash.no_update
315
+
316
+ elif trigger_id == "advanced-settings-toggle":
317
+ return dash.no_update, dash.no_update, not is_advanced_open, dash.no_update
318
+
319
+ elif trigger_id == "clear-btn":
320
+ return "", html.Div("No audio generated yet."), dash.no_update, ""
321
+
322
+ return dash.no_update, dash.no_update, dash.no_update, dash.no_update
323
+
324
+ # Run the app
325
+ if __name__ == '__main__':
326
+ print("Starting the Dash application...")
327
+ app.run(debug=True, host='0.0.0.0', port=7860)
328
+ print("Dash application has finished running.")