From bc837e440cf10545aeb19b3ee2fa077a8174f5c6 Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Wed, 30 Oct 2024 22:35:30 +0000 Subject: [PATCH] add audiocast share page --- pages/audiocast.py | 49 +++++++++++++++++++++++++++++++++++ src/utils/main_utils.py | 5 ++-- src/utils/render_audiocast.py | 2 +- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 pages/audiocast.py diff --git a/pages/audiocast.py b/pages/audiocast.py new file mode 100644 index 0000000..1666a9c --- /dev/null +++ b/pages/audiocast.py @@ -0,0 +1,49 @@ +import asyncio +from pathlib import Path + +import streamlit as st + +from src.utils.main_utils import get_audiocast_uri + + +def navigate_to_home(): + main_script = str(Path(__file__).parent.parent / "app.py") + st.switch_page(main_script) + + +async def render_audiocast_page(): + st.set_page_config(page_title="Audiora | Share Page", page_icon="🎧") + + audiocast_id = st.query_params.get("uuid") + + if audiocast_id: + # Display audiocast content + st.title("🎧 Audiocast Player") + st.write(f"Playing audiocast: {audiocast_id}") + + try: + with st.spinner("Loading audiocast..."): + audio_path = get_audiocast_uri(audiocast_id) + st.audio(audio_path) + + # TODO: Fetch audiocast metadata from the database + st.subheader("Audiocast Details") + st.write("Created: 2024-03-20") + + 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: ?uuid=your-audiocast-id" + ) + + st.markdown("---") + + cola, _ = st.columns([3, 5]) + with cola: + if st.button("← Back to Home", use_container_width=True): + navigate_to_home() + + +if __name__ == "__main__": + asyncio.run(render_audiocast_page()) diff --git a/src/utils/main_utils.py b/src/utils/main_utils.py index ad5913a..ac75136 100644 --- a/src/utils/main_utils.py +++ b/src/utils/main_utils.py @@ -120,9 +120,10 @@ async def generate_audiocast(request: GenerateAudioCastRequest): return response.model_dump() -async def get_audiocast_uri(uuid: str): +def get_audiocast_uri(uuid: str): """ Get the URI for the audiocast """ storage_manager = StorageManager() - return storage_manager.download_from_gcs(uuid) + filepath = storage_manager.download_from_gcs(uuid) + return filepath diff --git a/src/utils/render_audiocast.py b/src/utils/render_audiocast.py index 082aee4..5daa902 100644 --- a/src/utils/render_audiocast.py +++ b/src/utils/render_audiocast.py @@ -33,7 +33,7 @@ def render_audiocast(): st.sidebar.subheader("Audiocast Source") st.sidebar.markdown(current_audiocast["source_content"]) - share_url = f"{APP_URL}/audiocast/{current_audiocast['uuid']}" + share_url = f"{APP_URL}/audiocast?uuid={current_audiocast['uuid']}" st.text_input("Share this audiocast:", share_url) share_col, restart_row = st.columns(2, vertical_alignment="bottom")