awacke1 commited on
Commit
1f0db54
Β·
verified Β·
1 Parent(s): a986a94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -38
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)), # Fixed to add offset
102
- ("Regional Indicator", lambda x: "".join(chr(ord(c) - 0x41 + 0x1F1E6) if 'A' <= c <= 'Z' else c for c in x)), # Fixed to add offset
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
- image_path = line.split("Pasted image: ")[1].strip()
416
- if os.path.exists(image_path):
417
- st.image(image_path, use_container_width=True)
 
 
 
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', 'mp3', 'mp4'])
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
- media_files = glob.glob(f"{MEDIA_DIR}/*.png") + glob.glob(f"{MEDIA_DIR}/*.jpg") + glob.glob(f"{MEDIA_DIR}/*.mp3") + glob.glob(f"{MEDIA_DIR}/*.mp4")
 
533
  if media_files:
534
  media_votes = await load_votes(MEDIA_VOTES_FILE)
535
- users = sorted(set(f.split('_')[-1].split('.')[0] for f in media_files))
536
- for user in users:
537
- with st.expander(f"{user}'s Media"):
538
- user_files = [f for f in media_files if user in f]
539
- for media_file in user_files:
540
- vote_count = media_votes.get(media_file, 0)
541
- if vote_count > 0:
542
- col1, col2, col3 = st.columns([3, 1, 1])
543
- with col1:
544
- if media_file.endswith(('.png', '.jpg')):
545
- st.image(media_file, use_container_width=True, caption=os.path.basename(media_file))
546
- elif media_file.endswith('.mp3'):
547
- st.markdown(await get_audio_html(media_file), unsafe_allow_html=True)
548
- st.caption(os.path.basename(media_file))
549
- elif media_file.endswith('.mp4'):
550
- st.markdown(await get_video_html(media_file), unsafe_allow_html=True)
551
- st.caption(os.path.basename(media_file))
552
- if media_file in st.session_state.media_notifications:
553
- st.session_state.media_notifications.remove(media_file)
554
- with col2:
555
- if st.button(f"πŸ‘ {vote_count}", key=f"media_vote_{media_file}"):
556
- comment = st.session_state.message_text
557
- await save_vote(MEDIA_VOTES_FILE, media_file, await generate_user_hash(), st.session_state.username, comment)
558
- st.session_state.message_text = ''
559
- st.rerun()
560
- with col3:
561
- if st.button("πŸ—‘οΈ", key=f"media_delete_{media_file}"):
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 instead of asyncio.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 πŸ“œ")