awacke1 commited on
Commit
7c3f5bc
Β·
verified Β·
1 Parent(s): ac4cd0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -35
app.py CHANGED
@@ -33,28 +33,28 @@ st.set_page_config(
33
  initial_sidebar_state="auto"
34
  )
35
 
36
- # Funky usernames - who’s who in the zoo! 🎭🐾
37
  FUN_USERNAMES = {
38
- "CosmicJester 🌌": "en-US-AriaNeural",
39
- "PixelPanda 🐼": "en-US-JennyNeural",
40
- "QuantumQuack πŸ¦†": "en-GB-SoniaNeural",
41
- "StellarSquirrel 🐿️": "en-AU-NatashaNeural",
42
- "GizmoGuru βš™οΈ": "en-CA-ClaraNeural",
43
- "NebulaNinja 🌠": "en-US-GuyNeural",
44
- "ByteBuster πŸ’Ύ": "en-GB-RyanNeural",
45
- "GalacticGopher 🌍": "en-AU-WilliamNeural",
46
- "RocketRaccoon πŸš€": "en-CA-LiamNeural",
47
- "EchoElf 🧝": "en-US-AriaNeural",
48
- "PhantomFox 🦊": "en-US-JennyNeural",
49
- "WittyWizard πŸ§™": "en-GB-SoniaNeural",
50
- "LunarLlama πŸŒ™": "en-AU-NatashaNeural",
51
- "SolarSloth β˜€οΈ": "en-CA-ClaraNeural",
52
- "AstroAlpaca πŸ¦™": "en-US-GuyNeural",
53
- "CyberCoyote 🐺": "en-GB-RyanNeural",
54
- "MysticMoose 🦌": "en-AU-WilliamNeural",
55
- "GlitchGnome 🧚": "en-CA-LiamNeural",
56
- "VortexViper 🐍": "en-US-AriaNeural",
57
- "ChronoChimp πŸ’": "en-US-JennyNeural"
58
  }
59
 
60
  # Folders galore - organizing chaos! πŸ“‚πŸŒ€
@@ -140,7 +140,7 @@ async def save_chat_entry(username, message):
140
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
141
  entry = f"[{timestamp}] {username}: {message}"
142
  await asyncio.to_thread(lambda: open(CHAT_FILE, 'a').write(f"{entry}\n"))
143
- voice = FUN_USERNAMES.get(username, "en-US-AriaNeural")
144
  audio_file = await async_edge_tts_generate(message, voice)
145
  if audio_file:
146
  with open(HISTORY_FILE, 'a') as f:
@@ -201,7 +201,7 @@ async def load_votes(file):
201
  await asyncio.to_thread(lambda: open(file, 'w').write("# Vote Tally\n\nNo votes yet - get clicking! πŸ–±οΈ\n"))
202
  with open(file, 'r') as f:
203
  content = await asyncio.to_thread(f.read)
204
- lines = content.strip().split('\n')[2:] # Process content after reading
205
  votes = {}
206
  user_votes = set()
207
  for line in lines:
@@ -326,7 +326,6 @@ async def process_voice_input(audio_bytes):
326
 
327
  # Interface builder - UI takes shape! πŸŽ¨πŸ–ŒοΈ
328
  def create_streamlit_interface():
329
- # Run async tasks within an event loop
330
  loop = asyncio.new_event_loop()
331
  asyncio.set_event_loop(loop)
332
 
@@ -363,17 +362,14 @@ def create_streamlit_interface():
363
  st.title(f"πŸ€–πŸ§ MMO {st.session_state.username}πŸ“πŸ”¬")
364
  st.markdown(f"Welcome to {START_ROOM} - chat, vote, upload, paste images, and enjoy quoting! πŸŽ‰")
365
 
366
- # Start websocket server if not running
367
  if not st.session_state.server_task:
368
  st.session_state.server_task = loop.create_task(run_websocket_server())
369
 
370
- # Voice Input
371
  audio_bytes = audio_recorder()
372
  if audio_bytes:
373
  await process_voice_input(audio_bytes)
374
  st.rerun()
375
 
376
- # Chat Section
377
  st.subheader(f"{START_ROOM} Chat πŸ’¬")
378
  chat_content = await load_chat()
379
  chat_lines = chat_content.split('\n')
@@ -410,7 +406,6 @@ def create_streamlit_interface():
410
  st.session_state.quote_line = line
411
  st.rerun()
412
 
413
- # Quoting Section
414
  if 'quote_line' in st.session_state:
415
  st.markdown(f"### Quoting: {st.session_state.quote_line}")
