AIencoder commited on
Commit
713e8e6
Β·
verified Β·
1 Parent(s): 12ba16b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -69
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
- return history + [["", "❌ Error: API Key missing. Check Settings -> Secrets."]], ""
14
-
15
- # Map friendly names to internal codes
16
- role_map = {
17
- "Auto (Router)": "Auto",
18
- "πŸ‘¨β€πŸ’» ASM (Coder)": "ASM",
19
- "πŸ”¬ SFE (Scientist)": "SFE",
20
- "🎨 CSM (Writer)": "CSM"
21
- }
22
- selected_role = role_map.get(mode_selection, "Auto")
23
-
24
- # Get response
25
- response_text, active_module = chimera.process_request(message, history, selected_role)
26
-
27
- # Format the output with the active module tag
28
- final_response = f"**[{active_module} Active]**\n\n{response_text}"
29
-
30
- history.append((message, final_response))
31
- return history, ""
32
-
33
- # --- Sci-Fi Theme CSS ---
34
- custom_css = """
35
- body {background-color: #0b0f19; color: #c9d1d9;}
36
- .gradio-container {font-family: 'IBM Plex Mono', monospace;}
37
- header {display: none !important;}
38
- #chatbot {
39
- height: 600px;
40
- border: 1px solid #30363d;
41
- background-color: #0d1117;
42
- border-radius: 12px;
43
- }
44
- .feedback {font-size: 12px; color: #8b949e;}
45
- """
46
-
47
- with gr.Blocks(css=custom_css, title="Project Chimera") as demo:
48
- gr.Markdown("# 🦁 Project Chimera")
49
- gr.Markdown("*> Multi-Persona Routing System // Online*")
50
-
51
- with gr.Row():
52
- with gr.Column(scale=4):
53
- chatbot = gr.Chatbot(elem_id="chatbot", type="messages")
54
-
55
- with gr.Column(scale=1):
56
- gr.Markdown("### βš™οΈ System Controls")
57
- mode = gr.Dropdown(
58
- choices=["Auto (Router)", "πŸ‘¨β€πŸ’» ASM (Coder)", "πŸ”¬ SFE (Scientist)", "🎨 CSM (Writer)"],
59
- value="Auto (Router)",
60
- label="Persona Mode",
61
- interactive=True
62
- )
63
- gr.Markdown("*Select 'Auto' to let the AI decide, or force a specific module.*")
64
-
65
- msg = gr.Textbox(placeholder="Enter command or query...", autofocus=True, label="User Input")
66
-
67
- msg.submit(chat_logic, [msg, chatbot, mode], [chatbot, msg])
68
-
69
- if __name__ == "__main__":
 
 
 
 
 
 
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()