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()
|
@@ -115,8 +116,6 @@ if 'last_chat_update' not in st.session_state:
|
|
115 |
st.session_state.last_chat_update = 0
|
116 |
if 'displayed_chat_lines' not in st.session_state:
|
117 |
st.session_state.displayed_chat_lines = []
|
118 |
-
if 'pasted_image_data_temp' not in st.session_state:
|
119 |
-
st.session_state.pasted_image_data_temp = None
|
120 |
|
121 |
# Timestamp wizardry - clock ticks with flair! β°π©
|
122 |
def format_timestamp_prefix():
|
@@ -378,7 +377,6 @@ def create_streamlit_interface():
|
|
378 |
.chat-box {font-family: monospace; background: #1e1e1e; color: #d4d4d4; padding: 10px; border-radius: 5px; height: 300px; overflow-y: auto;}
|
379 |
.timer {font-size: 24px; color: #ffcc00; text-align: center; animation: pulse 1s infinite;}
|
380 |
@keyframes pulse {0% {transform: scale(1);} 50% {transform: scale(1.1);} 100% {transform: scale(1);}}
|
381 |
-
#paste-target {border: 2px dashed #ccc; padding: 20px; text-align: center; cursor: pointer;}
|
382 |
</style>
|
383 |
""", unsafe_allow_html=True)
|
384 |
|
@@ -479,51 +477,15 @@ def create_streamlit_interface():
|
|
479 |
st.session_state.message_text = ''
|
480 |
st.rerun()
|
481 |
|
482 |
-
#
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
if (items[i].type.indexOf('image') !== -1) {
|
492 |
-
const blob = items[i].getAsFile();
|
493 |
-
const reader = new FileReader();
|
494 |
-
reader.onload = (e) => {
|
495 |
-
window.parent.postMessage({
|
496 |
-
type: 'streamlit:setComponentValue',
|
497 |
-
value: e.target.result
|
498 |
-
}, '*');
|
499 |
-
pasteTarget.innerHTML = '<p>Image pasted! Processing...</p>';
|
500 |
-
// Trigger a custom event to notify Python
|
501 |
-
window.parent.postMessage({
|
502 |
-
type: 'streamlit:imagePasted',
|
503 |
-
value: e.target.result
|
504 |
-
}, '*');
|
505 |
-
};
|
506 |
-
reader.readAsDataURL(blob);
|
507 |
-
}
|
508 |
-
}
|
509 |
-
event.preventDefault();
|
510 |
-
});
|
511 |
-
</script>
|
512 |
-
""",
|
513 |
-
height=100
|
514 |
-
)
|
515 |
-
|
516 |
-
# Custom JavaScript listener for pasted image (simulated via session state)
|
517 |
-
if 'pasted_image_data_temp' in st.session_state and st.session_state.pasted_image_data_temp and st.session_state.pasted_image_data != st.session_state.pasted_image_data_temp:
|
518 |
-
pasted_image_data = st.session_state.pasted_image_data_temp
|
519 |
-
if isinstance(pasted_image_data, str):
|
520 |
-
st.session_state.pasted_image_data = pasted_image_data
|
521 |
-
filename = await save_pasted_image(st.session_state.pasted_image_data, st.session_state.username)
|
522 |
-
if filename:
|
523 |
-
await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
524 |
-
st.session_state.pasted_image_data = None
|
525 |
-
st.session_state.pasted_image_data_temp = None # Clear after processing
|
526 |
-
st.rerun()
|
527 |
|
528 |
st.subheader("Media Gallery π¨πΆπ₯")
|
529 |
uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp3', 'mp4'])
|
|
|
18 |
from audio_recorder_streamlit import audio_recorder
|
19 |
import nest_asyncio
|
20 |
import re
|
21 |
+
from image_paster import image_paster # Import the custom component
|
22 |
|
23 |
# Patch for nested async - sneaky fix! πβ¨
|
24 |
nest_asyncio.apply()
|
|
|
116 |
st.session_state.last_chat_update = 0
|
117 |
if 'displayed_chat_lines' not in st.session_state:
|
118 |
st.session_state.displayed_chat_lines = []
|
|
|
|
|
119 |
|
120 |
# Timestamp wizardry - clock ticks with flair! β°π©
|
121 |
def format_timestamp_prefix():
|
|
|
377 |
.chat-box {font-family: monospace; background: #1e1e1e; color: #d4d4d4; padding: 10px; border-radius: 5px; height: 300px; overflow-y: auto;}
|
378 |
.timer {font-size: 24px; color: #ffcc00; text-align: center; animation: pulse 1s infinite;}
|
379 |
@keyframes pulse {0% {transform: scale(1);} 50% {transform: scale(1.1);} 100% {transform: scale(1);}}
|
|
|
380 |
</style>
|
381 |
""", unsafe_allow_html=True)
|
382 |
|
|
|
477 |
st.session_state.message_text = ''
|
478 |
st.rerun()
|
479 |
|
480 |
+
# Use the custom image paster component
|
481 |
+
pasted_image_data = image_paster()
|
482 |
+
if pasted_image_data and st.session_state.pasted_image_data != pasted_image_data:
|
483 |
+
st.session_state.pasted_image_data = pasted_image_data
|
484 |
+
filename = await save_pasted_image(st.session_state.pasted_image_data, st.session_state.username)
|
485 |
+
if filename:
|
486 |
+
await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
487 |
+
st.session_state.pasted_image_data = None
|
488 |
+
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
489 |
|
490 |
st.subheader("Media Gallery π¨πΆπ₯")
|
491 |
uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp3', 'mp4'])
|