Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,24 @@ st.set_page_config(
|
|
| 34 |
)
|
| 35 |
load_dotenv()
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
# 🔑 2. API Setup & Clients
|
| 38 |
openai_api_key = os.getenv('OPENAI_API_KEY', "")
|
| 39 |
anthropic_key = os.getenv('ANTHROPIC_API_KEY_3', "")
|
|
@@ -361,28 +379,26 @@ def parse_arxiv_refs(ref_text: str):
|
|
| 361 |
|
| 362 |
return results[:20] # Ensure we return maximum 20 papers
|
| 363 |
|
|
|
|
|
|
|
| 364 |
def create_paper_audio_files(papers):
|
| 365 |
"""
|
| 366 |
-
Create audio files for each paper's
|
|
|
|
| 367 |
"""
|
| 368 |
for paper in papers:
|
| 369 |
try:
|
| 370 |
-
# Generate audio for
|
| 371 |
-
title_text = clean_for_speech(paper['title'])
|
| 372 |
-
title_file = speak_with_edge_tts(title_text)
|
| 373 |
-
paper['title_audio'] = title_file
|
| 374 |
-
|
| 375 |
-
# Generate audio for full content
|
| 376 |
full_text = f"{paper['title']} by {paper['authors']}. {paper['summary']}"
|
| 377 |
full_text = clean_for_speech(full_text)
|
| 378 |
-
full_file = speak_with_edge_tts(full_text)
|
| 379 |
paper['full_audio'] = full_file
|
| 380 |
|
| 381 |
except Exception as e:
|
| 382 |
st.warning(f"Error generating audio for paper {paper['title']}: {str(e)}")
|
| 383 |
-
paper['title_audio'] = None
|
| 384 |
paper['full_audio'] = None
|
| 385 |
|
|
|
|
| 386 |
def display_papers(papers):
|
| 387 |
"""
|
| 388 |
Display papers with their audio controls using URLs as unique keys.
|
|
@@ -395,18 +411,11 @@ def display_papers(papers):
|
|
| 395 |
st.markdown(f"*{paper['authors']}*")
|
| 396 |
st.markdown(paper['summary'])
|
| 397 |
|
| 398 |
-
#
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
st.write("🎙️ Title Audio")
|
| 404 |
-
st.audio(paper['title_audio'])
|
| 405 |
-
|
| 406 |
-
with col2:
|
| 407 |
-
if paper.get('full_audio'):
|
| 408 |
-
st.write("📚 Full Paper Audio")
|
| 409 |
-
st.audio(paper['full_audio'])
|
| 410 |
|
| 411 |
def perform_ai_lookup(q, vocal_summary=True, extended_refs=False,
|
| 412 |
titles_summary=True, full_audio=False):
|
|
@@ -595,6 +604,21 @@ def display_file_manager_sidebar(groups, sorted_prefixes):
|
|
| 595 |
# 🎯 11. Main Application
|
| 596 |
def main():
|
| 597 |
st.sidebar.markdown("### 🚲BikeAI🏆 Multi-Agent Research")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
tab_main = st.radio("Action:",["🎤 Voice","📸 Media","🔍 ArXiv","📝 Editor"],horizontal=True)
|
| 599 |
|
| 600 |
mycomponent = components.declare_component("mycomponent", path="mycomponent")
|
|
|
|
| 34 |
)
|
| 35 |
load_dotenv()
|
| 36 |
|
| 37 |
+
# Add available English voices for Edge TTS
|
| 38 |
+
EDGE_TTS_VOICES = [
|
| 39 |
+
"en-US-AriaNeural", # Default voice
|
| 40 |
+
"en-US-GuyNeural",
|
| 41 |
+
"en-US-JennyNeural",
|
| 42 |
+
"en-GB-SoniaNeural",
|
| 43 |
+
"en-GB-RyanNeural",
|
| 44 |
+
"en-AU-NatashaNeural",
|
| 45 |
+
"en-AU-WilliamNeural",
|
| 46 |
+
"en-CA-ClaraNeural",
|
| 47 |
+
"en-CA-LiamNeural"
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
# Add this to your session state initialization section:
|
| 51 |
+
if 'tts_voice' not in st.session_state:
|
| 52 |
+
st.session_state['tts_voice'] = EDGE_TTS_VOICES[0] # Default voice
|
| 53 |
+
|
| 54 |
+
|
| 55 |
# 🔑 2. API Setup & Clients
|
| 56 |
openai_api_key = os.getenv('OPENAI_API_KEY', "")
|
| 57 |
anthropic_key = os.getenv('ANTHROPIC_API_KEY_3', "")
|
|
|
|
| 379 |
|
| 380 |
return results[:20] # Ensure we return maximum 20 papers
|
| 381 |
|
| 382 |
+
|
| 383 |
+
|
| 384 |
def create_paper_audio_files(papers):
|
| 385 |
"""
|
| 386 |
+
Create audio files for each paper's content and add file paths to paper dict.
|
| 387 |
+
Only generates full audio file since it includes the title.
|
| 388 |
"""
|
| 389 |
for paper in papers:
|
| 390 |
try:
|
| 391 |
+
# Generate audio for full content only
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
full_text = f"{paper['title']} by {paper['authors']}. {paper['summary']}"
|
| 393 |
full_text = clean_for_speech(full_text)
|
| 394 |
+
full_file = speak_with_edge_tts(full_text, voice=st.session_state['tts_voice'])
|
| 395 |
paper['full_audio'] = full_file
|
| 396 |
|
| 397 |
except Exception as e:
|
| 398 |
st.warning(f"Error generating audio for paper {paper['title']}: {str(e)}")
|
|
|
|
| 399 |
paper['full_audio'] = None
|
| 400 |
|
| 401 |
+
|
| 402 |
def display_papers(papers):
|
| 403 |
"""
|
| 404 |
Display papers with their audio controls using URLs as unique keys.
|
|
|
|
| 411 |
st.markdown(f"*{paper['authors']}*")
|
| 412 |
st.markdown(paper['summary'])
|
| 413 |
|
| 414 |
+
# Single audio control for full content
|
| 415 |
+
if paper.get('full_audio'):
|
| 416 |
+
st.write("📚 Paper Audio")
|
| 417 |
+
st.audio(paper['full_audio'])
|
| 418 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|
| 420 |
def perform_ai_lookup(q, vocal_summary=True, extended_refs=False,
|
| 421 |
titles_summary=True, full_audio=False):
|
|
|
|
| 604 |
# 🎯 11. Main Application
|
| 605 |
def main():
|
| 606 |
st.sidebar.markdown("### 🚲BikeAI🏆 Multi-Agent Research")
|
| 607 |
+
|
| 608 |
+
# Add voice selector to sidebar
|
| 609 |
+
st.sidebar.markdown("### 🎤 Voice Settings")
|
| 610 |
+
selected_voice = st.sidebar.selectbox(
|
| 611 |
+
"Select TTS Voice:",
|
| 612 |
+
options=EDGE_TTS_VOICES,
|
| 613 |
+
index=EDGE_TTS_VOICES.index(st.session_state['tts_voice'])
|
| 614 |
+
)
|
| 615 |
+
|
| 616 |
+
# Update session state if voice changes
|
| 617 |
+
if selected_voice != st.session_state['tts_voice']:
|
| 618 |
+
st.session_state['tts_voice'] = selected_voice
|
| 619 |
+
st.rerun()
|
| 620 |
+
|
| 621 |
+
|
| 622 |
tab_main = st.radio("Action:",["🎤 Voice","📸 Media","🔍 ArXiv","📝 Editor"],horizontal=True)
|
| 623 |
|
| 624 |
mycomponent = components.declare_component("mycomponent", path="mycomponent")
|