Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -312,6 +312,261 @@ def create_download_link_with_cache(
|
|
312 |
st.error(f"Error creating download link: {str(e)}")
|
313 |
return ""
|
314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
315 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
316 |
# 4. PAPER PROCESSING & DISPLAY
|
317 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
312 |
st.error(f"Error creating download link: {str(e)}")
|
313 |
return ""
|
314 |
|
315 |
+
|
316 |
+
|
317 |
+
# ---
|
318 |
+
def display_voice_tab():
|
319 |
+
"""Display voice input tab with TTS settings."""
|
320 |
+
st.subheader("π€ Voice Input")
|
321 |
+
|
322 |
+
# Voice Settings Section
|
323 |
+
st.markdown("### π€ Voice Settings")
|
324 |
+
selected_voice = st.selectbox(
|
325 |
+
"Select TTS Voice:",
|
326 |
+
options=EDGE_TTS_VOICES,
|
327 |
+
index=EDGE_TTS_VOICES.index(st.session_state['tts_voice'])
|
328 |
+
)
|
329 |
+
|
330 |
+
# Audio Format Selection
|
331 |
+
st.markdown("### π Audio Format")
|
332 |
+
selected_format = st.radio(
|
333 |
+
"Choose Audio Format:",
|
334 |
+
options=["MP3", "WAV"],
|
335 |
+
index=0
|
336 |
+
)
|
337 |
+
|
338 |
+
# Update session state if settings change
|
339 |
+
if selected_voice != st.session_state['tts_voice']:
|
340 |
+
st.session_state['tts_voice'] = selected_voice
|
341 |
+
st.rerun()
|
342 |
+
if selected_format.lower() != st.session_state['audio_format']:
|
343 |
+
st.session_state['audio_format'] = selected_format.lower()
|
344 |
+
st.rerun()
|
345 |
+
|
346 |
+
# Text Input Area
|
347 |
+
user_text = st.text_area("π¬ Message:", height=100)
|
348 |
+
user_text = user_text.strip().replace('\n', ' ')
|
349 |
+
|
350 |
+
# Send Button
|
351 |
+
if st.button("π¨ Send"):
|
352 |
+
process_voice_input(user_text)
|
353 |
+
|
354 |
+
# Chat History
|
355 |
+
st.subheader("π Chat History")
|
356 |
+
for c in st.session_state.chat_history:
|
357 |
+
st.write("**You:**", c["user"])
|
358 |
+
st.write("**Response:**", c["claude"])
|
359 |
+
|
360 |
+
def display_arxiv_tab():
|
361 |
+
"""Display ArXiv search tab with options."""
|
362 |
+
st.subheader("π Query ArXiv")
|
363 |
+
q = st.text_input("π Query:", key="arxiv_query")
|
364 |
+
|
365 |
+
# Options Section
|
366 |
+
st.markdown("### π Options")
|
367 |
+
col1, col2 = st.columns(2)
|
368 |
+
|
369 |
+
with col1:
|
370 |
+
vocal_summary = st.checkbox("π Short Audio", value=True,
|
371 |
+
key="option_vocal_summary")
|
372 |
+
extended_refs = st.checkbox("π Long Refs", value=False,
|
373 |
+
key="option_extended_refs")
|
374 |
+
|
375 |
+
with col2:
|
376 |
+
titles_summary = st.checkbox("π Titles Only", value=True,
|
377 |
+
key="option_titles_summary")
|
378 |
+
full_audio = st.checkbox("π Full Audio", value=False,
|
379 |
+
key="option_full_audio")
|
380 |
+
|
381 |
+
full_transcript = st.checkbox("π§Ύ Full Transcript", value=False,
|
382 |
+
key="option_full_transcript")
|
383 |
+
|
384 |
+
if q and st.button("π Run Search"):
|
385 |
+
st.session_state.last_query = q
|
386 |
+
result, timings = perform_ai_lookup(
|
387 |
+
q,
|
388 |
+
vocal_summary=vocal_summary,
|
389 |
+
extended_refs=extended_refs,
|
390 |
+
titles_summary=titles_summary,
|
391 |
+
full_audio=full_audio
|
392 |
+
)
|
393 |
+
|
394 |
+
if full_transcript:
|
395 |
+
create_file(q, result, "md")
|
396 |
+
|
397 |
+
def display_media_tab():
|
398 |
+
"""Display media gallery tab with audio, images, and video."""
|
399 |
+
st.header("πΈ Media Gallery")
|
400 |
+
|
401 |
+
# Create tabs for different media types
|
402 |
+
tabs = st.tabs(["π΅ Audio", "πΌ Images", "π₯ Video"])
|
403 |
+
|
404 |
+
# Audio Files Tab
|
405 |
+
with tabs[0]:
|
406 |
+
st.subheader("π΅ Audio Files")
|
407 |
+
audio_files = glob.glob("*.mp3") + glob.glob("*.wav")
|
408 |
+
|
409 |
+
if audio_files:
|
410 |
+
for audio_file in audio_files:
|
411 |
+
with st.expander(os.path.basename(audio_file)):
|
412 |
+
st.audio(audio_file)
|
413 |
+
ext = os.path.splitext(audio_file)[1].replace('.', '')
|
414 |
+
dl_link = get_download_link(audio_file, file_type=ext)
|
415 |
+
st.markdown(dl_link, unsafe_allow_html=True)
|
416 |
+
else:
|
417 |
+
st.write("No audio files found.")
|
418 |
+
|
419 |
+
# Images Tab
|
420 |
+
with tabs[1]:
|
421 |
+
st.subheader("πΌ Image Files")
|
422 |
+
image_files = glob.glob("*.png") + glob.glob("*.jpg") + glob.glob("*.jpeg")
|
423 |
+
|
424 |
+
if image_files:
|
425 |
+
cols = st.slider("Columns:", 1, 5, 3, key="cols_images")
|
426 |
+
image_cols = st.columns(cols)
|
427 |
+
|
428 |
+
for i, img_file in enumerate(image_files):
|
429 |
+
with image_cols[i % cols]:
|
430 |
+
try:
|
431 |
+
img = Image.open(img_file)
|
432 |
+
st.image(img, use_column_width=True)
|
433 |
+
except Exception as e:
|
434 |
+
st.error(f"Error loading image {img_file}: {str(e)}")
|
435 |
+
else:
|
436 |
+
st.write("No images found.")
|
437 |
+
|
438 |
+
# Video Tab
|
439 |
+
with tabs[2]:
|
440 |
+
st.subheader("π₯ Video Files")
|
441 |
+
video_files = glob.glob("*.mp4") + glob.glob("*.mov") + glob.glob("*.avi")
|
442 |
+
|
443 |
+
if video_files:
|
444 |
+
for video_file in video_files:
|
445 |
+
with st.expander(os.path.basename(video_file)):
|
446 |
+
st.video(video_file)
|
447 |
+
else:
|
448 |
+
st.write("No videos found.")
|
449 |
+
|
450 |
+
def display_editor_tab():
|
451 |
+
"""Display text editor tab with file management."""
|
452 |
+
st.subheader("π Text Editor")
|
453 |
+
|
454 |
+
# File Management Section
|
455 |
+
st.markdown("### π File Management")
|
456 |
+
|
457 |
+
# File Selection
|
458 |
+
md_files = glob.glob("*.md")
|
459 |
+
selected_file = st.selectbox(
|
460 |
+
"Select file to edit:",
|
461 |
+
["New File"] + md_files,
|
462 |
+
key="file_selector"
|
463 |
+
)
|
464 |
+
|
465 |
+
# Edit Area
|
466 |
+
if selected_file == "New File":
|
467 |
+
new_filename = st.text_input("New filename (without extension):")
|
468 |
+
file_content = st.text_area("Content:", height=300)
|
469 |
+
|
470 |
+
if st.button("πΎ Save File"):
|
471 |
+
if new_filename:
|
472 |
+
try:
|
473 |
+
with open(f"{new_filename}.md", 'w', encoding='utf-8') as f:
|
474 |
+
f.write(file_content)
|
475 |
+
st.success(f"File {new_filename}.md saved successfully!")
|
476 |
+
st.session_state.should_rerun = True
|
477 |
+
except Exception as e:
|
478 |
+
st.error(f"Error saving file: {str(e)}")
|
479 |
+
else:
|
480 |
+
st.warning("Please enter a filename.")
|
481 |
+
else:
|
482 |
+
try:
|
483 |
+
# Load existing file content
|
484 |
+
with open(selected_file, 'r', encoding='utf-8') as f:
|
485 |
+
file_content = f.read()
|
486 |
+
|
487 |
+
# Edit existing file
|
488 |
+
edited_content = st.text_area(
|
489 |
+
"Edit content:",
|
490 |
+
value=file_content,
|
491 |
+
height=300
|
492 |
+
)
|
493 |
+
|
494 |
+
col1, col2 = st.columns(2)
|
495 |
+
with col1:
|
496 |
+
if st.button("πΎ Save Changes"):
|
497 |
+
try:
|
498 |
+
with open(selected_file, 'w', encoding='utf-8') as f:
|
499 |
+
f.write(edited_content)
|
500 |
+
st.success("Changes saved successfully!")
|
501 |
+
except Exception as e:
|
502 |
+
st.error(f"Error saving changes: {str(e)}")
|
503 |
+
|
504 |
+
with col2:
|
505 |
+
if st.button("π Delete File"):
|
506 |
+
try:
|
507 |
+
os.remove(selected_file)
|
508 |
+
st.success(f"File {selected_file} deleted successfully!")
|
509 |
+
st.session_state.should_rerun = True
|
510 |
+
except Exception as e:
|
511 |
+
st.error(f"Error deleting file: {str(e)}")
|
512 |
+
|
513 |
+
except Exception as e:
|
514 |
+
st.error(f"Error loading file {selected_file}: {str(e)}")
|
515 |
+
|
516 |
+
def display_settings_tab():
|
517 |
+
"""Display application settings tab."""
|
518 |
+
st.subheader("βοΈ Settings")
|
519 |
+
|
520 |
+
# General Settings
|
521 |
+
st.markdown("### π§ General Settings")
|
522 |
+
|
523 |
+
# Theme Selection
|
524 |
+
theme = st.selectbox(
|
525 |
+
"Color Theme:",
|
526 |
+
["Dark", "Light", "Custom"],
|
527 |
+
index=0
|
528 |
+
)
|
529 |
+
|
530 |
+
if theme == "Custom":
|
531 |
+
st.color_picker("Primary Color:", "#1E1E1E")
|
532 |
+
st.color_picker("Secondary Color:", "#2D2D2D")
|
533 |
+
|
534 |
+
# Performance Settings
|
535 |
+
st.markdown("### β‘ Performance Settings")
|
536 |
+
|
537 |
+
# Cache Settings
|
538 |
+
cache_size = st.slider(
|
539 |
+
"Maximum Cache Size (MB):",
|
540 |
+
0, 1000, 100
|
541 |
+
)
|
542 |
+
|
543 |
+
if st.button("Clear Cache"):
|
544 |
+
st.session_state['audio_cache'] = {}
|
545 |
+
st.session_state['paper_cache'] = {}
|
546 |
+
st.session_state['download_link_cache'] = {}
|
547 |
+
st.success("Cache cleared successfully!")
|
548 |
+
|
549 |
+
# API Settings
|
550 |
+
st.markdown("### π API Settings")
|
551 |
+
|
552 |
+
# Show/hide API keys
|
553 |
+
show_keys = st.checkbox("Show API Keys")
|
554 |
+
if show_keys:
|
555 |
+
st.text_input("OpenAI API Key:", value=openai_api_key)
|
556 |
+
st.text_input("Anthropic API Key:", value=anthropic_key)
|
557 |
+
|
558 |
+
# Save Settings
|
559 |
+
if st.button("πΎ Save Settings"):
|
560 |
+
st.success("Settings saved successfully!")
|
561 |
+
st.session_state.should_rerun = True
|
562 |
+
|
563 |
+
|
564 |
+
|
565 |
+
|
566 |
+
|
567 |
+
|
568 |
+
|
569 |
+
|
570 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
571 |
# 4. PAPER PROCESSING & DISPLAY
|
572 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|