callanwu commited on
Commit
cd14fc6
1 Parent(s): 0738b43
Files changed (2) hide show
  1. app.py +11 -4
  2. gradio_backend.py +7 -8
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import sys
 
2
 
3
  from gradio_base import UIHelper, WebUI
4
  import os
@@ -8,6 +9,7 @@ from typing import List, Tuple, Any
8
  import gradio as gr
9
  import time
10
 
 
11
  class DebateUI(WebUI):
12
  FORMAT = "{}\n<debate topic>\n{}\nAffirmative viewpoint:{}\nNegative viewpoint:{}\n<debate topic>{}"
13
  AUDIENCE = "Audience"
@@ -77,13 +79,13 @@ class DebateUI(WebUI):
77
  render_data = self.render_bubble(history, self.data_history, node_name, render_node_name= True or state % 10 == 2)
78
  return render_data
79
 
80
- def start_button_when_click(self, theme, positive, negative, choose, mode):
81
  """
82
  inputs=[self.text_theme, self.text_positive, self.text_negative, self.radio_choose],
83
  outputs=[self.chatbot, self.btn_send]
84
  """
85
  cosplay = None if choose == self.AUDIENCE else choose.split("(")[0]
86
- message = dict(theme=theme, positive=positive, negative=negative, cosplay=cosplay, mode=mode)
87
  self.send_start_cmd(message=message)
