Skip to content

Commit

Permalink
move download_waveform_video internal to render_waveform
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 1, 2024
1 parent efedaa6 commit d5308ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
16 changes: 6 additions & 10 deletions src/utils/render_audiocast_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import streamlit as st

from src.env_var import APP_URL
from src.utils.waveform_utils import download_waveform_video, render_waveform
from src.utils.waveform_utils import render_waveform


def navigate_to_home():
Expand All @@ -31,15 +31,11 @@ def render_audiocast_handler(session_id: str, audiocast: GenerateAudiocastDict):

# Create placeholder for visualization
with st.expander("Show Waveform Visualization"):
viz = st.empty()
with viz.container():
try:
video_path = render_waveform(session_id, 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)}")
# with st.container():
try:
render_waveform(session_id, audiocast["url"])
except Exception as e:
st.error(f"Error rendering waveform: {str(e)}")

# Transcript
with st.expander("Show Transcript"):
Expand Down
32 changes: 28 additions & 4 deletions src/utils/waveform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,36 @@ def render_waveform(session_id: str, audio_path: str):
with st.spinner("Generating waveform visualization..."):
video_path = generate_waveform_video(tmp_vid_path, audio_path)

# st.video(str(video_path), autoplay=True)
with open(video_path, "rb") as video_file:
video_bytes = video_file.read()
st.video(video_bytes, autoplay=True)
# st.video(str(video_path), autoplay=True)
# st.video(video_bytes, autoplay=True)
st.markdown(
f"""
<style>
.video-container {{
position: relative;
width: 100%;
max-width: 640px; /* 16:9 aspect ratio for width */
height: 240px; /* Fixed height */
}}
.video-container video {{
width: 100%;
height: 100%;
object-fit: cover;
background-color: transparent; /* Set background to transparent */
}}
</style>
<div class="video-container">
<video autoplay loop muted playsinline style="border:none;">
<source src="data:video/mp4;base64,{video_bytes.hex()}" type="video/mp4">
</video>
</div>
""",
unsafe_allow_html=True,
)

return video_path
download_waveform_video(str(video_path))
except Exception as e:
st.error(f"Error generating visualization: {str(e)}")

Expand All @@ -65,5 +89,5 @@ def download_waveform_video(video_path: str):
data=f,
file_name="audio_visualization.mp4",
mime="video/mp4",
use_container_width=True
use_container_width=True,
)

0 comments on commit d5308ba

Please sign in to comment.