Onyxl commited on
Commit
bfccda2
·
verified ·
1 Parent(s): f2332f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -63
app.py CHANGED
@@ -1,75 +1,87 @@
1
  import gradio as gr
 
2
 
3
- # --- THE LOGIC ---
4
- def chat_fn(message, history):
5
- # Standard Chat History update for Gradio 6
6
- return history + [[message, "📡 TeraBites™ Core: Received."]]
7
 
8
- def gemma_service(query):
9
- return "🎧 Gemma 3: Protocol verified. How can I assist the Empire?"
 
 
 
10
 
11
- # --- THE UI ARCHITECTURE ---
12
- with gr.Blocks() as demo:
13
- # TOP HEADER: CUSTOMER SERVICE (GEMMA 3)
14
- with gr.Row():
15
- with gr.Column(scale=3):
16
- gr.Markdown("# 🪐 TERABITES™ CORE")
17
- with gr.Column(scale=1, variant="panel"):
18
- gr.Markdown("🎧 **GEMMA 3 SERVICE**")
19
- support_out = gr.Markdown("*Sentinel Active*")
20
- support_in = gr.Textbox(placeholder="Ask Support...", show_label=False, container=False)
 
 
 
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  with gr.Row():
23
- # LEFT SIDEBAR (The Navigation from your PDF)
24
- with gr.Column(scale=1, variant="panel"):
25
- gr.Markdown("### 🔐 ACCESS")
26
- gr.LoginButton()
27
-
28
- with gr.Group():
29
- gr.Markdown("### 👤 PROFILE")
30
- gr.Markdown("## Hi Bro!")
31
- profile_name = gr.Textbox(value="Authenticating...", interactive=False, show_label=False)
32
-
33
- # RAW HTML DIVIDER (Indestructible)
34
- gr.HTML("<hr style='border-top: 1px solid #333; margin: 10px 0;'>")
35
-
36
- gr.Markdown("### 📡 FREQUENCIES")
37
- group_nav = gr.Radio(["🌐 main", "📢 news"], value="🌐 main", label=None)
38
-
39
- with gr.Accordion("👥 OTHER GROUPS", open=False):
40
- gr.Radio(["🛠️ build-squad"], label=None)
41
 
42
- # CENTER GAP (THE CHAT)
43
- with gr.Column(scale=4):
44
- # FIXED: Removed 'bubble_full_width' for Gradio 6 compatibility
45
- chatbot = gr.Chatbot(height=550, show_label=False)
 
 
 
 
 
46
 
47
- # THE PROMPT TYPING (Per PDF: Center Bottom)
48
  with gr.Row():
49
- msg_input = gr.Textbox(
50
- placeholder="here is the prompt typing...",
51
- scale=9,
52
- show_label=False,
53
- container=False
54
  )
55
- send_btn = gr.Button("SUI", scale=1, variant="primary")
56
-
57
- # --- ACTION BINDING ---
58
- def sync(profile: gr.OAuthProfile | None):
59
- if profile: return profile.name
60
- return "Guest Warrior"
61
 
62
- demo.load(sync, None, profile_name)
63
- support_in.submit(gemma_service, [support_in], [support_out])
64
- send_btn.click(chat_fn, [msg_input, chatbot], [chatbot])
65
- msg_input.submit(chat_fn, [msg_input, chatbot], [chatbot])
 
 
66
 
67
- # --- LAUNCH WITH THEME AND CSS ---
68
- demo.launch(
69
- theme=gr.themes.Monochrome(),
70
- css="""
71
- .gradio-container { background-color: #050505 !important; }
72
- footer { display: none !important; }
73
- .message-row { justify-content: flex-start !important; }
74
- """
75
- )
 
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({
34
+ "role": "user",
35
+ "content": m["text"],
36
+ "metadata": {"title": f" {m['user']}"}
37
+ })
38
+ return formatted
39
+
40
+ # --- UI ARCHITECTURE (Onyx Color Rules) ---
41
+ css = """
42
+ .gradio-container { background-color: #050505 !important; color: #00FF00 !important; }
43
+ .message-user { border-left: 3px solid #FFD700 !important; background: #0a0a0a !important; }
44
+ #status-panel { border: 1px solid #333; padding: 15px; border-radius: 8px; }
45
+ footer { visibility: hidden; }
46
+ """
47
+
48
+ 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")
56
+ gr.Label(value="VM: ACTIVE", color="green")
57
+ gr.Label(value="RAM: 7GB STABLE", color="green")
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
 
86
+ if __name__ == "__main__":
87
+ demo.launch()