Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,70 +1,76 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from src.chimera_core import Chimera
|
| 3 |
-
|
| 4 |
-
# Initialize the Beast
|
| 5 |
-
try:
|
| 6 |
-
chimera = Chimera()
|
| 7 |
-
except Exception as e:
|
| 8 |
-
chimera = None
|
| 9 |
-
print(f"Startup Error: {e}")
|
| 10 |
-
|
| 11 |
-
def chat_logic(message, history, mode_selection):
|
| 12 |
-
if not chimera:
|
| 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 |
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from src.chimera_core import Chimera
|
| 3 |
+
|
| 4 |
+
# Initialize the Beast
|
| 5 |
+
try:
|
| 6 |
+
chimera = Chimera()
|
| 7 |
+
except Exception as e:
|
| 8 |
+
chimera = None
|
| 9 |
+
print(f"Startup Error: {e}")
|
| 10 |
+
|
| 11 |
+
def chat_logic(message, history, mode_selection):
|
| 12 |
+
if not chimera:
|
| 13 |
+
# Error handling also needs to be a dictionary now
|
| 14 |
+
history.append({"role": "assistant", "content": "β Error: API Key missing. Check Settings -> Secrets."})
|
| 15 |
+
return history, ""
|
| 16 |
+
|
| 17 |
+
# Map friendly names to internal codes
|
| 18 |
+
role_map = {
|
| 19 |
+
"Auto (Router)": "Auto",
|
| 20 |
+
"π¨βπ» ASM (Coder)": "ASM",
|
| 21 |
+
"π¬ SFE (Scientist)": "SFE",
|
| 22 |
+
"π¨ CSM (Writer)": "CSM"
|
| 23 |
+
}
|
| 24 |
+
selected_role = role_map.get(mode_selection, "Auto")
|
| 25 |
+
|
| 26 |
+
# Get response
|
| 27 |
+
response_text, active_module = chimera.process_request(message, history, selected_role)
|
| 28 |
+
|
| 29 |
+
# Format the output with the active module tag
|
| 30 |
+
final_response = f"**[{active_module} Active]**\n\n{response_text}"
|
| 31 |
+
|
| 32 |
+
# --- THE FIX IS HERE ---
|
| 33 |
+
# Instead of history.append((message, final_response)), we do this:
|
| 34 |
+
history.append({"role": "user", "content": message})
|
| 35 |
+
history.append({"role": "assistant", "content": final_response})
|
| 36 |
+
|
| 37 |
+
return history, ""
|
| 38 |
+
|
| 39 |
+
# --- Sci-Fi Theme CSS ---
|
| 40 |
+
custom_css = """
|
| 41 |
+
body {background-color: #0b0f19; color: #c9d1d9;}
|
| 42 |
+
.gradio-container {font-family: 'IBM Plex Mono', monospace;}
|
| 43 |
+
header {display: none !important;}
|
| 44 |
+
#chatbot {
|
| 45 |
+
height: 600px;
|
| 46 |
+
border: 1px solid #30363d;
|
| 47 |
+
background-color: #0d1117;
|
| 48 |
+
border-radius: 12px;
|
| 49 |
+
}
|
| 50 |
+
.feedback {font-size: 12px; color: #8b949e;}
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
with gr.Blocks(css=custom_css, title="Project Chimera") as demo:
|
| 54 |
+
gr.Markdown("# π¦ Project Chimera")
|
| 55 |
+
gr.Markdown("*> Multi-Persona Routing System // Online*")
|
| 56 |
+
|
| 57 |
+
with gr.Row():
|
| 58 |
+
with gr.Column(scale=4):
|
| 59 |
+
chatbot = gr.Chatbot(elem_id="chatbot", type="messages")
|
| 60 |
+
|
| 61 |
+
with gr.Column(scale=1):
|
| 62 |
+
gr.Markdown("### βοΈ System Controls")
|
| 63 |
+
mode = gr.Dropdown(
|
| 64 |
+
choices=["Auto (Router)", "π¨βπ» ASM (Coder)", "π¬ SFE (Scientist)", "π¨ CSM (Writer)"],
|
| 65 |
+
value="Auto (Router)",
|
| 66 |
+
label="Persona Mode",
|
| 67 |
+
interactive=True
|
| 68 |
+
)
|
| 69 |
+
gr.Markdown("*Select 'Auto' to let the AI decide, or force a specific module.*")
|
| 70 |
+
|
| 71 |
+
msg = gr.Textbox(placeholder="Enter command or query...", autofocus=True, label="User Input")
|
| 72 |
+
|
| 73 |
+
msg.submit(chat_logic, [msg, chatbot, mode], [chatbot, msg])
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
demo.launch()
|