Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,28 +42,47 @@ def chat_logic(message, image_file, history, mode):
|
|
| 42 |
|
| 43 |
# 3. Process Request
|
| 44 |
try:
|
| 45 |
-
|
| 46 |
message or "",
|
| 47 |
simple_history,
|
| 48 |
mode,
|
| 49 |
image_file
|
| 50 |
)
|
| 51 |
except Exception as e:
|
| 52 |
-
|
| 53 |
active_module = "ERR"
|
| 54 |
|
| 55 |
-
# 4.
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# 5. Create user message
|
| 59 |
if image_file:
|
| 60 |
-
user_msg = f"[Uploaded
|
| 61 |
else:
|
| 62 |
user_msg = message
|
| 63 |
|
| 64 |
-
# 6. Append to History
|
| 65 |
history.append({"role": "user", "content": user_msg})
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
return history, "", None
|
| 69 |
|
|
@@ -76,27 +95,44 @@ body {
|
|
| 76 |
.gradio-container {
|
| 77 |
font-family: 'IBM Plex Mono', monospace;
|
| 78 |
}
|
|
|
|
|
|
|
|
|
|
| 79 |
"""
|
| 80 |
|
| 81 |
-
with gr.Blocks(title="
|
| 82 |
gr.Markdown("# ⚡ AXON: GOD MODE")
|
| 83 |
gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
|
| 84 |
|
| 85 |
with gr.Row():
|
| 86 |
-
chatbot = gr.Chatbot(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
with gr.Row():
|
| 89 |
with gr.Column(scale=4):
|
| 90 |
-
msg = gr.Textbox(
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
with gr.Column(scale=1):
|
| 94 |
mode = gr.Dropdown(
|
| 95 |
choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"],
|
| 96 |
value="Auto",
|
| 97 |
-
|
|
|
|
| 98 |
)
|
| 99 |
-
submit = gr.Button("🚀 EXECUTE", variant="primary")
|
| 100 |
|
| 101 |
# Event Handlers
|
| 102 |
submit.click(
|
|
|
|
| 42 |
|
| 43 |
# 3. Process Request
|
| 44 |
try:
|
| 45 |
+
response_data, active_module = chimera.process_request(
|
| 46 |
message or "",
|
| 47 |
simple_history,
|
| 48 |
mode,
|
| 49 |
image_file
|
| 50 |
)
|
| 51 |
except Exception as e:
|
| 52 |
+
response_data = f"Processing Error: {str(e)}"
|
| 53 |
active_module = "ERR"
|
| 54 |
|
| 55 |
+
# 4. Handle response data (could be text or tuple with image)
|
| 56 |
+
if isinstance(response_data, tuple):
|
| 57 |
+
# Image generation response (text, image_path)
|
| 58 |
+
response_text, image_path = response_data
|
| 59 |
+
final_response = f"**[{active_module} Active]**\n\n{response_text}"
|
| 60 |
+
else:
|
| 61 |
+
# Regular text response
|
| 62 |
+
response_text = response_data
|
| 63 |
+
image_path = None
|
| 64 |
+
final_response = f"**[{active_module} Active]**\n\n{response_text}"
|
| 65 |
|
| 66 |
# 5. Create user message
|
| 67 |
if image_file:
|
| 68 |
+
user_msg = f"🖼️ [Image Uploaded]\n\n{message or 'Analyze this image'}"
|
| 69 |
else:
|
| 70 |
user_msg = message
|
| 71 |
|
| 72 |
+
# 6. Append to History
|
| 73 |
history.append({"role": "user", "content": user_msg})
|
| 74 |
+
|
| 75 |
+
# If there's an image to display, include it in the response
|
| 76 |
+
if image_path:
|
| 77 |
+
history.append({
|
| 78 |
+
"role": "assistant",
|
| 79 |
+
"content": {
|
| 80 |
+
"text": final_response,
|
| 81 |
+
"files": [image_path]
|
| 82 |
+
}
|
| 83 |
+
})
|
| 84 |
+
else:
|
| 85 |
+
history.append({"role": "assistant", "content": final_response})
|
| 86 |
|
| 87 |
return history, "", None
|
| 88 |
|
|
|
|
| 95 |
.gradio-container {
|
| 96 |
font-family: 'IBM Plex Mono', monospace;
|
| 97 |
}
|
| 98 |
+
#chatbot {
|
| 99 |
+
border-radius: 10px;
|
| 100 |
+
}
|
| 101 |
"""
|
| 102 |
|
| 103 |
+
with gr.Blocks(title="⚡ AXON: GOD MODE") as demo:
|
| 104 |
gr.Markdown("# ⚡ AXON: GOD MODE")
|
| 105 |
gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
|
| 106 |
|
| 107 |
with gr.Row():
|
| 108 |
+
chatbot = gr.Chatbot(
|
| 109 |
+
height=500,
|
| 110 |
+
elem_id="chatbot",
|
| 111 |
+
avatar_images=(None, "🤖"),
|
| 112 |
+
show_copy_button=True
|
| 113 |
+
)
|
| 114 |
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column(scale=4):
|
| 117 |
+
msg = gr.Textbox(
|
| 118 |
+
placeholder="Ask anything, or upload an image...",
|
| 119 |
+
show_label=False,
|
| 120 |
+
container=False
|
| 121 |
+
)
|
| 122 |
+
btn_upload = gr.Image(
|
| 123 |
+
type="filepath",
|
| 124 |
+
label="📸 Upload for Vision (VIM)",
|
| 125 |
+
height=100
|
| 126 |
+
)
|
| 127 |
|
| 128 |
with gr.Column(scale=1):
|
| 129 |
mode = gr.Dropdown(
|
| 130 |
choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"],
|
| 131 |
value="Auto",
|
| 132 |
+
label="Mode",
|
| 133 |
+
show_label=True
|
| 134 |
)
|
| 135 |
+
submit = gr.Button("🚀 EXECUTE", variant="primary", size="lg")
|
| 136 |
|
| 137 |
# Event Handlers
|
| 138 |
submit.click(
|