Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -87,7 +87,7 @@ def load_username():
|
|
87 |
return f.read().strip()
|
88 |
return None
|
89 |
|
90 |
-
# Audio Processing
|
91 |
async def async_edge_tts_generate(text, voice, username):
|
92 |
cache_key = f"{text[:100]}_{voice}"
|
93 |
if cache_key in st.session_state['audio_cache']:
|
@@ -106,7 +106,20 @@ def play_and_download_audio(file_path):
|
|
106 |
st.audio(file_path)
|
107 |
st.markdown(get_download_link(file_path), unsafe_allow_html=True)
|
108 |
|
109 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
async def save_chat_entry(username, message, voice, is_markdown=False):
|
111 |
if not message.strip() or message == st.session_state.last_transcript:
|
112 |
return None, None
|
@@ -204,18 +217,6 @@ async def websocket_handler(websocket, path):
|
|
204 |
if room_id in st.session_state.active_connections and client_id in st.session_state.active_connections[room_id]:
|
205 |
del st.session_state.active_connections[room_id][client_id]
|
206 |
|
207 |
-
async def broadcast_message(message, room_id):
|
208 |
-
if room_id in st.session_state.active_connections:
|
209 |
-
disconnected = []
|
210 |
-
for client_id, ws in st.session_state.active_connections[room_id].items():
|
211 |
-
try:
|
212 |
-
await ws.send(message)
|
213 |
-
except websockets.ConnectionClosed:
|
214 |
-
disconnected.append(client_id)
|
215 |
-
for client_id in disconnected:
|
216 |
-
if client_id in st.session_state.active_connections[room_id]:
|
217 |
-
del st.session_state.active_connections[room_id][client_id]
|
218 |
-
|
219 |
async def periodic_update():
|
220 |
while True:
|
221 |
if st.session_state.active_connections.get("quest"):
|
|
|
87 |
return f.read().strip()
|
88 |
return None
|
89 |
|
90 |
+
# Audio Processing
|
91 |
async def async_edge_tts_generate(text, voice, username):
|
92 |
cache_key = f"{text[:100]}_{voice}"
|
93 |
if cache_key in st.session_state['audio_cache']:
|
|
|
106 |
st.audio(file_path)
|
107 |
st.markdown(get_download_link(file_path), unsafe_allow_html=True)
|
108 |
|
109 |
+
# WebSocket Broadcast (Moved Up for save_chat_entry Dependency)
|
110 |
+
async def broadcast_message(message, room_id):
|
111 |
+
if room_id in st.session_state.active_connections:
|
112 |
+
disconnected = []
|
113 |
+
for client_id, ws in st.session_state.active_connections[room_id].items():
|
114 |
+
try:
|
115 |
+
await ws.send(message)
|
116 |
+
except websockets.ConnectionClosed:
|
117 |
+
disconnected.append(client_id)
|
118 |
+
for client_id in disconnected:
|
119 |
+
if client_id in st.session_state.active_connections[room_id]:
|
120 |
+
del st.session_state.active_connections[room_id][client_id]
|
121 |
+
|
122 |
+
# Chat and Quest Log
|
123 |
async def save_chat_entry(username, message, voice, is_markdown=False):
|
124 |
if not message.strip() or message == st.session_state.last_transcript:
|
125 |
return None, None
|
|
|
217 |
if room_id in st.session_state.active_connections and client_id in st.session_state.active_connections[room_id]:
|
218 |
del st.session_state.active_connections[room_id][client_id]
|
219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
async def periodic_update():
|
221 |
while True:
|
222 |
if st.session_state.active_connections.get("quest"):
|