Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,54 +8,69 @@ except Exception as e:
|
|
| 8 |
chimera = None
|
| 9 |
print(f"Startup Error: {e}")
|
| 10 |
|
| 11 |
-
def
|
| 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 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
"
|
| 26 |
-
|
| 27 |
-
# Handle case where mode is None
|
| 28 |
-
selected_role = role_map.get(mode_selection, "Auto")
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
response_text, active_module = chimera.process_request(message, history,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
return f"**[{active_module} Active]**\n\n{response_text}"
|
| 35 |
|
| 36 |
-
# ---
|
| 37 |
custom_css = """
|
| 38 |
body {background-color: #0b0f19; color: #c9d1d9;}
|
| 39 |
.gradio-container {font-family: 'IBM Plex Mono', monospace;}
|
| 40 |
"""
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
gr.Markdown("
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
-
|
| 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)
|
|
|