-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into move-business-logic-t…
…o-fastapi
- Loading branch information
Showing
6 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters