awacke1 commited on
Commit
642d274
Β·
verified Β·
1 Parent(s): a0094de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -24
app.py CHANGED
@@ -6,7 +6,6 @@ from datetime import datetime
6
  import os
7
  import random
8
  import hashlib
9
- import glob
10
  import base64
11
  import edge_tts
12
  import nest_asyncio
@@ -162,7 +161,7 @@ def init_session_state():
162
  'speech_processed': False, 'players': {}, 'last_update': time.time(),
163
  'update_interval': 20, 'x_pos': 0, 'z_pos': 0, 'move_left': False,
164
  'move_right': False, 'move_up': False, 'move_down': False,
165
- 'prairie_players': {} # New for prairie simulator
166
  }
167
  for k, v in defaults.items():
168
  if k not in st.session_state:
@@ -198,11 +197,10 @@ async def websocket_handler(websocket, path):
198
  st.session_state.active_connections[room_id][client_id] = websocket
199
  username = st.session_state.username
200
 
201
- # Handle both Rocky Mountain Quest and Prairie Simulator players
202
  if "prairie" in path:
203
  st.session_state.prairie_players[client_id] = {
204
  "username": username,
205
- "animal": "prairie_dog", # Default
206
  "location": PRAIRIE_LOCATIONS["Deadwood, SD"],
207
  "color": CHARACTERS[username]["color"]
208
  }
@@ -250,14 +248,12 @@ async def websocket_handler(websocket, path):
250
  async def periodic_update():
251
  while True:
252
  if st.session_state.active_connections.get("quest"):
253
- # Rocky Mountain Quest update
254
  player_list = ", ".join([p["username"] for p in st.session_state.players.values()]) or "No adventurers yet!"
255
  message = f"πŸ“’ Quest Update: Active Adventurers - {player_list}"
256
  player_data = json.dumps(list(st.session_state.players.values()))
257
  await broadcast_message(f"System|{message}", "quest")
258
  await broadcast_message(f"MAP_UPDATE:{player_data}", "quest")
259
 
260
- # Prairie Simulator update
261
  prairie_list = ", ".join([f"{p['username']} ({p['animal']})" for p in st.session_state.prairie_players.values()]) or "No animals yet!"
262
  prairie_message = f"🌾 Prairie Update: {prairie_list}"
263
  prairie_data = json.dumps(list(st.session_state.prairie_players.values()))
@@ -398,8 +394,8 @@ rocky_map_html = f"""
398
  </html>
399
  """
400
 
401
- # Prairie Simulator HTML
402
- prairie_simulator_html = f"""
403
  <!DOCTYPE html>
404
  <html lang="en">
405
  <head>
@@ -407,12 +403,12 @@ prairie_simulator_html = f"""
407
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
408
  <title>Prairie Simulator</title>
409
  <style>
410
- body {{ margin: 0; font-family: Arial, sans-serif; background: #f0f0f0; }}
411
- #simContainer {{ width: 100%; height: 600px; position: relative; }}
412
- #map {{ width: 100%; height: 400px; }}
413
- #controls {{ padding: 10px; background: #fff; border-radius: 5px; }}
414
- #status {{ color: #333; padding: 5px; }}
415
- #chatBox {{ height: 100px; overflow-y: auto; background: #fff; border: 1px solid #ccc; padding: 5px; }}
416
  </style>
417
  </head>
418
  <body>
@@ -441,11 +437,11 @@ prairie_simulator_html = f"""
441
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
442
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
443
  <script>
444
- const playerName = "{st.session_state.username}";
445
  let ws = new WebSocket('ws://localhost:8765/prairie');
446
  const map = L.map('map').setView([44.0, -103.0], 7);
447
- L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {{
448
- attribution: '&copy; OpenStreetMap contributors'
449
  }}).addTo(map);
450
 
451
  const locations = {{
@@ -499,7 +495,7 @@ prairie_simulator_html = f"""
499
  </script>
500
  </body>
501
  </html>
502
- """
503
 
504
  # Main Game Loop
505
  def main():
@@ -524,13 +520,9 @@ def main():
524
 
525
  # Left Column: Rocky Mountain Quest
526
  with left_col:
527
- # Render Rocky Mountain Map
528
  components.html(rocky_map_html, width=800, height=600)
529
-
530
- # Chat Interface
531
  chat_content = asyncio.run(load_chat())
532
  st.text_area("πŸ“œ Quest Log", "\n".join(chat_content[-10:]), height=200, disabled=True)
533
-
534
  message = st.text_input(f"πŸ—¨οΈ {st.session_state.username} says:", placeholder="Speak or type to chat! 🌲")
535
  if st.button("🌟 Send & Chat 🎀"):
536
  if message:
@@ -539,8 +531,6 @@ def main():
539
  if audio_file:
540
  play_and_download_audio(audio_file)
541
  st.success(f"πŸŒ„ +10 points! New Score: {st.session_state.score}")
542
-
543
- # Voice Input Component
544
  mycomponent = components.declare_component("speech_component", path="./speech_component")
545
  val = mycomponent(my_input_value="", key=f"speech_{st.session_state.get('speech_processed', False)}")
546
  if val and val != st.session_state.last_transcript:
 
6
  import os
7
  import random
8
  import hashlib
 
9
  import base64
10
  import edge_tts
11
  import nest_asyncio
 
161
  'speech_processed': False, 'players': {}, 'last_update': time.time(),
162
  'update_interval': 20, 'x_pos': 0, 'z_pos': 0, 'move_left': False,
163
  'move_right': False, 'move_up': False, 'move_down': False,
164
+ 'prairie_players': {}
165
  }
166
  for k, v in defaults.items():
167
  if k not in st.session_state:
 
197
  st.session_state.active_connections[room_id][client_id] = websocket
198
  username = st.session_state.username
199
 
 
200
  if "prairie" in path:
201
  st.session_state.prairie_players[client_id] = {
202
  "username": username,
203
+ "animal": "prairie_dog",
204
  "location": PRAIRIE_LOCATIONS["Deadwood, SD"],
205
  "color": CHARACTERS[username]["color"]
206
  }
 
248
  async def periodic_update():
249
  while True:
250
  if st.session_state.active_connections.get("quest"):
 
251
  player_list = ", ".join([p["username"] for p in st.session_state.players.values()]) or "No adventurers yet!"
252
  message = f"πŸ“’ Quest Update: Active Adventurers - {player_list}"
253
  player_data = json.dumps(list(st.session_state.players.values()))
254
  await broadcast_message(f"System|{message}", "quest")
255
  await broadcast_message(f"MAP_UPDATE:{player_data}", "quest")
256
 
 
257
  prairie_list = ", ".join([f"{p['username']} ({p['animal']})" for p in st.session_state.prairie_players.values()]) or "No animals yet!"
258
  prairie_message = f"🌾 Prairie Update: {prairie_list}"
259
  prairie_data = json.dumps(list(st.session_state.prairie_players.values()))
 
394
  </html>
395
  """
396
 
397
+ # Prairie Simulator HTML (Corrected)
398
+ prairie_simulator_html = """
399
  <!DOCTYPE html>
400
  <html lang="en">
401
  <head>
 
403
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
404
  <title>Prairie Simulator</title>
405
  <style>
406
+ body { margin: 0; font-family: Arial, sans-serif; background: #f0f0f0; }
407
+ #simContainer { width: 100%; height: 600px; position: relative; }
408
+ #map { width: 100%; height: 400px; }
409
+ #controls { padding: 10px; background: #fff; border-radius: 5px; }
410
+ #status { color: #333; padding: 5px; }
411
+ #chatBox { height: 100px; overflow-y: auto; background: #fff; border: 1px solid #ccc; padding: 5px; }
412
  </style>
413
  </head>
414
  <body>
 
437
  <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
438
  <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
439
  <script>
440
+ const playerName = "{username}";
441
  let ws = new WebSocket('ws://localhost:8765/prairie');
442
  const map = L.map('map').setView([44.0, -103.0], 7);
443
+ L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png', {{
444
+ attribution: 'Β© OpenStreetMap contributors'
445
  }}).addTo(map);
446
 
447
  const locations = {{
 
495
  </script>
496
  </body>
497
  </html>
498
+ """.format(username=st.session_state.username)
499
 
500
  # Main Game Loop
501
  def main():
 
520
 
521
  # Left Column: Rocky Mountain Quest
522
  with left_col:
 
523
  components.html(rocky_map_html, width=800, height=600)
 
 
524
  chat_content = asyncio.run(load_chat())
525
  st.text_area("πŸ“œ Quest Log", "\n".join(chat_content[-10:]), height=200, disabled=True)
 
526
  message = st.text_input(f"πŸ—¨οΈ {st.session_state.username} says:", placeholder="Speak or type to chat! 🌲")
527
  if st.button("🌟 Send & Chat 🎀"):
528
  if message:
 
531
  if audio_file:
532
  play_and_download_audio(audio_file)
533
  st.success(f"πŸŒ„ +10 points! New Score: {st.session_state.score}")
 
 
534
  mycomponent = components.declare_component("speech_component", path="./speech_component")
535
  val = mycomponent(my_input_value="", key=f"speech_{st.session_state.get('speech_processed', False)}")
536
  if val and val != st.session_state.last_transcript: