Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ except Exception as e:
|
|
| 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
|
|
@@ -16,21 +17,25 @@ def chat_logic(message, image_file, history, mode):
|
|
| 16 |
return history, "", None
|
| 17 |
|
| 18 |
if not chimera:
|
| 19 |
-
|
|
|
|
| 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 (
|
| 29 |
if image_file:
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
else:
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
return history, "", None
|
| 36 |
|
|
@@ -45,12 +50,12 @@ with gr.Blocks(title="Axon God Mode", css=custom_css) as demo:
|
|
| 45 |
gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
|
| 46 |
|
| 47 |
with gr.Row():
|
| 48 |
-
|
|
|
|
| 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):
|
|
@@ -73,4 +78,5 @@ with gr.Blocks(title="Axon God Mode", css=custom_css) as demo:
|
|
| 73 |
)
|
| 74 |
|
| 75 |
if __name__ == "__main__":
|
|
|
|
| 76 |
demo.launch(ssr_mode=False)
|
|
|
|
| 9 |
print(f"Startup Error: {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
|
|
|
|
| 17 |
return history, "", None
|
| 18 |
|
| 19 |
if not chimera:
|
| 20 |
+
# Error in Dictionary Format
|
| 21 |
+
history.append({"role": "assistant", "content": "❌ Error: API Keys missing."})
|
| 22 |
return history, "", None
|
| 23 |
|
| 24 |
+
# 2. Process Request
|
| 25 |
response_text, active_module = chimera.process_request(message, history, mode, image_file)
|
| 26 |
|
| 27 |
# 3. Format Output
|
| 28 |
final_response = f"**[{active_module} Active]**\n\n{response_text}"
|
| 29 |
|
| 30 |
+
# 4. Append to History using DICTIONARIES (This fixes the "Incompatible Data" error)
|
| 31 |
if image_file:
|
| 32 |
+
# For uploaded images, we just note it in text for now to keep it stable
|
| 33 |
+
user_msg = f"[Uploaded Image] {message}"
|
| 34 |
else:
|
| 35 |
+
user_msg = message
|
| 36 |
+
|
| 37 |
+
history.append({"role": "user", "content": user_msg})
|
| 38 |
+
history.append({"role": "assistant", "content": final_response})
|
| 39 |
|
| 40 |
return history, "", None
|
| 41 |
|
|
|
|
| 50 |
gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
|
| 51 |
|
| 52 |
with gr.Row():
|
| 53 |
+
# We do NOT set type="messages" (avoids conflict), but we feed it dictionaries (satisfies requirement)
|
| 54 |
+
chatbot = gr.Chatbot(height=500, elem_id="chatbot", type="messages")
|
| 55 |
|
| 56 |
with gr.Row():
|
| 57 |
with gr.Column(scale=4):
|
| 58 |
msg = gr.Textbox(placeholder="Ask anything, or upload an image...", show_label=False)
|
|
|
|
| 59 |
btn_upload = gr.Image(type="filepath", label="Upload for Vision (VIM)", height=70)
|
| 60 |
|
| 61 |
with gr.Column(scale=1):
|
|
|
|
| 78 |
)
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
+
# CRITICAL FIX: ssr_mode=False (Fixes the asyncio crash)
|
| 82 |
demo.launch(ssr_mode=False)
|