aymnsk commited on
Commit
af94bd7
·
verified ·
1 Parent(s): c80e1d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -23,7 +23,7 @@ all_agents = [
23
 
24
  agent_map = {agent.name: agent for agent in all_agents}
25
 
26
- # ✅ Main chat function
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] # Gradio API requires list
37
 
38
- # ✅ Gradio Interface
39
- iface = gr.Interface(
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="Choose Which Personalities to Ask",
50
- value=list(agent_map.keys())
51
  )
52
  ],
53
  outputs=gr.JSON(label="Responses"),
54
- title="PerspectiveAI",
55
- description="Ask a question, get 8 expert AI perspectives.",
56
- theme=gr.themes.Soft()
57
  )
58
 
59
- # ✅ Launch (no ssr anymore!)
60
- iface.launch(
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
  )