From 8fb89e326baea2568d0717433903efc7ca6a9162 Mon Sep 17 00:00:00 2001 From: Kostis-S-Z Date: Thu, 5 Dec 2024 20:37:36 +0200 Subject: [PATCH] [WIP] --- demo/app.py | 58 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/demo/app.py b/demo/app.py index 8773c8f..e1c8229 100644 --- a/demo/app.py +++ b/demo/app.py @@ -50,6 +50,32 @@ def load_text_to_speech_model_and_tokenizer(): return load_parler_tts_model_and_tokenizer("parler-tts/parler-tts-mini-v1", "cpu") +gen_pod_button = "generate_podcast_clicked" +save_audio_button = "save_podcast_clicked" +save_text_button = "save_script_clicked" + +if gen_pod_button not in st.session_state: + st.session_state[gen_pod_button] = False +if save_audio_button not in st.session_state: + st.session_state[save_audio_button] = False +if save_text_button not in st.session_state: + st.session_state[save_text_button] = False + + +def click_generate_podcast(): + st.session_state[gen_pod_button] = True + st.session_state[save_audio_button] = False + st.session_state[save_text_button] = False + + +def click_save_audio(): + st.session_state[save_audio_button] = True + + +def click_save_text(): + st.session_state[save_text_button] = True + + st.title("Document To Podcast") st.header("Uploading Data") @@ -103,7 +129,7 @@ def load_text_to_speech_model_and_tokenizer(): system_prompt = st.text_area("Podcast generation prompt", value=PODCAST_PROMPT) - if st.button("Generate Podcast"): + if st.button("Generate Podcast", on_click=click_generate_podcast): with st.spinner("Generating Podcast..."): text = "" complete_script = "" @@ -126,15 +152,21 @@ def load_text_to_speech_model_and_tokenizer(): complete_audio.append(speech) complete_script += text text = "" - - with st.spinner("Saving Podcast to file..."): - complete_audio = np.concatenate(complete_audio) - save_waveform_as_file( - waveform=complete_audio, - sampling_rate=speech_model.config.sampling_rate, - filename="podcast.wav", - ) - with open("script.txt", "w") as f: - f.write(complete_script) - - st.subheader("Podcast and Script saved to disk!") + if st.session_state[gen_pod_button]: + if st.button("Save Podcast to audio file", on_click=click_save_audio): + complete_audio = np.concatenate(complete_audio) + save_waveform_as_file( + waveform=complete_audio, + sampling_rate=speech_model.config.sampling_rate, + filename="podcast.wav", + ) + st.markdown("Podcast saved to disk!") + + if st.button( + "Save Podcast script to text file", on_click=click_save_text + ): + with open("script.txt", "w") as f: + complete_script += "}" + f.write(complete_script) + + st.markdown("Script saved to disk!")