Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,33 +25,37 @@ all_agents = [
|
|
| 25 |
agent_map = {agent.name: agent for agent in all_agents}
|
| 26 |
|
| 27 |
|
| 28 |
-
# β
|
| 29 |
def chat(prompt, selected_agents):
|
| 30 |
responses = {}
|
| 31 |
for name in selected_agents:
|
| 32 |
agent = agent_map.get(name)
|
| 33 |
try:
|
| 34 |
output = agent.generate([ACPMessage(role="user", content=prompt)])
|
|
|
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
output = f"[ERROR: {e}]"
|
| 37 |
responses[name] = output
|
| 38 |
|
| 39 |
-
return [responses] # β
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
-
# β
|
| 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()) # β
|
| 55 |
)
|
| 56 |
],
|
| 57 |
outputs=gr.JSON(label="Responses"),
|
|
@@ -87,4 +91,5 @@ iface = gr.Interface(
|
|
| 87 |
"""
|
| 88 |
)
|
| 89 |
|
|
|
|
| 90 |
iface.launch()
|
|
|
|
| 25 |
agent_map = {agent.name: agent for agent in all_agents}
|
| 26 |
|
| 27 |
|
| 28 |
+
# β
Core response function
|
| 29 |
def chat(prompt, selected_agents):
|
| 30 |
responses = {}
|
| 31 |
for name in selected_agents:
|
| 32 |
agent = agent_map.get(name)
|
| 33 |
try:
|
| 34 |
output = agent.generate([ACPMessage(role="user", content=prompt)])
|
| 35 |
+
if isinstance(output, list): # Handle output like [msg]
|
| 36 |
+
output = output[0]
|
| 37 |
except Exception as e:
|
| 38 |
output = f"[ERROR: {e}]"
|
| 39 |
responses[name] = output
|
| 40 |
|
| 41 |
+
return [responses] # β
Must return list for Gradio API format
|
| 42 |
+
# That results in: { "data": [ { "Philosopher": "...", ... } ] }
|
| 43 |
|
| 44 |
|
| 45 |
+
# β
Interface for direct testing/debugging (optional if using just API)
|
| 46 |
iface = gr.Interface(
|
| 47 |
fn=chat,
|
| 48 |
inputs=[
|
| 49 |
gr.Textbox(
|
| 50 |
label="Ask Anything",
|
| 51 |
lines=4,
|
| 52 |
+
placeholder="Ask your question here...",
|
| 53 |
+
elem_id="chat-input"
|
| 54 |
),
|
| 55 |
gr.CheckboxGroup(
|
| 56 |
choices=list(agent_map.keys()),
|
| 57 |
label="Choose Which Personalities to Ask",
|
| 58 |
+
value=list(agent_map.keys()) # β
default: all selected
|
| 59 |
)
|
| 60 |
],
|
| 61 |
outputs=gr.JSON(label="Responses"),
|
|
|
|
| 91 |
"""
|
| 92 |
)
|
| 93 |
|
| 94 |
+
# β
Launch Gradio β allow API call via /run/predict
|
| 95 |
iface.launch()
|