Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostis-S-Z committed Dec 5, 2024
1 parent 13dae6d commit 8fb89e3
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 = ""
Expand All @@ -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!")

0 comments on commit 8fb89e3

Please sign in to comment.