Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,6 +149,24 @@ async def generate_chat_audio(username, message, voice):
|
|
| 149 |
audio_file = await async_edge_tts_generate(message, voice, username)
|
| 150 |
return audio_file
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
async def save_chat_entry(username, message, voice, is_markdown=False):
|
| 153 |
if not message.strip() or message == st.session_state.get('last_transcript', ''):
|
| 154 |
return None, None
|
|
@@ -226,18 +244,6 @@ init_session_state()
|
|
| 226 |
# -----------------------------
|
| 227 |
# WebSocket and Multiplayer Functions
|
| 228 |
# -----------------------------
|
| 229 |
-
async def broadcast_message(message, room_id):
|
| 230 |
-
if room_id in st.session_state.active_connections:
|
| 231 |
-
disconnected = []
|
| 232 |
-
for client_id, ws in st.session_state.active_connections[room_id].items():
|
| 233 |
-
try:
|
| 234 |
-
await ws.send(message)
|
| 235 |
-
except websockets.ConnectionClosed:
|
| 236 |
-
disconnected.append(client_id)
|
| 237 |
-
for client_id in disconnected:
|
| 238 |
-
if client_id in st.session_state.active_connections[room_id]:
|
| 239 |
-
del st.session_state.active_connections[room_id][client_id]
|
| 240 |
-
|
| 241 |
async def websocket_handler(websocket, path):
|
| 242 |
client_id = str(uuid.uuid4())
|
| 243 |
room_id = "quest"
|
|
@@ -388,7 +394,10 @@ def log_performance_metrics():
|
|
| 388 |
# -----------------------------
|
| 389 |
# Enhanced 3D World HTML
|
| 390 |
# -----------------------------
|
| 391 |
-
#
|
|
|
|
|
|
|
|
|
|
| 392 |
rocky_map_html = f"""
|
| 393 |
<!DOCTYPE html>
|
| 394 |
<html lang="en">
|
|
@@ -556,7 +565,7 @@ rocky_map_html = f"""
|
|
| 556 |
}}
|
| 557 |
const mesh = playerMeshes[player.username];
|
| 558 |
mesh.position.set(player.x, 1, player.z);
|
| 559 |
-
players[player.username] = {{
|
| 560 |
if(player.username === playerName) {{
|
| 561 |
xPos = player.x;
|
| 562 |
zPos = player.z;
|
|
@@ -657,7 +666,7 @@ rocky_map_html = f"""
|
|
| 657 |
# -----------------------------
|
| 658 |
def main():
|
| 659 |
st.markdown(f"<h2 style='text-align: center;'>Welcome, {st.session_state.username}!</h2>", unsafe_allow_html=True)
|
| 660 |
-
# Chat Input
|
| 661 |
message = st.text_input(f"π¨οΈ Chat as {st.session_state.username}:", placeholder="Type to chat or add world features! π²", key="chat_input")
|
| 662 |
if st.button("π Send"):
|
| 663 |
if message:
|
|
@@ -668,7 +677,7 @@ def main():
|
|
| 668 |
st.session_state.last_activity = time.time()
|
| 669 |
st.success(f"π +10 points! New Score: ${st.session_state.score}")
|
| 670 |
|
| 671 |
-
# Display Quest Log as a
|
| 672 |
chat_content = asyncio.run(load_chat())
|
| 673 |
st.code("\n".join(chat_content[-10:]), language="python")
|
| 674 |
|
|
|
|
| 149 |
audio_file = await async_edge_tts_generate(message, voice, username)
|
| 150 |
return audio_file
|
| 151 |
|
| 152 |
+
# -----------------------------
|
| 153 |
+
# Broadcast Message (defined before usage)
|
| 154 |
+
# -----------------------------
|
| 155 |
+
async def broadcast_message(message, room_id):
|
| 156 |
+
if room_id in st.session_state.active_connections:
|
| 157 |
+
disconnected = []
|
| 158 |
+
for client_id, ws in st.session_state.active_connections[room_id].items():
|
| 159 |
+
try:
|
| 160 |
+
await ws.send(message)
|
| 161 |
+
except websockets.ConnectionClosed:
|
| 162 |
+
disconnected.append(client_id)
|
| 163 |
+
for client_id in disconnected:
|
| 164 |
+
if client_id in st.session_state.active_connections[room_id]:
|
| 165 |
+
del st.session_state.active_connections[room_id][client_id]
|
| 166 |
+
|
| 167 |
+
# -----------------------------
|
| 168 |
+
# Chat Entry Saving Function
|
| 169 |
+
# -----------------------------
|
| 170 |
async def save_chat_entry(username, message, voice, is_markdown=False):
|
| 171 |
if not message.strip() or message == st.session_state.get('last_transcript', ''):
|
| 172 |
return None, None
|
|
|
|
| 244 |
# -----------------------------
|
| 245 |
# WebSocket and Multiplayer Functions
|
| 246 |
# -----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
async def websocket_handler(websocket, path):
|
| 248 |
client_id = str(uuid.uuid4())
|
| 249 |
room_id = "quest"
|
|
|
|
| 394 |
# -----------------------------
|
| 395 |
# Enhanced 3D World HTML
|
| 396 |
# -----------------------------
|
| 397 |
+
# Precompute player attributes for correct interpolation.
|
| 398 |
+
player_color = next(c["color"] for c in EDGE_TTS_VOICES if c["name"] == st.session_state.username)
|
| 399 |
+
player_shape = next(c["shape"] for c in EDGE_TTS_VOICES if c["name"] == st.session_state.username)
|
| 400 |
+
|
| 401 |
rocky_map_html = f"""
|
| 402 |
<!DOCTYPE html>
|
| 403 |
<html lang="en">
|
|
|
|
| 565 |
}}
|
| 566 |
const mesh = playerMeshes[player.username];
|
| 567 |
mesh.position.set(player.x, 1, player.z);
|
| 568 |
+
players[player.username] = {{ score: player.score, treasures: player.treasures }};
|
| 569 |
if(player.username === playerName) {{
|
| 570 |
xPos = player.x;
|
| 571 |
zPos = player.z;
|
|
|
|
| 666 |
# -----------------------------
|
| 667 |
def main():
|
| 668 |
st.markdown(f"<h2 style='text-align: center;'>Welcome, {st.session_state.username}!</h2>", unsafe_allow_html=True)
|
| 669 |
+
# Chat Input Section
|
| 670 |
message = st.text_input(f"π¨οΈ Chat as {st.session_state.username}:", placeholder="Type to chat or add world features! π²", key="chat_input")
|
| 671 |
if st.button("π Send"):
|
| 672 |
if message:
|
|
|
|
| 677 |
st.session_state.last_activity = time.time()
|
| 678 |
st.success(f"π +10 points! New Score: ${st.session_state.score}")
|
| 679 |
|
| 680 |
+
# Display Quest Log as a Code Block (with Python formatting)
|
| 681 |
chat_content = asyncio.run(load_chat())
|
| 682 |
st.code("\n".join(chat_content[-10:]), language="python")
|
| 683 |
|