Skip to content

Commit

Permalink
add audiocast share page
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Oct 30, 2024
1 parent e4a78b1 commit bc837e4
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
49 changes: 49 additions & 0 deletions pages/audiocast.py
Original file line number Diff line number Diff line change
@@ -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())
5 changes: 3 additions & 2 deletions src/utils/main_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/utils/render_audiocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bc837e4

Please sign in to comment.