From ec95a252768ff6a5ce45076c85669da39c82a7a6 Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Fri, 1 Nov 2024 17:29:17 +0000 Subject: [PATCH] put waveform viz in an expander --- pages/audiocast.py | 12 ++++++++---- src/utils/render_audiocast.py | 13 +++++++++++++ src/utils/waveform_utils.py | 5 +++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pages/audiocast.py b/pages/audiocast.py index ec9c8ed..d5f60d3 100644 --- a/pages/audiocast.py +++ b/pages/audiocast.py @@ -30,8 +30,11 @@ async def render_audiocast_page(): with st.spinner("Loading audiocast..."): audiocast = get_audiocast(session_id) + # Audio player + st.audio(audiocast["url"]) + # Create placeholder for visualization - if audiocast["url"]: + with st.expander("Show Waveform Visualization"): viz = st.empty() with viz.container(): try: @@ -42,9 +45,6 @@ async def render_audiocast_page(): except Exception as e: st.error(f"Error rendering waveform: {str(e)}") - # Audio player - st.audio(audiocast["url"]) - # Transcript with st.expander("Show Transcript"): st.markdown(parse_ai_script(audiocast["script"])) @@ -67,6 +67,10 @@ async def render_audiocast_page(): if st.button("Create your Audiocast", use_container_width=True): navigate_to_home() + if st.session_state.get("show_copy_success", False): + st.session_state.show_copy_succes = False + st.success("Share link copied successfully!", icon="✅") + if audiocast["created_at"]: st.markdown(f"> Created: {audiocast["created_at"]}") diff --git a/src/utils/render_audiocast.py b/src/utils/render_audiocast.py index 556070a..0a2ec65 100644 --- a/src/utils/render_audiocast.py +++ b/src/utils/render_audiocast.py @@ -6,6 +6,7 @@ from src.env_var import APP_URL from src.utils.session_state import reset_session +from src.utils.waveform_utils import download_waveform_video, render_waveform class GenerateAudiocastDict(TypedDict): @@ -31,6 +32,18 @@ def render_audiocast(session_id: str): # Audio player st.audio(current_audiocast["url"]) + # Create placeholder for visualization + with st.expander("Show Waveform Visualization"): + viz = st.empty() + with viz.container(): + try: + video_path = render_waveform(session_id, current_audiocast["url"]) + if video_path: + # Download video + download_waveform_video(str(video_path)) + except Exception as e: + st.error(f"Error rendering waveform: {str(e)}") + # Transcript with st.expander("Show Transcript"): st.markdown(parse_ai_script(current_audiocast["script"])) diff --git a/src/utils/waveform_utils.py b/src/utils/waveform_utils.py index 828962c..742c8b8 100644 --- a/src/utils/waveform_utils.py +++ b/src/utils/waveform_utils.py @@ -17,8 +17,8 @@ def generate_waveform_video(output_path: Path, audio_path: str) -> Path: bars=60, speed=4, time=0.4, - rate=60, - size=(200, 200), + # rate=60, + size=(120, 68), fg_color=(0.0, 1.0, 0.6), # Bright green. Try 0.2 0.2 0.2 for dark green bg_color=(0.05, 0.05, 0.05), # Near black ) @@ -65,4 +65,5 @@ def download_waveform_video(video_path: str): data=f, file_name="audio_visualization.mp4", mime="video/mp4", + use_container_width=True )