Spaces:
Sleeping
Sleeping
| 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: | |
| # Classic Format: [User Message, Bot Message] | |
| history.append([message, "β Error: API Keys missing."]) | |
| return history, "", None | |
| # 2. Process Request | |
| response_text, active_module = chimera.process_request(message, history, mode, image_file) | |
| # 3. Format Output | |
| final_response = f"**[{active_module} Active]**\n\n{response_text}" | |
| # 4. Append to History using CLASSIC LISTS | |
| # This format works on ALL versions of Gradio. | |
| if image_file: | |
| user_msg = f"[Uploaded Image] {message}" | |
| else: | |
| user_msg = message | |
| # CRITICAL FIX: Appending a List [User, AI], NOT a Dictionary | |
| history.append([user_msg, final_response]) | |
| return history, "", None | |
| # --- UI Layout --- | |
| custom_css = """ | |
| body {background-color: #0b0f19; color: #c9d1d9;} | |
| .gradio-container {font-family: 'IBM Plex Mono', monospace;} | |
| """ | |
| # Removed 'css' from constructor to fix warning | |
| 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(): | |
| # CRITICAL FIX: Removed type="messages" (This was causing the crash) | |
| 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) | |
| btn_upload = gr.Image(type="filepath", label="Upload for Vision (VIM)", height=70) | |
| with gr.Column(scale=1): | |
| mode = gr.Dropdown( | |
| choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"], | |
| value="Auto", show_label=False | |
| ) | |
| submit = gr.Button("π EXECUTE", variant="primary") | |
| # 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__": | |
| # CRITICAL FIX: ssr_mode=False (Fixes the asyncio crash) | |
| # Moved css=custom_css here (Fixes the warning) | |
| demo.launch(ssr_mode=False, css=custom_css) |