Onyxl commited on
Commit
b4bd700
·
verified ·
1 Parent(s): b3070a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -27
app.py CHANGED
@@ -1,33 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import time
3
 
4
  # GLOBAL STORAGE: Managed within the 7GB RAM Fortress
5
- # Stores messages as: {"user": str, "avatar": str, "text": str}
6
  team_messages = []
7
 
8
  def get_user_data(request: gr.Request):
9
- """Retrieves OAuth data from Hugging Face."""
10
  if request and request.user_info:
11
  return request.user_info.preferred_username, request.user_info.picture
12
  return None, None
13
 
14
  def send_to_fleet(message, request: gr.Request):
15
- """Processes message and adds to the global stream."""
16
- if not message:
17
- return ""
18
-
19
  username, avatar = get_user_data(request)
20
- if not username:
21
- return "⚠️ ACCESS DENIED: Please Login with HF first."
22
-
23
- # Prevent Bot Overload: Keep last 50 messages in RAM
24
  team_messages.append({"user": username, "avatar": avatar, "text": message})
25
- if len(team_messages) > 50:
26
- team_messages.pop(0)
27
  return ""
28
 
29
  def sync_labyrinth():
30
- """Updates the UI with the global message stream."""
31
  formatted = []
32
  for m in team_messages:
33
  formatted.append({
@@ -49,7 +55,6 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
49
  gr.HTML("<h1 style='color: #00FF00; text-align: center;'>🟢 TERABITES AI TEAM</h1>")
50
 
51
  with gr.Row():
52
- # SECURITY PANEL
53
  with gr.Column(scale=1, elem_id="status-panel"):
54
  gr.Markdown("### 🛡️ SYSTEM STATUS")
55
  gr.LoginButton(size="lg")
@@ -58,28 +63,17 @@ with gr.Blocks(theme=gr.themes.Monochrome(), css=css) as demo:
58
  gr.Markdown("---")
59
  gr.Markdown("Welcome, Team. Use the **Gold-Bordered** stream for secure comms.")
60
 
61
- # CHAT INTERFACE
62
  with gr.Column(scale=3):
63
- # type="messages" is required for Gradio 5.x
64
  chat_stream = gr.Chatbot(
65
  label="TeraBites Global Feed",
66
  height=550,
67
- type="messages",
68
- avatar_images=(None, "https://huggingface.co/front/assets/huggingface_logo.svg")
69
  )
70
-
71
  with gr.Row():
72
- txt_input = gr.Textbox(
73
- placeholder="Input command to the fleet...",
74
- show_label=False,
75
- scale=4
76
- )
77
  submit_btn = gr.Button("🚀 SEND", variant="primary", scale=1)
78
 
79
- # REFRESH LOGIC: Syncs every 2 seconds
80
  demo.load(sync_labyrinth, None, chat_stream, every=2)
81
-
82
- # INTERACTION LOGIC
83
  txt_input.submit(send_to_fleet, [txt_input], [txt_input]).then(sync_labyrinth, None, chat_stream)
84
  submit_btn.click(send_to_fleet, [txt_input], [txt_input]).then(sync_labyrinth, None, chat_stream)
85
 
 
1
+ import sys
2
+
3
+ # --- ONYX PRE-FLIGHT: FIX FOR PYTHON 3.13 ---
4
+ try:
5
+ import audioop
6
+ except ImportError:
7
+ try:
8
+ from audioop_lts import audioop
9
+ sys.modules["audioop"] = audioop
10
+ except ImportError:
11
+ # If the library is missing, we create a 'Ghost' module to stop the crash
12
+ from types import ModuleType
13
+ sys.modules["audioop"] = ModuleType("audioop")
14
+ # --------------------------------------------
15
+
16
  import gradio as gr
17
  import time
18
 
19
  # GLOBAL STORAGE: Managed within the 7GB RAM Fortress
 
20
  team_messages = []
21
 
22
  def get_user_data(request: gr.Request):
 
23
  if request and request.user_info:
24
  return request.user_info.preferred_username, request.user_info.picture
25
  return None, None
26
 
27
  def send_to_fleet(message, request: gr.Request):
28
+ if not message: return ""
 
 
 
29
  username, avatar = get_user_data(request)
30
+ if not username: return "⚠️ ACCESS DENIED: Please Login with HF first."
31
+
 
 
32
  team_messages.append({"user": username, "avatar": avatar, "text": message})
33
+ if len(team_messages) > 50: team_messages.pop(0)
 
34
  return ""
35
 
36
  def sync_labyrinth():
 
37
  formatted = []
38
  for m in team_messages:
39
  formatted.append({
 
55
  gr.HTML("<h1 style='color: #00FF00; text-align: center;'>🟢 TERABITES AI TEAM</h1>")
56
 
57
  with gr.Row():
 
58
  with gr.Column(scale=1, elem_id="status-panel"):
59
  gr.Markdown("### 🛡️ SYSTEM STATUS")
60
  gr.LoginButton(size="lg")
 
63
  gr.Markdown("---")
64
  gr.Markdown("Welcome, Team. Use the **Gold-Bordered** stream for secure comms.")
65
 
 
66
  with gr.Column(scale=3):
 
67
  chat_stream = gr.Chatbot(
68
  label="TeraBites Global Feed",
69
  height=550,
70
+ type="messages"
 
71
  )
 
72
  with gr.Row():
73
+ txt_input = gr.Textbox(placeholder="Input command to the fleet...", show_label=False, scale=4)
 
 
 
 
74
  submit_btn = gr.Button("🚀 SEND", variant="primary", scale=1)
75
 
 
76
  demo.load(sync_labyrinth, None, chat_stream, every=2)
 
 
77
  txt_input.submit(send_to_fleet, [txt_input], [txt_input]).then(sync_labyrinth, None, chat_stream)
78
  submit_btn.click(send_to_fleet, [txt_input], [txt_input]).then(sync_labyrinth, None, chat_stream)
79