Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into move-business-logic-t…
Browse files Browse the repository at this point in the history
…o-fastapi
  • Loading branch information
nwaughachukwuma committed Nov 3, 2024
2 parents c4d6d03 + 3808390 commit 0b78ba2
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 6 deletions.
11 changes: 8 additions & 3 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ ENV PYTHONDONTWRITEBYTECODE 1

WORKDIR /app

# Install FFmpeg and any other required dependencies
RUN apt-get -yqq update && apt-get -yqq install build-essential ffmpeg && \
rm -rf /var/lib/apt/lists/*
# Install FFmpeg, Cairo, and any other required dependencies
RUN apt-get -yqq update && apt-get -yqq install \
build-essential \
ffmpeg \
libcairo2-dev \
pkg-config \
python3-dev \
&& rm -rf /var/lib/apt/lists/*

COPY . ./

Expand Down
63 changes: 63 additions & 0 deletions pages/audiocast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import asyncio
from typing import cast

import pyperclip
import streamlit as st
from src.utils.main_utils import get_audiocast
from src.utils.render_audiocast_utils import (
GenerateAudiocastDict,
navigate_to_home,
render_audiocast_handler,
)


async def render_audiocast_page():
st.set_page_config(page_title="Audiora | Share Page", page_icon="🎧")

session_id = st.query_params.get("session_id")

if session_id:
# Display audiocast content
st.title("🎧 Audiora")
st.subheader("Share Page ")
st.markdown(f"##### Viewing audiocast: _{session_id}_")

try:
with st.spinner("Loading audiocast..."):
audiocast = cast(GenerateAudiocastDict, get_audiocast(session_id))

share_url = render_audiocast_handler(session_id, audiocast)

share_col, restart_row = st.columns(2, vertical_alignment="bottom")

with share_col:
if st.button("Copy Share link", use_container_width=True):
pyperclip.copy(share_url)
st.session_state.show_copy_success = True

with restart_row:
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"]}")

except Exception as e:
st.error(f"Error loading audiocast: {str(e)}")
else:
st.warning("Audiocast ID is missing in the URL. Expected URL format: ?session_id=your-audiocast-id")

st.markdown("---")

col1, _ = st.columns([3, 5])
with col1:
if st.button("← Back to Home", use_container_width=True):
navigate_to_home()


if __name__ == "__main__":
asyncio.run(render_audiocast_page())
File renamed without changes.
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ google-cloud-storage
google-api-python-client
google-generativeai

<<<<<<< HEAD
ruff
watchdog
setuptools
=======
watchdog
ruff
>>>>>>> origin/main
73 changes: 73 additions & 0 deletions utils_pkg/render_audiocast_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import re
from pathlib import Path
from typing import TypedDict

import streamlit as st

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


def navigate_to_home():
main_script = str(Path(__file__).parent.parent / "app.py")
st.switch_page(main_script)


def parse_ai_script(ai_script: str):
matches = re.findall(r"<(Speaker\d+)>(.*?)</Speaker\d+>", ai_script, re.DOTALL)
return "\n\n".join([f"**{speaker}**: {content}" for speaker, content in matches])


class GenerateAudiocastDict(TypedDict):
url: str
script: str
source_content: str
created_at: str | None


def render_audiocast_handler(session_id: str, audiocast: GenerateAudiocastDict):
# Audio player
st.audio(audiocast["url"])

st.markdown("---")

col1, _ = st.columns([4, 1])
with col1:

def toggle_show_waveform():
st.session_state.show_waveform = not st.session_state.get("show_waveform")

button_label = (
"Hide Waveform Visualization"
if st.session_state.get("show_waveform")
else "Show Waveform Visualization"
)

st.button(
button_label,
on_click=toggle_show_waveform,
use_container_width=True,
)

if st.session_state.get("show_waveform"):
try:
render_waveform(session_id, audiocast["url"])
except Exception as e:
st.error(f"Error rendering waveform: {str(e)}")

st.markdown("---")

# Transcript
with st.expander("Show Transcript"):
st.markdown(parse_ai_script(audiocast["script"]))

st.markdown("---")

# Metadata
st.sidebar.subheader("Audiocast Source")
st.sidebar.markdown(audiocast["source_content"])

share_url = f"{APP_URL}/audiocast?session_id={session_id}"
st.text_input("Share this audiocast:", share_url)

return share_url
4 changes: 1 addition & 3 deletions utils_pkg/waveform_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def get_tmp_video_path(self):

def save_waveform_video_to_gcs(self, video_path: str):
"""Ingest waveform visualization to GCS."""
full_path = StorageManager().upload_video_to_gcs(
video_path, f"{self.session_id}.mp4"
)
full_path = StorageManager().upload_video_to_gcs(video_path, f"{self.session_id}.mp4")
return full_path

def generate_waveform_video(self, output_path: Path) -> Path:
Expand Down

0 comments on commit 0b78ba2

Please sign in to comment.