AIencoder commited on
Commit
3d29f72
·
verified ·
1 Parent(s): 80c0889

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -23
app.py CHANGED
@@ -10,41 +10,64 @@ except Exception as e:
10
 
11
  def chat_logic(message, image_file, history, mode):
12
  # Ensure history is a list
13
- if history is None: history = []
 
14
 
15
  # 1. Handle Empty Input
16
  if not message and not image_file:
17
  return history, "", None
18
-
19
  if not chimera:
20
- history.append([message, "❌ Error: API Keys missing."])
 
 
21
  return history, "", None
22
-
23
- # 2. Process Request
 
 
 
 
 
 
 
 
 
24
  try:
25
- response_text, active_module = chimera.process_request(message, history, mode, image_file)
 
 
 
 
 
26
  except Exception as e:
27
  response_text = f"Processing Error: {str(e)}"
28
  active_module = "ERR"
29
 
30
- # 3. Format Output
31
  final_response = f"**[{active_module} Active]**\n\n{response_text}"
32
 
33
- # 4. Append to History (Universal List Format)
34
- # This works on ALL Gradio versions and avoids format crashes.
35
  if image_file:
36
- user_msg = f"[Uploaded Image] {message}"
37
  else:
38
  user_msg = message
39
-
40
- history.append([user_msg, final_response])
 
 
41
 
42
  return history, "", None
43
 
44
  # --- UI Layout ---
45
  custom_css = """
46
- body {background-color: #0b0f19; color: #c9d1d9;}
47
- .gradio-container {font-family: 'IBM Plex Mono', monospace;}
 
 
 
 
 
48
  """
49
 
50
  with gr.Blocks(title="Axon God Mode", css=custom_css) as demo:
@@ -52,8 +75,7 @@ with gr.Blocks(title="Axon God Mode", css=custom_css) as demo:
52
  gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
53
 
54
  with gr.Row():
55
- # No type="..." needed. Defaults to Lists.
56
- chatbot = gr.Chatbot(height=500, elem_id="chatbot")
57
 
58
  with gr.Row():
59
  with gr.Column(scale=4):
@@ -63,22 +85,22 @@ with gr.Blocks(title="Axon God Mode", css=custom_css) as demo:
63
  with gr.Column(scale=1):
64
  mode = gr.Dropdown(
65
  choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"],
66
- value="Auto", show_label=False
 
67
  )
68
  submit = gr.Button("🚀 EXECUTE", variant="primary")
69
-
70
  # Event Handlers
71
  submit.click(
72
- chat_logic,
73
- inputs=[msg, btn_upload, chatbot, mode],
74
  outputs=[chatbot, msg, btn_upload]
75
  )
76
  msg.submit(
77
- chat_logic,
78
- inputs=[msg, btn_upload, chatbot, mode],
79
  outputs=[chatbot, msg, btn_upload]
80
  )
81
 
82
  if __name__ == "__main__":
83
- # CRITICAL: ssr_mode=False is still needed for Python 3.13 stability
84
  demo.launch(ssr_mode=False)
 
10
 
11
  def chat_logic(message, image_file, history, mode):
12
  # Ensure history is a list
13
+ if history is None:
14
+ history = []
15
 
16
  # 1. Handle Empty Input
17
  if not message and not image_file:
18
  return history, "", None
19
+
20
  if not chimera:
21
+ user_msg = message or "[Image uploaded]"
22
+ history.append({"role": "user", "content": user_msg})
23
+ history.append({"role": "assistant", "content": "❌ Error: API Keys missing."})
24
  return history, "", None
25
+
26
+ # 2. Convert history to simple format for chimera (it doesn't use the full history currently)
27
+ # But we'll keep it available for future use
28
+ simple_history = []
29
+ for msg in history:
30
+ if isinstance(msg, dict):
31
+ simple_history.append([msg.get("content", "")])
32
+ else:
33
+ simple_history.append(msg)
34
+
35
+ # 3. Process Request
36
  try:
37
+ response_text, active_module = chimera.process_request(
38
+ message or "",
39
+ simple_history,
40
+ mode,
41
+ image_file
42
+ )
43
  except Exception as e:
44
  response_text = f"Processing Error: {str(e)}"
45
  active_module = "ERR"
46
 
47
+ # 4. Format Output
48
  final_response = f"**[{active_module} Active]**\n\n{response_text}"
49
 
50
+ # 5. Create user message
 
51
  if image_file:
52
+ user_msg = f"[Uploaded Image] {message or 'Analyze this image'}"
53
  else:
54
  user_msg = message
55
+
56
+ # 6. Append to History (Dictionary Format for modern Gradio)
57
+ history.append({"role": "user", "content": user_msg})
58
+ history.append({"role": "assistant", "content": final_response})
59
 
60
  return history, "", None
61
 
62
  # --- UI Layout ---
63
  custom_css = """
64
+ body {
65
+ background-color: #0b0f19;
66
+ color: #c9d1d9;
67
+ }
68
+ .gradio-container {
69
+ font-family: 'IBM Plex Mono', monospace;
70
+ }
71
  """
72
 
73
  with gr.Blocks(title="Axon God Mode", css=custom_css) as demo:
 
75
  gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
76
 
77
  with gr.Row():
78
+ chatbot = gr.Chatbot(height=500, elem_id="chatbot", type="messages")
 
79
 
80
  with gr.Row():
81
  with gr.Column(scale=4):
 
85
  with gr.Column(scale=1):
86
  mode = gr.Dropdown(
87
  choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"],
88
+ value="Auto",
89
+ show_label=False
90
  )
91
  submit = gr.Button("🚀 EXECUTE", variant="primary")
92
+
93
  # Event Handlers
94
  submit.click(
95
+ chat_logic,
96
+ inputs=[msg, btn_upload, chatbot, mode],
97
  outputs=[chatbot, msg, btn_upload]
98
  )
99
  msg.submit(
100
+ chat_logic,
101
+ inputs=[msg, btn_upload, chatbot, mode],
102
  outputs=[chatbot, msg, btn_upload]
103
  )
104
 
105
  if __name__ == "__main__":
 
106
  demo.launch(ssr_mode=False)