Spaces:
Sleeping
Sleeping
File size: 4,293 Bytes
1317471 dbf3196 1317471 dbf3196 713e8e6 70f515f 713e8e6 d4b3a04 28b5b32 3d29f72 713e8e6 d4b3a04 3d29f72 d4b3a04 3d29f72 d4b3a04 3d29f72 d6ab688 3d29f72 ee8059f 63316a5 3d29f72 ee8059f 63316a5 ee8059f d4b3a04 63316a5 d4b3a04 3d29f72 d4b3a04 63316a5 d4b3a04 ee8059f 3d29f72 63316a5 3d29f72 63316a5 713e8e6 d4b3a04 713e8e6 d4b3a04 713e8e6 3d29f72 63316a5 713e8e6 63316a5 d4b3a04 713e8e6 d4b3a04 63316a5 b2ea920 63316a5 d4b3a04 63316a5 d4b3a04 3d29f72 63316a5 d4b3a04 63316a5 3d29f72 d4b3a04 3d29f72 d4b3a04 3d29f72 d4b3a04 ced25cf 713e8e6 dbf3196 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
import warnings
import sys
# Suppress asyncio warnings (Python 3.12/3.13 known issue with Gradio)
warnings.filterwarnings('ignore', message='.*Invalid file descriptor.*')
if sys.version_info >= (3, 12):
import logging
logging.getLogger('asyncio').setLevel(logging.CRITICAL)
import gradio as gr
from src.chimera_core import Chimera
# Initialize
try:
chimera = Chimera()
except Exception as e:
chimera = None
print(f"Startup Error: {e}")
def chat_logic(message, image_file, history, mode):
# Ensure history is a list
if history is None:
history = []
# 1. Handle Empty Input
if not message and not image_file:
return history, "", None
if not chimera:
user_msg = message or "[Image uploaded]"
history.append({"role": "user", "content": user_msg})
history.append({"role": "assistant", "content": "❌ Error: API Keys missing."})
return history, "", None
# 2. Convert history to simple format for chimera
simple_history = []
for msg in history:
if isinstance(msg, dict):
simple_history.append([msg.get("content", "")])
else:
simple_history.append(msg)
# 3. Process Request
try:
response_data, active_module = chimera.process_request(
message or "",
simple_history,
mode,
image_file
)
except Exception as e:
response_data = f"Processing Error: {str(e)}"
active_module = "ERR"
# 4. Handle response data (could be text or tuple with image)
if isinstance(response_data, tuple):
# Image generation response (text, image_path)
response_text, image_path = response_data
final_response = f"**[{active_module} Active]**\n\n{response_text}"
else:
# Regular text response
response_text = response_data
image_path = None
final_response = f"**[{active_module} Active]**\n\n{response_text}"
# 5. Create user message
if image_file:
user_msg = f"🖼️ [Image Uploaded]\n\n{message or 'Analyze this image'}"
else:
user_msg = message
# 6. Append to History
history.append({"role": "user", "content": user_msg})
# If there's an image to display, include it in the response
if image_path:
history.append({
"role": "assistant",
"content": {
"text": final_response,
"files": [image_path]
}
})
else:
history.append({"role": "assistant", "content": final_response})
return history, "", None
# --- UI Layout ---
custom_css = """
body {
background-color: #0b0f19;
color: #c9d1d9;
}
.gradio-container {
font-family: 'IBM Plex Mono', monospace;
}
#chatbot {
border-radius: 10px;
}
"""
with gr.Blocks(title="⚡ AXON: GOD MODE") as demo:
gr.Markdown("# ⚡ AXON: GOD MODE")
gr.Markdown("*> Modules: VIM (Vision) | NET (Web) | IGM (Art) | ASM (Code)*")
with gr.Row():
chatbot = gr.Chatbot(
height=500,
elem_id="chatbot"
)
with gr.Row():
with gr.Column(scale=4):
msg = gr.Textbox(
placeholder="Ask anything, or upload an image...",
show_label=False,
container=False
)
btn_upload = gr.Image(
type="filepath",
label="📸 Upload for Vision (VIM)",
height=100
)
with gr.Column(scale=1):
mode = gr.Dropdown(
choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"],
value="Auto",
label="Mode",
show_label=True
)
submit = gr.Button("🚀 EXECUTE", variant="primary", size="lg")
# Event Handlers
submit.click(
chat_logic,
inputs=[msg, btn_upload, chatbot, mode],
outputs=[chatbot, msg, btn_upload]
)
msg.submit(
chat_logic,
inputs=[msg, btn_upload, chatbot, mode],
outputs=[chatbot, msg, btn_upload]
)
if __name__ == "__main__":
demo.launch(ssr_mode=False, css=custom_css) |