Update app.py
Browse files
app.py
CHANGED
@@ -258,6 +258,8 @@ async def save_chat_entry(username, message, is_markdown=False, quote_line=None)
|
|
258 |
f.write(f"[{timestamp}] {username} ({voice}): Audio generated - {audio_filename}\n")
|
259 |
with open(user_history_file, 'a') as f:
|
260 |
f.write(f"{indent}[{timestamp}] Audio: {audio_filename}\n")
|
|
|
|
|
261 |
|
262 |
# Embed audio and image in global chat if applicable
|
263 |
if message.startswith("Pasted image:") or message.startswith("Uploaded media:") or message.startswith("Uploaded PDF:"):
|
@@ -449,7 +451,12 @@ async def get_audio_html(audio_path, width="100%"):
|
|
449 |
username = st.session_state.get('username', 'System π')
|
450 |
await asyncio.to_thread(log_action, username, "πΆβοΈ - Audio renderer - sounds soar!")
|
451 |
audio_url = f"data:audio/mpeg;base64,{base64.b64encode(await asyncio.to_thread(open, audio_path, 'rb').read()).decode()}"
|
452 |
-
return f'
|
|
|
|
|
|
|
|
|
|
|
453 |
|
454 |
# Websocket handler - chat links up! ππ
|
455 |
async def websocket_handler(websocket, path):
|
@@ -590,15 +597,13 @@ def main():
|
|
590 |
elif file_path.endswith('.pdf'):
|
591 |
st.write(f"PDF: {os.path.basename(file_path)}")
|
592 |
with col_audio:
|
593 |
-
|
594 |
-
cache_key = f"{line}_{FUN_USERNAMES.get(username, 'en-US-AriaNeural')}"
|
595 |
-
if cache_key not in st.session_state.audio_cache and "Audio:" in line:
|
596 |
audio_ref = line.split("Audio: ")[-1].strip()
|
597 |
if os.path.exists(audio_ref):
|
|
|
|
|
|
|
598 |
st.session_state.audio_cache[cache_key] = audio_ref
|
599 |
-
audio_file = st.session_state.audio_cache.get(cache_key)
|
600 |
-
if audio_file:
|
601 |
-
play_and_download_audio(audio_file)
|
602 |
|
603 |
if st.session_state.quote_line:
|
604 |
st.markdown(f"### Quoting: {st.session_state.quote_line}")
|
@@ -714,33 +719,30 @@ def main():
|
|
714 |
time.sleep(1)
|
715 |
st.rerun()
|
716 |
|
717 |
-
# Gallery with Adjustable Tiles
|
718 |
-
st.subheader("
|
719 |
-
|
720 |
-
st.
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
await save_vote(MEDIA_VOTES_FILE, media_file, await generate_user_hash(), st.session_state.username)
|
742 |
-
st.rerun()
|
743 |
-
col_idx = (col_idx + 1) % gallery_columns
|
744 |
|
745 |
# Full Log at End
|
746 |
st.subheader("Full Chat Log π")
|
|
|
258 |
f.write(f"[{timestamp}] {username} ({voice}): Audio generated - {audio_filename}\n")
|
259 |
with open(user_history_file, 'a') as f:
|
260 |
f.write(f"{indent}[{timestamp}] Audio: {audio_filename}\n")
|
261 |
+
with open(CHAT_FILE, 'a') as f:
|
262 |
+
f.write(f"{indent}[{timestamp}] Audio: {audio_filename}\n")
|
263 |
|
264 |
# Embed audio and image in global chat if applicable
|
265 |
if message.startswith("Pasted image:") or message.startswith("Uploaded media:") or message.startswith("Uploaded PDF:"):
|
|
|
451 |
username = st.session_state.get('username', 'System π')
|
452 |
await asyncio.to_thread(log_action, username, "πΆβοΈ - Audio renderer - sounds soar!")
|
453 |
audio_url = f"data:audio/mpeg;base64,{base64.b64encode(await asyncio.to_thread(open, audio_path, 'rb').read()).decode()}"
|
454 |
+
return f'''
|
455 |
+
<audio controls style="width: {width};">
|
456 |
+
<source src="{audio_url}" type="audio/mpeg">
|
457 |
+
Your browser does not support the audio element.
|
458 |
+
</audio>
|
459 |
+
'''
|
460 |
|
461 |
# Websocket handler - chat links up! ππ
|
462 |
async def websocket_handler(websocket, path):
|
|
|
597 |
elif file_path.endswith('.pdf'):
|
598 |
st.write(f"PDF: {os.path.basename(file_path)}")
|
599 |
with col_audio:
|
600 |
+
if "Audio:" in line:
|
|
|
|
|
601 |
audio_ref = line.split("Audio: ")[-1].strip()
|
602 |
if os.path.exists(audio_ref):
|
603 |
+
play_and_download_audio(audio_ref)
|
604 |
+
username = line.split(': ')[1].split(' ')[0] if ': ' in line else "Unknown"
|
605 |
+
cache_key = f"{line}_{FUN_USERNAMES.get(username, 'en-US-AriaNeural')}"
|
606 |
st.session_state.audio_cache[cache_key] = audio_ref
|
|
|
|
|
|
|
607 |
|
608 |
if st.session_state.quote_line:
|
609 |
st.markdown(f"### Quoting: {st.session_state.quote_line}")
|
|
|
719 |
time.sleep(1)
|
720 |
st.rerun()
|
721 |
|
722 |
+
# Gallery with Adjustable Tiles - Consistent Three-Set from Provided Code
|
723 |
+
st.subheader("Image Gallery πΌ")
|
724 |
+
image_files = glob.glob("*.png") + glob.glob("*.jpg") + glob.glob("*.jpeg")
|
725 |
+
image_cols = st.slider("Image Gallery Columns πΌ", min_value=1, max_value=15, value=5)
|
726 |
+
cols = st.columns(image_cols)
|
727 |
+
for idx, image_file in enumerate(image_files):
|
728 |
+
with cols[idx % image_cols]:
|
729 |
+
st.image(image_file, use_container_width=True)
|
730 |
+
|
731 |
+
st.subheader("Video Gallery π₯")
|
732 |
+
video_files = glob.glob("*.mp4")
|
733 |
+
video_cols = st.slider("Video Gallery Columns π¬", min_value=1, max_value=5, value=3)
|
734 |
+
cols = st.columns(video_cols)
|
735 |
+
for idx, video_file in enumerate(video_files):
|
736 |
+
with cols[idx % video_cols]:
|
737 |
+
st.markdown(get_video_html(video_file, width="100%"), unsafe_allow_html=True)
|
738 |
+
|
739 |
+
st.subheader("Audio Gallery π§")
|
740 |
+
audio_files = glob.glob("*.mp3") + glob.glob("*.wav")
|
741 |
+
audio_cols = st.slider("Audio Gallery Columns πΆ", min_value=1, max_value=15, value=5)
|
742 |
+
cols = st.columns(audio_cols)
|
743 |
+
for idx, audio_file in enumerate(audio_files):
|
744 |
+
with cols[idx % audio_cols]:
|
745 |
+
st.markdown(await get_audio_html(audio_file, width="100%"), unsafe_allow_html=True)
|
|
|
|
|
|
|
746 |
|
747 |
# Full Log at End
|
748 |
st.subheader("Full Chat Log π")
|