Update app.py
Browse files
app.py
CHANGED
@@ -98,8 +98,8 @@ UNICODE_FONTS = [
|
|
98 |
("Circled", lambda x: "".join(chr(ord(c) - 0x41 + 0x24B6) if 'A' <= c <= 'Z' else chr(ord(c) - 0x61 + 0x24D0) if 'a' <= c <= 'z' else c for c in x)),
|
99 |
("Squared", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F130) if 'A' <= c <= 'Z' else c for c in x)),
|
100 |
("Negative Circled", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F150) if 'A' <= c <= 'Z' else c for c in x)),
|
101 |
-
("Negative Squared", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F170) if 'A' <= c <= 'Z' else c for c in x)),
|
102 |
-
("Regional Indicator", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F1E6) if 'A' <= c <= 'Z' else c for c in x)),
|
103 |
]
|
104 |
|
105 |
# Global state - keeping tabs! ππ
|
@@ -411,10 +411,13 @@ def main():
|
|
411 |
col1, col2, col3, col4 = st.columns([3, 1, 1, 2])
|
412 |
with col1:
|
413 |
st.markdown(line)
|
414 |
-
if "Pasted image:" in line:
|
415 |
-
|
416 |
-
if os.path.exists(
|
417 |
-
|
|
|
|
|
|
|
418 |
with col2:
|
419 |
vote_count = chat_votes.get(line.split('. ')[1] if '. ' in line else line, 0)
|
420 |
if st.button(f"π {vote_count}", key=f"chat_vote_{i}"):
|
@@ -494,6 +497,7 @@ def main():
|
|
494 |
filename = await save_pasted_image(val['image'], st.session_state.username)
|
495 |
if filename:
|
496 |
await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
|
|
497 |
|
498 |
edited_input = st.text_area("βοΈ Edit Input:", value=val_stripped if isinstance(val, dict) and val.get('type') == 'text' else "", height=100)
|
499 |
run_option = st.selectbox("Model:", ["Arxiv", "Other (demo)"])
|
@@ -516,7 +520,7 @@ def main():
|
|
516 |
await perform_ai_lookup(edited_input, vocal_summary=True, extended_refs=False, titles_summary=True, full_audio=full_audio, useArxiv=useArxiv, useArxivAudio=useArxivAudio)
|
517 |
|
518 |
st.subheader("Media Gallery π¨πΆπ₯")
|
519 |
-
uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', '
|
520 |
if uploaded_file:
|
521 |
timestamp = format_timestamp_prefix()
|
522 |
username = st.session_state.username
|
@@ -529,38 +533,37 @@ def main():
|
|
529 |
if file_path.endswith('.mp4'):
|
530 |
st.session_state.media_notifications.append(file_path)
|
531 |
|
532 |
-
|
|
|
533 |
if media_files:
|
534 |
media_votes = await load_votes(MEDIA_VOTES_FILE)
|
535 |
-
|
536 |
-
for
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
await asyncio.to_thread(os.remove, media_file)
|
563 |
-
st.rerun()
|
564 |
|
565 |
st.subheader("Refresh β³")
|
566 |
refresh_rate = st.slider("Refresh Rate", 1, 300, st.session_state.refresh_rate)
|
@@ -570,7 +573,7 @@ def main():
|
|
570 |
font_name, font_func = random.choice(UNICODE_FONTS)
|
571 |
countdown_str = "".join(UNICODE_DIGITS[int(d)] for d in str(i)) if i < 10 else font_func(str(i))
|
572 |
timer_placeholder.markdown(f"<p class='timer'>β³ {font_func('Refresh in:')} {countdown_str}</p>", unsafe_allow_html=True)
|
573 |
-
time.sleep(1) # Use synchronous sleep
|
574 |
st.rerun()
|
575 |
|
576 |
st.sidebar.subheader("Chat History π")
|
|
|
98 |
("Circled", lambda x: "".join(chr(ord(c) - 0x41 + 0x24B6) if 'A' <= c <= 'Z' else chr(ord(c) - 0x61 + 0x24D0) if 'a' <= c <= 'z' else c for c in x)),
|
99 |
("Squared", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F130) if 'A' <= c <= 'Z' else c for c in x)),
|
100 |
("Negative Circled", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F150) if 'A' <= c <= 'Z' else c for c in x)),
|
101 |
+
("Negative Squared", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F170) if 'A' <= c <= 'Z' else c for c in x)),
|
102 |
+
("Regional Indicator", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F1E6) if 'A' <= c <= 'Z' else c for c in x)),
|
103 |
]
|
104 |
|
105 |
# Global state - keeping tabs! ππ
|
|
|
411 |
col1, col2, col3, col4 = st.columns([3, 1, 1, 2])
|
412 |
with col1:
|
413 |
st.markdown(line)
|
414 |
+
if "Pasted image:" in line or "Uploaded media:" in line:
|
415 |
+
file_path = line.split(': ')[-1].strip()
|
416 |
+
if os.path.exists(file_path):
|
417 |
+
if file_path.endswith(('.png', '.jpg')):
|
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}"):
|
|
|
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)"])
|
|
|
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 Gallery π¨πΆπ₯")
|
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 |
if file_path.endswith('.mp4'):
|
534 |
st.session_state.media_notifications.append(file_path)
|
535 |
|
536 |
+
# Enhanced Media Gallery
|
537 |
+
media_files = glob.glob(f"{MEDIA_DIR}/*.png") + glob.glob(f"{MEDIA_DIR}/*.jpg") + glob.glob(f"{MEDIA_DIR}/*.mp4")
|
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, col3, col4 = st.columns([3, 1, 1, 2])
|
549 |
+
with col1:
|
550 |
+
st.markdown(f"**{filename}** - Uploaded by {uploader} at {timestamp}")
|
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 |
+
comment = st.session_state.message_text
|
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)
|
|
|
573 |
font_name, font_func = random.choice(UNICODE_FONTS)
|
574 |
countdown_str = "".join(UNICODE_DIGITS[int(d)] for d in str(i)) if i < 10 else font_func(str(i))
|
575 |
timer_placeholder.markdown(f"<p class='timer'>β³ {font_func('Refresh in:')} {countdown_str}</p>", unsafe_allow_html=True)
|
576 |
+
time.sleep(1) # Use synchronous sleep
|
577 |
st.rerun()
|
578 |
|
579 |
st.sidebar.subheader("Chat History π")
|