Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from agents.journalist import JournalistAgent
|
|
9 |
from agents.trader import TraderAgent
|
10 |
from agents.base_agent import ACPMessage
|
11 |
|
12 |
-
# Initialize all agents
|
13 |
all_agents = [
|
14 |
PhilosopherAgent(),
|
15 |
HistorianAgent(),
|
@@ -21,8 +21,11 @@ all_agents = [
|
|
21 |
TraderAgent()
|
22 |
]
|
23 |
|
|
|
24 |
agent_map = {agent.name: agent for agent in all_agents}
|
25 |
|
|
|
|
|
26 |
def chat(prompt, selected_agents):
|
27 |
responses = {}
|
28 |
for name in selected_agents:
|
@@ -32,25 +35,56 @@ def chat(prompt, selected_agents):
|
|
32 |
except Exception as e:
|
33 |
output = f"[ERROR: {e}]"
|
34 |
responses[name] = output
|
35 |
-
return [responses] # ✅ Required for Gradio API structure
|
36 |
|
|
|
|
|
|
|
|
|
37 |
iface = gr.Interface(
|
38 |
fn=chat,
|
39 |
inputs=[
|
40 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
41 |
gr.CheckboxGroup(
|
42 |
choices=list(agent_map.keys()),
|
43 |
label="Choose Which Personalities to Ask",
|
44 |
-
value=list(agent_map.keys()) # All selected by default
|
45 |
)
|
46 |
],
|
47 |
outputs=gr.JSON(label="Responses"),
|
48 |
title="PerspectiveAI",
|
49 |
description=(
|
50 |
-
"Ask your question and
|
51 |
-
"Created by Aymn
|
52 |
"[Instagram](https://instagram.com/damnn_aymn)"
|
53 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
)
|
55 |
|
56 |
iface.launch()
|
|
|
9 |
from agents.trader import TraderAgent
|
10 |
from agents.base_agent import ACPMessage
|
11 |
|
12 |
+
# ✅ Initialize all 8 agents
|
13 |
all_agents = [
|
14 |
PhilosopherAgent(),
|
15 |
HistorianAgent(),
|
|
|
21 |
TraderAgent()
|
22 |
]
|
23 |
|
24 |
+
# ✅ Map name to agent
|
25 |
agent_map = {agent.name: agent for agent in all_agents}
|
26 |
|
27 |
+
|
28 |
+
# ✅ Function to be called from frontend or Replit
|
29 |
def chat(prompt, selected_agents):
|
30 |
responses = {}
|
31 |
for name in selected_agents:
|
|
|
35 |
except Exception as e:
|
36 |
output = f"[ERROR: {e}]"
|
37 |
responses[name] = output
|
|
|
38 |
|
39 |
+
return [responses] # ✅ Gradio requires return as a list
|
40 |
+
|
41 |
+
|
42 |
+
# ✅ Gradio Interface
|
43 |
iface = gr.Interface(
|
44 |
fn=chat,
|
45 |
inputs=[
|
46 |
+
gr.Textbox(
|
47 |
+
label="Ask Anything",
|
48 |
+
lines=4,
|
49 |
+
placeholder="Ask your question here..."
|
50 |
+
),
|
51 |
gr.CheckboxGroup(
|
52 |
choices=list(agent_map.keys()),
|
53 |
label="Choose Which Personalities to Ask",
|
54 |
+
value=list(agent_map.keys()) # ✅ All selected by default
|
55 |
)
|
56 |
],
|
57 |
outputs=gr.JSON(label="Responses"),
|
58 |
title="PerspectiveAI",
|
59 |
description=(
|
60 |
+
"🤖 Ask your question and receive multi-agent wisdom.\n\n"
|
61 |
+
"Created by Aymn · [GitHub](https://github.com/aymnsk) · "
|
62 |
"[Instagram](https://instagram.com/damnn_aymn)"
|
63 |
+
),
|
64 |
+
theme=gr.themes.Soft(
|
65 |
+
primary_hue="blue",
|
66 |
+
secondary_hue="gray",
|
67 |
+
font=[gr.themes.GoogleFont("Inter")],
|
68 |
+
radius_size=gr.themes.sizes.radius_md,
|
69 |
+
spacing_size=gr.themes.sizes.spacing_md
|
70 |
+
),
|
71 |
+
css="""
|
72 |
+
#chat-input textarea {
|
73 |
+
font-size: 1.1rem;
|
74 |
+
padding: 12px;
|
75 |
+
background: #1e1e2f;
|
76 |
+
color: white;
|
77 |
+
border-radius: 12px;
|
78 |
+
}
|
79 |
+
body {
|
80 |
+
background-color: #111827;
|
81 |
+
color: white;
|
82 |
+
font-family: 'Inter', sans-serif;
|
83 |
+
}
|
84 |
+
.gr-box {
|
85 |
+
border: none;
|
86 |
+
}
|
87 |
+
"""
|
88 |
)
|
89 |
|
90 |
iface.launch()
|