Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -407,15 +407,112 @@ def create_paper_audio_files(papers, input_question):
|
|
| 407 |
paper['full_audio'] = None
|
| 408 |
paper['download_base64'] = ''
|
| 409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
def display_papers(papers, marquee_settings):
|
| 411 |
-
"""Display paper info
|
| 412 |
st.write("## Research Papers")
|
| 413 |
for i, paper in enumerate(papers, start=1):
|
| 414 |
-
marquee_text = f"π {paper['title']} | π€ {paper['authors'][:120]}
|
| 415 |
display_marquee(marquee_text, marquee_settings, key_suffix=f"paper_{i}")
|
| 416 |
|
| 417 |
with st.expander(f"{i}. π {paper['title']}", expanded=True):
|
| 418 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
st.markdown(f"*Authors:* {paper['authors']}")
|
| 420 |
st.markdown(paper['summary'])
|
| 421 |
if paper.get('full_audio'):
|
|
@@ -425,19 +522,34 @@ def display_papers(papers, marquee_settings):
|
|
| 425 |
st.markdown(paper['download_base64'], unsafe_allow_html=True)
|
| 426 |
|
| 427 |
def display_papers_in_sidebar(papers):
|
| 428 |
-
"""Mirrors the paper listing in
|
| 429 |
st.sidebar.title("πΆ Papers & Audio")
|
| 430 |
for i, paper in enumerate(papers, start=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
with st.sidebar.expander(f"{i}. {paper['title']}"):
|
| 432 |
-
|
| 433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
st.audio(paper['full_audio'])
|
| 435 |
if paper['download_base64']:
|
| 436 |
st.markdown(paper['download_base64'], unsafe_allow_html=True)
|
| 437 |
-
|
| 438 |
-
if paper['summary']:
|
| 439 |
-
st.markdown(f"**Summary:** {paper['summary'][:300]}...")
|
| 440 |
-
|
| 441 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 442 |
# 4. ZIP FUNCTION
|
| 443 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 407 |
paper['full_audio'] = None
|
| 408 |
paper['download_base64'] = ''
|
| 409 |
|
| 410 |
+
|
| 411 |
+
def display_file_history_in_sidebar():
|
| 412 |
+
"""
|
| 413 |
+
Shows a history of files grouped by query, with lazy loading of audio and content.
|
| 414 |
+
"""
|
| 415 |
+
st.sidebar.markdown("---")
|
| 416 |
+
st.sidebar.markdown("### π File History")
|
| 417 |
+
|
| 418 |
+
# Gather all files
|
| 419 |
+
md_files = glob.glob("*.md")
|
| 420 |
+
mp3_files = glob.glob("*.mp3")
|
| 421 |
+
wav_files = glob.glob("*.wav")
|
| 422 |
+
all_files = md_files + mp3_files + wav_files
|
| 423 |
+
|
| 424 |
+
if not all_files:
|
| 425 |
+
st.sidebar.write("No files found.")
|
| 426 |
+
return
|
| 427 |
+
|
| 428 |
+
# Group files by their query prefix (timestamp_query)
|
| 429 |
+
grouped_files = {}
|
| 430 |
+
for f in all_files:
|
| 431 |
+
fname = os.path.basename(f)
|
| 432 |
+
prefix = '_'.join(fname.split('_')[:6]) # Get timestamp part
|
| 433 |
+
if prefix not in grouped_files:
|
| 434 |
+
grouped_files[prefix] = {'md': [], 'audio': [], 'loaded': False}
|
| 435 |
+
|
| 436 |
+
ext = os.path.splitext(fname)[1].lower()
|
| 437 |
+
if ext == '.md':
|
| 438 |
+
grouped_files[prefix]['md'].append(f)
|
| 439 |
+
elif ext in ['.mp3', '.wav']:
|
| 440 |
+
grouped_files[prefix]['audio'].append(f)
|
| 441 |
+
|
| 442 |
+
# Sort groups by timestamp (newest first)
|
| 443 |
+
sorted_groups = sorted(grouped_files.items(), key=lambda x: x[0], reverse=True)
|
| 444 |
+
|
| 445 |
+
# πβ¬οΈ Sidebar delete all and zip all download
|
| 446 |
+
col1, col4 = st.sidebar.columns(2)
|
| 447 |
+
with col1:
|
| 448 |
+
if st.button("π Delete All"):
|
| 449 |
+
for f in all_files:
|
| 450 |
+
os.remove(f)
|
| 451 |
+
st.session_state.should_rerun = True
|
| 452 |
+
with col4:
|
| 453 |
+
if st.button("β¬οΈ Zip All"):
|
| 454 |
+
zip_name = create_zip_of_files(md_files, mp3_files, wav_files,
|
| 455 |
+
st.session_state.get('last_query', ''))
|
| 456 |
+
if zip_name:
|
| 457 |
+
st.sidebar.markdown(get_download_link(zip_name, "zip"),
|
| 458 |
+
unsafe_allow_html=True)
|
| 459 |
+
|
| 460 |
+
# Display grouped files
|
| 461 |
+
for prefix, files in sorted_groups:
|
| 462 |
+
# Get a preview of content from first MD file
|
| 463 |
+
preview = ""
|
| 464 |
+
if files['md']:
|
| 465 |
+
with open(files['md'][0], "r", encoding="utf-8") as f:
|
| 466 |
+
preview = f.read(200).replace("\n", " ")
|
| 467 |
+
if len(preview) > 200:
|
| 468 |
+
preview += "..."
|
| 469 |
+
|
| 470 |
+
# Create unique key for this group
|
| 471 |
+
group_key = f"group_{prefix}"
|
| 472 |
+
if group_key not in st.session_state:
|
| 473 |
+
st.session_state[group_key] = False
|
| 474 |
+
|
| 475 |
+
# Display group expander
|
| 476 |
+
with st.sidebar.expander(f"π Query Group: {prefix}"):
|
| 477 |
+
st.write("**Preview:**")
|
| 478 |
+
st.write(preview)
|
| 479 |
+
|
| 480 |
+
# Load full content button
|
| 481 |
+
if st.button("π View Full Content", key=f"btn_{prefix}"):
|
| 482 |
+
st.session_state[group_key] = True
|
| 483 |
+
|
| 484 |
+
# Only show full content and audio if button was clicked
|
| 485 |
+
if st.session_state[group_key]:
|
| 486 |
+
# Display markdown files
|
| 487 |
+
for md_file in files['md']:
|
| 488 |
+
with open(md_file, "r", encoding="utf-8") as f:
|
| 489 |
+
content = f.read()
|
| 490 |
+
st.markdown("**Full Content:**")
|
| 491 |
+
st.markdown(content)
|
| 492 |
+
st.markdown(get_download_link(md_file, file_type="md"),
|
| 493 |
+
unsafe_allow_html=True)
|
| 494 |
+
|
| 495 |
+
# Display audio files
|
| 496 |
+
for audio_file in files['audio']:
|
| 497 |
+
ext = os.path.splitext(audio_file)[1].replace('.', '')
|
| 498 |
+
st.audio(audio_file)
|
| 499 |
+
st.markdown(get_download_link(audio_file, file_type=ext),
|
| 500 |
+
unsafe_allow_html=True)
|
| 501 |
+
|
| 502 |
def display_papers(papers, marquee_settings):
|
| 503 |
+
"""Display paper info with both abs and PDF links."""
|
| 504 |
st.write("## Research Papers")
|
| 505 |
for i, paper in enumerate(papers, start=1):
|
| 506 |
+
marquee_text = f"π {paper['title']} | π€ {paper['authors'][:120]}"
|
| 507 |
display_marquee(marquee_text, marquee_settings, key_suffix=f"paper_{i}")
|
| 508 |
|
| 509 |
with st.expander(f"{i}. π {paper['title']}", expanded=True):
|
| 510 |
+
# Create PDF link by replacing 'abs' with 'pdf' in arxiv URL
|
| 511 |
+
pdf_url = paper['url'].replace('/abs/', '/pdf/')
|
| 512 |
+
st.markdown(f"""
|
| 513 |
+
**{paper['date']} | {paper['title']}**
|
| 514 |
+
π [Abstract]({paper['url']}) | π [PDF]({pdf_url})
|
| 515 |
+
""")
|
| 516 |
st.markdown(f"*Authors:* {paper['authors']}")
|
| 517 |
st.markdown(paper['summary'])
|
| 518 |
if paper.get('full_audio'):
|
|
|
|
| 522 |
st.markdown(paper['download_base64'], unsafe_allow_html=True)
|
| 523 |
|
| 524 |
def display_papers_in_sidebar(papers):
|
| 525 |
+
"""Mirrors the paper listing in sidebar with lazy loading."""
|
| 526 |
st.sidebar.title("πΆ Papers & Audio")
|
| 527 |
for i, paper in enumerate(papers, start=1):
|
| 528 |
+
paper_key = f"paper_{paper['url']}"
|
| 529 |
+
if paper_key not in st.session_state:
|
| 530 |
+
st.session_state[paper_key] = False
|
| 531 |
+
|
| 532 |
with st.sidebar.expander(f"{i}. {paper['title']}"):
|
| 533 |
+
# Create PDF link
|
| 534 |
+
pdf_url = paper['url'].replace('/abs/', '/pdf/')
|
| 535 |
+
st.markdown(f"π [Abstract]({paper['url']}) | π [PDF]({pdf_url})")
|
| 536 |
+
|
| 537 |
+
# Preview of authors and summary
|
| 538 |
+
st.markdown(f"**Authors:** {paper['authors'][:100]}...")
|
| 539 |
+
if paper['summary']:
|
| 540 |
+
st.markdown(f"**Summary:** {paper['summary'][:200]}...")
|
| 541 |
+
|
| 542 |
+
# Load audio button
|
| 543 |
+
if paper['full_audio'] and st.button("π΅ Load Audio",
|
| 544 |
+
key=f"btn_{paper_key}"):
|
| 545 |
+
st.session_state[paper_key] = True
|
| 546 |
+
|
| 547 |
+
# Show audio player and download only if requested
|
| 548 |
+
if st.session_state[paper_key] and paper['full_audio']:
|
| 549 |
st.audio(paper['full_audio'])
|
| 550 |
if paper['download_base64']:
|
| 551 |
st.markdown(paper['download_base64'], unsafe_allow_html=True)
|
| 552 |
+
|
|
|
|
|
|
|
|
|
|
| 553 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 554 |
# 4. ZIP FUNCTION
|
| 555 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|