88
  return gr.Chatbot.update(
89
  visible=True
@@ -209,6 +211,11 @@ class DebateUI(WebUI):
209
  with gr.Blocks(css=gc.CSS) as demo:
210
  with gr.Row():
211
  with gr.Column():
 
 
 
 
 
212
  self.radio_mode = gr.Radio(
213
  [Client.AUTO_MODE, Client.SINGLE_MODE],
214
  value=Client.AUTO_MODE,
@@ -268,7 +275,7 @@ class DebateUI(WebUI):
268
 
269
  self.btn_start.click(
270
  fn=self.start_button_when_click,
271
- inputs=[self.text_theme, self.text_positive, self.text_negative, self.radio_choose, self.radio_mode],
272
  outputs=[self.chatbot, self.btn_start]
273
  ).then(
274
  fn=self.start_button_after_click,
@@ -350,4 +357,4 @@ class DebateUI(WebUI):
350
  if __name__ == '__main__':
351
  ui = DebateUI(client_cmd=["python","gradio_backend.py"])
352
  ui.construct_ui()
353
- ui.run()
 
1
  import sys
2
+ sys.path.append("../../Gradio_Config")
3
 
4
  from gradio_base import UIHelper, WebUI
5
  import os
 
9
  import gradio as gr
10
  import time
11
 
12
+
13
  class DebateUI(WebUI):
14
  FORMAT = "{}\n<debate topic>\n{}\nAffirmative viewpoint:{}\nNegative viewpoint:{}\n<debate topic>{}"
15
  AUDIENCE = "Audience"
 
79
  render_data = self.render_bubble(history, self.data_history, node_name, render_node_name= True or state % 10 == 2)
80
  return render_data
81
 
82
+ def start_button_when_click(self, theme, positive, negative, choose, mode, api_key):
83
  """
84
  inputs=[self.text_theme, self.text_positive, self.text_negative, self.radio_choose],
85
  outputs=[self.chatbot, self.btn_send]
86
  """
87
  cosplay = None if choose == self.AUDIENCE else choose.split("(")[0]
88
+ message = dict(theme=theme, positive=positive, negative=negative, cosplay=cosplay, mode=mode, api_key=api_key)
89
  self.send_start_cmd(message=message)
90
  return gr.Chatbot.update(
91
  visible=True
 
211
  with gr.Blocks(css=gc.CSS) as demo:
212
  with gr.Row():
213
  with gr.Column():
214
+ self.text_api = gr.Textbox(
215
+ value = self.cache["api_key"],
216
+ placeholder="openai key",
217
+ label="Please input valid openai key for gpt-3.5-turbo-16k."
218
+ )
219
  self.radio_mode = gr.Radio(
220
  [Client.AUTO_MODE, Client.SINGLE_MODE],
221
  value=Client.AUTO_MODE,
 
275
 
276
  self.btn_start.click(
277
  fn=self.start_button_when_click,
278
+ inputs=[self.text_theme, self.text_positive, self.text_negative, self.radio_choose, self.radio_mode, self.text_api],
279
  outputs=[self.chatbot, self.btn_start]
280
  ).then(
281
  fn=self.start_button_after_click,
 
357
  if __name__ == '__main__':
358
  ui = DebateUI(client_cmd=["python","gradio_backend.py"])
359
  ui.construct_ui()
360
+ ui.run()
gradio_backend.py CHANGED
@@ -2,14 +2,12 @@ import yaml
2
  import os
3
  import argparse
4
  import sys
5
- sys.path.append("../../../src/agents")
6
- sys.path.append("../../Gradio_Config")
7
  from agents.SOP import SOP
8
  from agents.Agent import Agent
9
  from agents.Environment import Environment
10
  from agents.Memory import Memory
11
  from gradio_base import Client
12
- from app import DebateUI
13
 
14
  def process(action):
15
  response = action.response
@@ -43,7 +41,7 @@ def gradio_process(action,current_state):
43
  if item.startswith("<USER>"):
44
  content = item.split("<USER>")[1]
45
  break
46
- # print(f"client: recieved `{content}` from server")
47
  action.response = content
48
  break
49
  else:
@@ -83,12 +81,12 @@ def init(config):
83
  def run(agents,sop,environment):
84
  while True:
85
  current_state,current_agent= sop.next(environment,agents)
86
- block_when_next(current_agent, current_state)
87
  if sop.finished:
88
  print("finished!")
89
- Client.send_server(str([99, ' ', ' ', current_state.name]))
90
  os.environ.clear()
91
  break
 
92
  action = current_agent.step(current_state,"") #component_dict = current_state[self.role[current_node.name]] current_agent.compile(component_dict)
93
  gradio_process(action,current_state)
94
  memory = process(action)
@@ -107,12 +105,14 @@ def prepare(agents, sop, environment):
107
  "negative": f"{parse_data[2]}",
108
  "agents_name": DebateUI.convert2list4agentname(sop)[0],
109
  "only_name": DebateUI.convert2list4agentname(sop)[0],
110
- "default_cos_play_id": -1
 
111
  }
112
  )
113
  client.listening_for_start_()
114
  client.mode = Client.mode = client.cache["mode"]
115
  # cover config and then start
 
116
  if Client.cache["cosplay"] is not None:
117
  agents[Client.cache["cosplay"]].is_user = True
118
  sop.states['Negative_Task_Allocation_state'] = sop.states['Affirmative_Task_Allocation_state'].begin_query = \
@@ -135,4 +135,3 @@ if __name__ == '__main__':
135
 
136
  run(agents,sop,environment)
137
 
138
-
 
2
  import os
3
  import argparse
4
  import sys
 
 
5
  from agents.SOP import SOP
6
  from agents.Agent import Agent
7
  from agents.Environment import Environment
8
  from agents.Memory import Memory
9
  from gradio_base import Client
10
+ from run_gradio import DebateUI
11
 
12
  def process(action):
13
  response = action.response
 
41
  if item.startswith("<USER>"):
42
  content = item.split("<USER>")[1]
43
  break
44
+ # print(f"client: received `{content}` from server")
45
  action.response = content
46
  break
47
  else:
 
81
  def run(agents,sop,environment):
82
  while True:
83
  current_state,current_agent= sop.next(environment,agents)
 
84
  if sop.finished:
85
  print("finished!")
86
+ Client.send_server(str([99, ' ', ' ', "done"]))
87
  os.environ.clear()
88
  break
89
+ block_when_next(current_agent, current_state)
90
  action = current_agent.step(current_state,"") #component_dict = current_state[self.role[current_node.name]] current_agent.compile(component_dict)
91
  gradio_process(action,current_state)
92
  memory = process(action)
 
105
  "negative": f"{parse_data[2]}",
106
  "agents_name": DebateUI.convert2list4agentname(sop)[0],
107
  "only_name": DebateUI.convert2list4agentname(sop)[0],
108
+ "default_cos_play_id": -1,
109
+ "api_key": os.environ["API_KEY"]
110
  }
111
  )
112
  client.listening_for_start_()
113
  client.mode = Client.mode = client.cache["mode"]
114
  # cover config and then start
115
+ os.environ["API_KEY"] = client.cache["api_key"]
116
  if Client.cache["cosplay"] is not None:
117
  agents[Client.cache["cosplay"]].is_user = True
118
  sop.states['Negative_Task_Allocation_state'] = sop.states['Affirmative_Task_Allocation_state'].begin_query = \
 
135
 
136
  run(agents,sop,environment)
137