416
  quote_response = st.text_area("Add your response", key="quote_response")
@@ -429,14 +424,12 @@ def create_streamlit_interface():
429
  st.session_state.message_text = ''
430
  st.rerun()
431
 
432
- # Username changer
433
  new_username = st.selectbox("Change Name", [""] + list(FUN_USERNAMES.keys()), index=0)
434
  if new_username and new_username != st.session_state.username:
435
  loop.run_until_complete(save_chat_entry("System 🌟", f"{st.session_state.username} changed name to {new_username}"))
436
  st.session_state.username = new_username
437
  st.rerun()
438
 
439
- # Message Input
440
  message = st.text_input(f"Message as {st.session_state.username}", key="message_input", value=st.session_state.message_text, on_change=lambda: st.session_state.update(message_text=st.session_state.message_input))
441
  if st.button("Send πŸš€", key="send_button") and message.strip():
442
  loop.run_until_complete(save_chat_entry(st.session_state.username, message))
@@ -448,7 +441,6 @@ def create_streamlit_interface():
448
  st.session_state.message_text = ''
449
  st.rerun()
450
 
451
- # Paste Target
452
  components.html(
453
  """
454
  <div id="paste-target">Paste an image here (Ctrl+V)</div>
@@ -477,7 +469,6 @@ def create_streamlit_interface():
477
  height=100
478
  )
479
 
480
- # Media Section
481
  st.subheader("Media Gallery 🎨🎢πŸŽ₯")
482
  uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp3', 'mp4'])
483
  if uploaded_file:
@@ -516,7 +507,6 @@ def create_streamlit_interface():
516
  await asyncio.to_thread(os.remove, media_file)
517
  st.rerun()
518
 
519
- # Refresh Timer
520
  st.subheader("Refresh ⏳")
521
  refresh_rate = st.slider("Refresh Rate", 1, 300, st.session_state.refresh_rate)
522
  st.session_state.refresh_rate = refresh_rate
@@ -528,13 +518,11 @@ def create_streamlit_interface():
528
  loop.run_until_complete(asyncio.sleep(1))
529
  st.rerun()
530
 
531
- # Sidebar History
532
  st.sidebar.subheader("Chat History πŸ“œ")
533
  with open(HISTORY_FILE, 'r') as f:
534
  history_content = f.read()
535
  st.sidebar.markdown(history_content)
536
 
537
- # Run the async interface
538
  loop.run_until_complete(async_interface())
539
 
540
  # Main execution - let’s roll! πŸŽ²πŸš€
 
33
  initial_sidebar_state="auto"
34
  )
35
 
36
+ # Funky usernames - who’s who in the zoo with unique voices! πŸŽ­πŸΎπŸŽ™οΈ
37
  FUN_USERNAMES = {
38
+ "CosmicJester 🌌": "en-US-AriaNeural", # US Female, bright & clear
39
+ "PixelPanda 🐼": "en-US-JennyNeural", # US Female, warm & friendly
40
+ "QuantumQuack πŸ¦†": "en-GB-SoniaNeural", # UK Female, posh & crisp
41
+ "StellarSquirrel 🐿️": "en-AU-NatashaNeural", # AU Female, lively & upbeat
42
+ "GizmoGuru βš™οΈ": "en-CA-ClaraNeural", # CA Female, calm & soothing
43
+ "NebulaNinja 🌠": "en-US-GuyNeural", # US Male, deep & cool
44
+ "ByteBuster πŸ’Ύ": "en-GB-RyanNeural", # UK Male, smooth & refined
45
+ "GalacticGopher 🌍": "en-AU-WilliamNeural", # AU Male, bold & rugged
46
+ "RocketRaccoon πŸš€": "en-CA-LiamNeural", # CA Male, steady & warm
47
+ "EchoElf 🧝": "en-US-AnaNeural", # US Female, soft & gentle (child-like)
48
+ "PhantomFox 🦊": "en-US-BrandonNeural", # US Male, confident & rich
49
+ "WittyWizard πŸ§™": "en-GB-ThomasNeural", # UK Male, authoritative & clear
50
+ "LunarLlama πŸŒ™": "en-AU-FreyaNeural", # AU Female, sweet & melodic
51
+ "SolarSloth β˜€οΈ": "en-CA-LindaNeural", # CA Female, neutral & pleasant
52
+ "AstroAlpaca πŸ¦™": "en-US-ChristopherNeural",# US Male, strong & resonant
53
+ "CyberCoyote 🐺": "en-GB-ElliotNeural", # UK Male, youthful & energetic
54
+ "MysticMoose 🦌": "en-AU-JamesNeural", # AU Male, deep & grounded
55
+ "GlitchGnome 🧚": "en-CA-EthanNeural", # CA Male, bright & lively
56
+ "VortexViper 🐍": "en-US-AmberNeural", # US Female, expressive & vibrant
57
+ "ChronoChimp πŸ’": "en-GB-LibbyNeural" # UK Female, cheerful & distinct
58
  }
59
 
60
  # Folders galore - organizing chaos! πŸ“‚πŸŒ€
 
140
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
141
  entry = f"[{timestamp}] {username}: {message}"
142
  await asyncio.to_thread(lambda: open(CHAT_FILE, 'a').write(f"{entry}\n"))
143
+ voice = FUN_USERNAMES.get(username, "en-US-AriaNeural") # Use mapped voice or default
144
  audio_file = await async_edge_tts_generate(message, voice)
145
  if audio_file:
146
  with open(HISTORY_FILE, 'a') as f:
 
201
  await asyncio.to_thread(lambda: open(file, 'w').write("# Vote Tally\n\nNo votes yet - get clicking! πŸ–±οΈ\n"))
202
  with open(file, 'r') as f:
203
  content = await asyncio.to_thread(f.read)
204
+ lines = content.strip().split('\n')[2:]
205
  votes = {}
206
  user_votes = set()
207
  for line in lines:
 
326
 
327
  # Interface builder - UI takes shape! πŸŽ¨πŸ–ŒοΈ
328
  def create_streamlit_interface():
 
329
  loop = asyncio.new_event_loop()
330
  asyncio.set_event_loop(loop)
331
 
 
362
  st.title(f"πŸ€–πŸ§ MMO {st.session_state.username}πŸ“πŸ”¬")
363
  st.markdown(f"Welcome to {START_ROOM} - chat, vote, upload, paste images, and enjoy quoting! πŸŽ‰")
364
 
 
365
  if not st.session_state.server_task:
366
  st.session_state.server_task = loop.create_task(run_websocket_server())
367
 
 
368
  audio_bytes = audio_recorder()
369
  if audio_bytes:
370
  await process_voice_input(audio_bytes)
371
  st.rerun()
372
 
 
373
  st.subheader(f"{START_ROOM} Chat πŸ’¬")
374
  chat_content = await load_chat()
375
  chat_lines = chat_content.split('\n')
 
406
  st.session_state.quote_line = line
407
  st.rerun()
408
 
 
409
  if 'quote_line' in st.session_state:
410
  st.markdown(f"### Quoting: {st.session_state.quote_line}")
411
  quote_response = st.text_area("Add your response", key="quote_response")
 
424
  st.session_state.message_text = ''
425
  st.rerun()
426
 
 
427
  new_username = st.selectbox("Change Name", [""] + list(FUN_USERNAMES.keys()), index=0)
428
  if new_username and new_username != st.session_state.username:
429
  loop.run_until_complete(save_chat_entry("System 🌟", f"{st.session_state.username} changed name to {new_username}"))
430
  st.session_state.username = new_username
431
  st.rerun()
432
 
 
433
  message = st.text_input(f"Message as {st.session_state.username}", key="message_input", value=st.session_state.message_text, on_change=lambda: st.session_state.update(message_text=st.session_state.message_input))
434
  if st.button("Send πŸš€", key="send_button") and message.strip():
435
  loop.run_until_complete(save_chat_entry(st.session_state.username, message))
 
441
  st.session_state.message_text = ''
442
  st.rerun()
443
 
 
444
  components.html(
445
  """
446
  <div id="paste-target">Paste an image here (Ctrl+V)</div>
 
469
  height=100
470
  )
471
 
 
472
  st.subheader("Media Gallery 🎨🎢πŸŽ₯")
473
  uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp3', 'mp4'])
474
  if uploaded_file:
 
507
  await asyncio.to_thread(os.remove, media_file)
508
  st.rerun()
509
 
 
510
  st.subheader("Refresh ⏳")
511
  refresh_rate = st.slider("Refresh Rate", 1, 300, st.session_state.refresh_rate)
512
  st.session_state.refresh_rate = refresh_rate
 
518
  loop.run_until_complete(asyncio.sleep(1))
519
  st.rerun()
520
 
 
521
  st.sidebar.subheader("Chat History πŸ“œ")
522
  with open(HISTORY_FILE, 'r') as f:
523
  history_content = f.read()
524
  st.sidebar.markdown(history_content)
525
 
 
526
  loop.run_until_complete(async_interface())
527
 
528
  # Main execution - let’s roll! πŸŽ²πŸš€