Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,7 @@ import edge_tts
|
|
18 |
from audio_recorder_streamlit import audio_recorder
|
19 |
import nest_asyncio
|
20 |
import re
|
|
|
21 |
|
22 |
# Patch for nested async - sneaky fix! πβ¨
|
23 |
nest_asyncio.apply()
|
@@ -418,6 +419,8 @@ def main():
|
|
418 |
st.image(file_path, use_container_width=True)
|
419 |
elif file_path.endswith('.mp4'):
|
420 |
st.markdown(await get_video_html(file_path), unsafe_allow_html=True)
|
|
|
|
|
421 |
with col2:
|
422 |
vote_count = chat_votes.get(line.split('. ')[1] if '. ' in line else line, 0)
|
423 |
if st.button(f"π {vote_count}", key=f"chat_vote_{i}"):
|
@@ -470,34 +473,33 @@ def main():
|
|
470 |
message = st.text_input(f"Message as {st.session_state.username}", key="message_input", value=st.session_state.message_text, on_change=lambda: st.session_state.update(message_text=st.session_state.message_input))
|
471 |
if st.button("Send π", key="send_button") and message.strip():
|
472 |
await save_chat_entry(st.session_state.username, message)
|
473 |
-
if st.session_state.pasted_image_data:
|
474 |
-
filename = await save_pasted_image(st.session_state.pasted_image_data, st.session_state.username)
|
475 |
-
if filename:
|
476 |
-
await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
477 |
-
st.session_state.pasted_image_data = None
|
478 |
st.session_state.message_text = ''
|
479 |
st.rerun()
|
480 |
|
481 |
-
#
|
482 |
-
|
483 |
-
|
|
|
|
|
|
|
|
|
|
|
484 |
|
485 |
# Main action tabs and model use choices
|
486 |
tab_main = st.radio("Action:", ["π€ Voice", "πΈ Media", "π ArXiv", "π Editor"], horizontal=True)
|
487 |
useArxiv = st.checkbox("Search Arxiv for Research Paper Answers", value=True)
|
488 |
useArxivAudio = st.checkbox("Generate Audio File for Research Paper Answers", value=False)
|
489 |
|
|
|
|
|
|
|
|
|
490 |
if val:
|
491 |
if isinstance(val, dict):
|
492 |
if val.get('type') == 'text' and 'transcript' in val:
|
493 |
val_stripped = val['transcript'].replace('\n', ' ')
|
494 |
if val_stripped.strip():
|
495 |
await save_chat_entry(st.session_state.username, val_stripped)
|
496 |
-
elif val.get('type') == 'image' and 'image' in val:
|
497 |
-
filename = await save_pasted_image(val['image'], st.session_state.username)
|
498 |
-
if filename:
|
499 |
-
await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
500 |
-
st.session_state.pasted_image_data = None
|
501 |
|
502 |
edited_input = st.text_area("βοΈ Edit Input:", value=val_stripped if isinstance(val, dict) and val.get('type') == 'text' else "", height=100)
|
503 |
run_option = st.selectbox("Model:", ["Arxiv", "Other (demo)"])
|
@@ -519,8 +521,8 @@ def main():
|
|
519 |
st.session_state.last_query = edited_input
|
520 |
await perform_ai_lookup(edited_input, vocal_summary=True, extended_refs=False, titles_summary=True, full_audio=full_audio, useArxiv=useArxiv, useArxivAudio=useArxivAudio)
|
521 |
|
522 |
-
st.subheader("Media
|
523 |
-
uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp4'])
|
524 |
if uploaded_file:
|
525 |
timestamp = format_timestamp_prefix()
|
526 |
username = st.session_state.username
|
@@ -533,37 +535,29 @@ def main():
|
|
533 |
if file_path.endswith('.mp4'):
|
534 |
st.session_state.media_notifications.append(file_path)
|
535 |
|
536 |
-
# Enhanced Media Gallery
|
537 |
-
|
|
|
538 |
if media_files:
|
539 |
media_votes = await load_votes(MEDIA_VOTES_FILE)
|
540 |
st.write("### All Media Uploads")
|
541 |
for media_file in sorted(media_files, key=os.path.getmtime, reverse=True): # Sort by modification time, newest first
|
542 |
filename = os.path.basename(media_file)
|
543 |
-
timestamp_str, uploader = filename.split('_', 1)
|
544 |
-
uploader = uploader.rsplit('.', 1)[0] # Remove extension
|
545 |
-
timestamp = datetime.strptime(timestamp_str, "%Y%m%d%H%M%S").strftime("%Y-%m-%d %H:%M:%S")
|
546 |
vote_count = media_votes.get(media_file, 0)
|
547 |
|
548 |
-
col1, col2
|
549 |
with col1:
|
550 |
-
st.markdown(f"**{filename}**
|
551 |
if media_file.endswith(('.png', '.jpg')):
|
552 |
st.image(media_file, use_container_width=True)
|
553 |
elif media_file.endswith('.mp4'):
|
554 |
st.markdown(await get_video_html(media_file), unsafe_allow_html=True)
|
|
|
|
|
555 |
with col2:
|
556 |
if st.button(f"π {vote_count}", key=f"media_vote_{media_file}"):
|
557 |
-
|
558 |
-
await save_vote(MEDIA_VOTES_FILE, media_file, await generate_user_hash(), st.session_state.username, comment)
|
559 |
-
st.session_state.message_text = ''
|
560 |
-
st.rerun()
|
561 |
-
with col3:
|
562 |
-
if st.button("ποΈ", key=f"media_delete_{media_file}"):
|
563 |
-
await asyncio.to_thread(os.remove, media_file)
|
564 |
st.rerun()
|
565 |
-
with col4:
|
566 |
-
pass # Placeholder for potential future use
|
567 |
|
568 |
st.subheader("Refresh β³")
|
569 |
refresh_rate = st.slider("Refresh Rate", 1, 300, st.session_state.refresh_rate)
|
|
|
18 |
from audio_recorder_streamlit import audio_recorder
|
19 |
import nest_asyncio
|
20 |
import re
|
21 |
+
from streamlit_paste_button import paste_image_button # Import the new library
|
22 |
|
23 |
# Patch for nested async - sneaky fix! πβ¨
|
24 |
nest_asyncio.apply()
|
|
|
419 |
st.image(file_path, use_container_width=True)
|
420 |
elif file_path.endswith('.mp4'):
|
421 |
st.markdown(await get_video_html(file_path), unsafe_allow_html=True)
|
422 |
+
elif file_path.endswith('.mp3'):
|
423 |
+
st.markdown(await get_audio_html(file_path), unsafe_allow_html=True)
|
424 |
with col2:
|
425 |
vote_count = chat_votes.get(line.split('. ')[1] if '. ' in line else line, 0)
|
426 |
if st.button(f"π {vote_count}", key=f"chat_vote_{i}"):
|
|
|
473 |
message = st.text_input(f"Message as {st.session_state.username}", key="message_input", value=st.session_state.message_text, on_change=lambda: st.session_state.update(message_text=st.session_state.message_input))
|
474 |
if st.button("Send π", key="send_button") and message.strip():
|
475 |
await save_chat_entry(st.session_state.username, message)
|
|
|
|
|
|
|
|
|
|
|
476 |
st.session_state.message_text = ''
|
477 |
st.rerun()
|
478 |
|
479 |
+
# Paste Image Button
|
480 |
+
paste_result = paste_image_button("π Paste Image", key="paste_button")
|
481 |
+
if paste_result.image_data is not None:
|
482 |
+
st.image(paste_result.image_data, caption="Received Image")
|
483 |
+
filename = await save_pasted_image(base64.b64encode(paste_result.image_data.tobytes()).decode(), st.session_state.username)
|
484 |
+
if filename:
|
485 |
+
await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
486 |
+
st.session_state.pasted_image_data = None
|
487 |
|
488 |
# Main action tabs and model use choices
|
489 |
tab_main = st.radio("Action:", ["π€ Voice", "πΈ Media", "π ArXiv", "π Editor"], horizontal=True)
|
490 |
useArxiv = st.checkbox("Search Arxiv for Research Paper Answers", value=True)
|
491 |
useArxivAudio = st.checkbox("Generate Audio File for Research Paper Answers", value=False)
|
492 |
|
493 |
+
# Custom component for ASR
|
494 |
+
mycomponent = components.declare_component("mycomponent", path="./frontend")
|
495 |
+
val = mycomponent(my_input_value="Hello from MyComponent")
|
496 |
+
|
497 |
if val:
|
498 |
if isinstance(val, dict):
|
499 |
if val.get('type') == 'text' and 'transcript' in val:
|
500 |
val_stripped = val['transcript'].replace('\n', ' ')
|
501 |
if val_stripped.strip():
|
502 |
await save_chat_entry(st.session_state.username, val_stripped)
|
|
|
|
|
|
|
|
|
|
|
503 |
|
504 |
edited_input = st.text_area("βοΈ Edit Input:", value=val_stripped if isinstance(val, dict) and val.get('type') == 'text' else "", height=100)
|
505 |
run_option = st.selectbox("Model:", ["Arxiv", "Other (demo)"])
|
|
|
521 |
st.session_state.last_query = edited_input
|
522 |
await perform_ai_lookup(edited_input, vocal_summary=True, extended_refs=False, titles_summary=True, full_audio=full_audio, useArxiv=useArxiv, useArxivAudio=useArxivAudio)
|
523 |
|
524 |
+
st.subheader("Upload Media π¨πΆπ₯")
|
525 |
+
uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp4', 'mp3'])
|
526 |
if uploaded_file:
|
527 |
timestamp = format_timestamp_prefix()
|
528 |
username = st.session_state.username
|
|
|
535 |
if file_path.endswith('.mp4'):
|
536 |
st.session_state.media_notifications.append(file_path)
|
537 |
|
538 |
+
# Enhanced Media Gallery with Image, Audio, Video
|
539 |
+
st.subheader("Media Gallery π¨πΆπ₯")
|
540 |
+
media_files = glob.glob(f"{MEDIA_DIR}/*.png") + glob.glob(f"{MEDIA_DIR}/*.jpg") + glob.glob(f"{MEDIA_DIR}/*.mp4") + glob.glob(f"{MEDIA_DIR}/*.mp3")
|
541 |
if media_files:
|
542 |
media_votes = await load_votes(MEDIA_VOTES_FILE)
|
543 |
st.write("### All Media Uploads")
|
544 |
for media_file in sorted(media_files, key=os.path.getmtime, reverse=True): # Sort by modification time, newest first
|
545 |
filename = os.path.basename(media_file)
|
|
|
|
|
|
|
546 |
vote_count = media_votes.get(media_file, 0)
|
547 |
|
548 |
+
col1, col2 = st.columns([3, 1])
|
549 |
with col1:
|
550 |
+
st.markdown(f"**{filename}**")
|
551 |
if media_file.endswith(('.png', '.jpg')):
|
552 |
st.image(media_file, use_container_width=True)
|
553 |
elif media_file.endswith('.mp4'):
|
554 |
st.markdown(await get_video_html(media_file), unsafe_allow_html=True)
|
555 |
+
elif media_file.endswith('.mp3'):
|
556 |
+
st.markdown(await get_audio_html(media_file), unsafe_allow_html=True)
|
557 |
with col2:
|
558 |
if st.button(f"π {vote_count}", key=f"media_vote_{media_file}"):
|
559 |
+
await save_vote(MEDIA_VOTES_FILE, media_file, await generate_user_hash(), st.session_state.username)
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
st.rerun()
|
|
|
|
|
561 |
|
562 |
st.subheader("Refresh β³")
|
563 |
refresh_rate = st.slider("Refresh Rate", 1, 300, st.session_state.refresh_rate)
|