AIencoder/AXON-TRINITY
0
1import warnings2import sys3 4# Suppress asyncio warnings (Python 3.12/3.13 known issue with Gradio)5warnings.filterwarnings('ignore', message='.*Invalid file descriptor.*')6if sys.version_info >= (3, 12):7 import logging8 logging.getLogger('asyncio').setLevel(logging.CRITICAL)9 10import gradio as gr11from src.chimera_core import Chimera12 13# Initialize14try:15 chimera = Chimera()16except Exception as e:17 chimera = None18 print(f"Startup Error: {e}")19 20def chat_logic(message, image_file, history, mode):21 # Ensure history is a list22 if history is None:23 history = []24 25 # 1. Handle Empty Input26 if not message and not image_file:27 return history, "", None28 29 if not chimera:30 user_msg = message or "[Image uploaded]"31 history.append({"role": "user", "content": user_msg})32 history.append({"role": "assistant", "content": "โ Error: API Keys missing."})33 return history, "", None34 35 # 2. Convert history to simple format for chimera36 simple_history = []37 for msg in history:38 if isinstance(msg, dict):39 simple_history.append([msg.get("content", "")])40 else:41 simple_history.append(msg)42 43 # 3. Process Request44 try:45 response_data, active_module = chimera.process_request(46 message or "", 47 simple_history, 48 mode, 49 image_file50 )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_data59 final_response = f"**[{active_module} Active]**\n\n{response_text}"60 else:61 # Regular text response62 response_text = response_data63 image_path = None64 final_response = f"**[{active_module} Active]**\n\n{response_text}"65 66 # 5. Create user message67 if image_file:68 user_msg = f"๐ผ๏ธ [Image Uploaded]\n\n{message or 'Analyze this image'}"69 else:70 user_msg = message71 72 # 6. Append to History73 history.append({"role": "user", "content": user_msg})74 75 # If there's an image to display, include it in the response76 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, "", None88 89# --- UI Layout ---90custom_css = """91body {92 background-color: #0b0f19;93 color: #c9d1d9;94}95.gradio-container {96 font-family: 'IBM Plex Mono', monospace;97}98#chatbot {99 border-radius: 10px;100}101"""102 103with 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 )112 113 with gr.Row():114 with gr.Column(scale=4):115 msg = gr.Textbox(116 placeholder="Ask anything, or upload an image...", 117 show_label=False,118 container=False119 )120 btn_upload = gr.Image(121 type="filepath", 122 label="๐ธ Upload for Vision (VIM)", 123 height=100124 )125 126 with gr.Column(scale=1):127 mode = gr.Dropdown(128 choices=["Auto", "ASM (Code)", "IGM (Generate Image)", "NET (Search)", "VIM (Vision)"],129 value="Auto",130 label="Mode",131 show_label=True132 )133 submit = gr.Button("๐ EXECUTE", variant="primary", size="lg")134 135 # Event Handlers136 submit.click(137 chat_logic,138 inputs=[msg, btn_upload, chatbot, mode],139 outputs=[chatbot, msg, btn_upload]140 )141 msg.submit(142 chat_logic,143 inputs=[msg, btn_upload, chatbot, mode],144 outputs=[chatbot, msg, btn_upload]145 )146 147if __name__ == "__main__":148 demo.launch(ssr_mode=False, css=custom_css)