Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,7 @@ all_agents = [
|
|
23 |
|
24 |
agent_map = {agent.name: agent for agent in all_agents}
|
25 |
|
26 |
-
# ✅
|
27 |
def chat(prompt, selected_agents):
|
28 |
responses = {}
|
29 |
for name in selected_agents:
|
@@ -33,32 +33,28 @@ def chat(prompt, selected_agents):
|
|
33 |
except Exception as e:
|
34 |
output = f"[ERROR: {e}]"
|
35 |
responses[name] = output
|
36 |
-
return [responses] #
|
37 |
|
38 |
-
# ✅
|
39 |
-
|
40 |
fn=chat,
|
41 |
inputs=[
|
42 |
-
gr.Textbox(
|
43 |
-
label="Ask Anything",
|
44 |
-
lines=4,
|
45 |
-
placeholder="Ask your question here..."
|
46 |
-
),
|
47 |
gr.CheckboxGroup(
|
48 |
choices=list(agent_map.keys()),
|
49 |
-
label="
|
50 |
-
value=list(agent_map.keys())
|
51 |
)
|
52 |
],
|
53 |
outputs=gr.JSON(label="Responses"),
|
54 |
-
|
55 |
-
|
56 |
-
theme=gr.themes.Soft()
|
57 |
)
|
58 |
|
59 |
-
# ✅ Launch
|
60 |
-
|
61 |
server_name="0.0.0.0",
|
62 |
server_port=7860,
|
63 |
-
show_api=True
|
|
|
64 |
)
|
|
|
23 |
|
24 |
agent_map = {agent.name: agent for agent in all_agents}
|
25 |
|
26 |
+
# ✅ Core chat function
|
27 |
def chat(prompt, selected_agents):
|
28 |
responses = {}
|
29 |
for name in selected_agents:
|
|
|
33 |
except Exception as e:
|
34 |
output = f"[ERROR: {e}]"
|
35 |
responses[name] = output
|
36 |
+
return [responses] # must return list
|
37 |
|
38 |
+
# ✅ Interface
|
39 |
+
demo = gr.Interface(
|
40 |
fn=chat,
|
41 |
inputs=[
|
42 |
+
gr.Textbox(label="Prompt"),
|
|
|
|
|
|
|
|
|
43 |
gr.CheckboxGroup(
|
44 |
choices=list(agent_map.keys()),
|
45 |
+
label="Agents",
|
46 |
+
value=list(agent_map.keys()) # default select all
|
47 |
)
|
48 |
],
|
49 |
outputs=gr.JSON(label="Responses"),
|
50 |
+
live=False,
|
51 |
+
title="PerspectiveAI Backend API"
|
|
|
52 |
)
|
53 |
|
54 |
+
# ✅ Launch ONLY in API mode
|
55 |
+
demo.launch(
|
56 |
server_name="0.0.0.0",
|
57 |
server_port=7860,
|
58 |
+
show_api=True, # 🔥 Enables /run/predict
|
59 |
+
share=False # Optional
|
60 |
)
|