AIencoder commited on
Commit
d4b3a04
Β·
verified Β·
1 Parent(s): b5dae1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -37
app.py CHANGED
@@ -8,54 +8,69 @@ except Exception as e:
8
  chimera = None
9
  print(f"Startup Error: {e}")
10
 
11
- def generate_response(message, history, mode_selection):
12
- """
13
- Standard ChatInterface logic.
14
- Accepts: message (str), history (list of lists), mode_selection (str)
15
- Returns: response (str)
16
- """
17
- if not chimera:
18
- return "❌ Error: API Keys missing. Check Settings -> Secrets."
19
 
20
- # Map friendly names
21
- role_map = {
22
- "Auto (Router)": "Auto",
23
- "⚑ ASM (Qwen + Llama)": "ASM",
24
- "πŸ”¬ SFE (Data/Science)": "SFE",
25
- "🎨 CSM (Story/Creative)": "CSM"
26
- }
27
- # Handle case where mode is None
28
- selected_role = role_map.get(mode_selection, "Auto")
29
 
30
- # Get response from Chimera Brain
31
- response_text, active_module = chimera.process_request(message, history, selected_role)
 
 
 
 
 
 
 
 
 
 
32
 
33
- # Return formatted string
34
- return f"**[{active_module} Active]**\n\n{response_text}"
35
 
36
- # --- Sci-Fi Theme CSS ---
37
  custom_css = """
38
  body {background-color: #0b0f19; color: #c9d1d9;}
39
  .gradio-container {font-family: 'IBM Plex Mono', monospace;}
40
  """
41
 
42
- # 1. Removed 'css' from Blocks to fix the Warning
43
- with gr.Blocks(title="Axon Trinity") as demo:
44
- gr.Markdown("# βš”οΈ AXON: QWEN TRINITY")
45
 
46
- mode_picker = gr.Dropdown(
47
- choices=["Auto (Router)", "⚑ ASM (Qwen + Llama)", "πŸ”¬ SFE (Data/Science)", "🎨 CSM (Story/Creative)"],
48
- value="Auto (Router)",
49
- label="Persona Mode"
50
- )
 
 
 
 
 
 
 
 
 
 
51
 
52
- # 2. REMOVED 'type="messages"' completely.
53
- # This forces it to use the default 'List of Lists' format which never crashes.
54
- chat = gr.ChatInterface(
55
- fn=generate_response,
56
- additional_inputs=[mode_picker]
 
 
 
 
 
57
  )
58
 
59
  if __name__ == "__main__":
60
- # 3. Moved CSS here and disabled SSR for safety
61
- demo.launch(ssr_mode=False, css=custom_css)
 
8
  chimera = None
9
  print(f"Startup Error: {e}")
10
 
11
+ def chat_logic(message, image_file, history, mode):
12
+ if history is None: history = []
 
 
 
 
 
 
13
 
14
+ # 1. Handle Empty Input
15
+ if not message and not image_file:
16
+ return history, "", None
17
+
18
+ if not chimera:
19
+ history.append([message, "❌ Error: API Keys missing."])
20
+ return history, "", None
 
 
21
 
22
+ # 2. Process
23
+ response_text, active_module = chimera.process_request(message, history, mode, image_file)
24
+
25
+ # 3. Format Output
26
+ final_response = f"**[{active_module} Active]**\n\n{response_text}"
27
+
28
+ # 4. Append to History (Universal List Format)
29
+ if image_file:
30
+ # If user uploaded an image, show a placeholder text for their side
31
+ history.append([f"[Uploaded Image] {message}", final_response])
32
+ else:
33
+ history.append([message, final_response])
34
 
35
+ return history, "", None
 
36
 
37
+ # --- UI Layout ---
38
  custom_css = """
39
  body {background-color: #0b0f19; color: #c9d1d9;}
40
  .gradio-container {font-family: 'IBM Plex Mono', monospace;}
41
  """
42
 
43
+ with gr.Blocks(title="Axon God Mode", css=custom_css) as demo:
44
+ gr.Markdown("# ⚑ AXON: GOD MODE")
45
+ gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
46
 
47
+ with gr.Row():
48
+ chatbot = gr.Chatbot(height=500, elem_id="chatbot")
49
+
50
+ with gr.Row():
51
+ with gr.Column(scale=4):
52
+ msg = gr.Textbox(placeholder="Ask anything, or upload an image...", show_label=False)
53
+ # The Magic Upload Button
54
+ btn_upload = gr.Image(type="filepath", label="Upload for Vision (VIM)", height=70)
55
+
56
+ with gr.Column(scale=1):
57
+ mode = gr.Dropdown(
58
+ choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"],
59
+ value="Auto", show_label=False
60
+ )
61
+ submit = gr.Button("πŸš€ EXECUTE", variant="primary")
62
 
63
+ # Event Handlers
64
+ submit.click(
65
+ chat_logic,
66
+ inputs=[msg, btn_upload, chatbot, mode],
67
+ outputs=[chatbot, msg, btn_upload]
68
+ )
69
+ msg.submit(
70
+ chat_logic,
71
+ inputs=[msg, btn_upload, chatbot, mode],
72
+ outputs=[chatbot, msg, btn_upload]
73
  )
74
 
75
  if __name__ == "__main__":
76
+ demo.launch(ssr_mode=False)