alistairmcleay commited on
Commit
db90364
β€’
1 Parent(s): 19cbc2a

Improving UI

Browse files
Files changed (1) hide show
  1. app.py +56 -20
app.py CHANGED
@@ -13,7 +13,6 @@ from scripts.UBAR_code.interaction import UBAR_interact
13
  from scripts.user_model_code.interaction import multiwoz_interact
14
  from scripts.UBAR_code.interaction.UBAR_interact import bcolors
15
 
16
-
17
  # Initialise agents
18
  UBAR_checkpoint_path = "epoch50_trloss0.59_gpt2"
19
  user_model_checkpoint_path = "MultiWOZ-full_checkpoint_step340k"
@@ -48,22 +47,41 @@ us_history = []
48
  self_play_history = []
49
 
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  def change_goal():
52
  global curr_goal_idx
53
  curr_goal_idx = random.randint(0, n_goals - 1)
54
  current_goal = goals[curr_goal_idx]
55
- user_model.init_session(ini_goal=current_goal)
56
  current_goal_yaml = yaml.dump(current_goal, default_flow_style=False)
57
- return current_goal_yaml
58
 
59
 
60
  def change_sp_goal():
61
  global curr_sp_goal_idx
62
  curr_sp_goal_idx = random.randint(0, n_goals - 1)
63
  current_sp_goal = goals[curr_sp_goal_idx]
64
- self_play_user_model.init_session(ini_goal=current_sp_goal)
65
  current_sp_goal_yaml = yaml.dump(current_sp_goal, default_flow_style=False)
66
- return current_sp_goal_yaml
67
 
68
 
69
  def ds_chatbot(user_utt):
@@ -87,10 +105,10 @@ def self_play():
87
  else:
88
  sys_response = self_play_history[-1][1]
89
 
90
- user_utt = user_model.response(sys_response)
91
 
92
  turn_id = len(self_play_history)
93
- sys_response = sys_model.response(user_utt, turn_id)
94
 
95
  self_play_history.append((user_utt, sys_response))
96
 
@@ -104,12 +122,20 @@ def self_play():
104
  block = gr.Blocks()
105
 
106
  with block:
107
- gr.Markdown("# Demo User Simulator and Task-Oriented Dialogue System")
108
- gr.Markdown("*Created by Alistair McLeay, with help from Professor Bill Byrne, Andy Tseng, and Alex Coca*")
 
 
 
 
 
 
 
 
109
  with gr.Tabs():
110
  with gr.TabItem("Dialogue System"):
111
  gr.Markdown(
112
- "This bot is a Task-Oriented Dialogue Systen. You are the user. Go ahead and try to book a train, or a hotel etc."
113
  )
114
  with gr.Row():
115
  ds_input_text = gr.inputs.Textbox(
@@ -117,34 +143,44 @@ with block:
117
  )
118
  ds_response = gr.outputs.Chatbot(label="Dialogue System Response")
119
  ds_button = gr.Button("Submit Message")
 
120
 
121
  with gr.TabItem("User Simulator"):
122
  gr.Markdown(
123
- "This bot is a User Simulator. You are the Task-Oriented Dialogue System. Your job is to help the user with their requests."
124
  )
125
- new_goal_button = gr.Button("Generate Goal")
126
  with gr.Row():
127
  us_input_text = gr.inputs.Textbox(
128
  label="Dialogue System Message", placeholder="How can I help you today?"
129
  )
130
  us_response = gr.outputs.Chatbot(label="User Simulator Response")
131
- current_goal_yaml = gr.outputs.Textbox(label="Current Goal (YAML)")
132
  us_button = gr.Button("Submit Message")
 
 
 
133
 
134
  with gr.TabItem("Self-Play"):
135
  gr.Markdown(
136
- "In this scenario you define a goal and you then watch both agents interact where the User Simulator is trying to achieve the goal, and the Task-Oriented Dialogue System is trying to help the User Simulator do so."
137
  )
138
- new_sp_goal_button = gr.Button("Generate Goal")
139
- with gr.Row():
140
- self_play_response = gr.outputs.Chatbot(label="Self-Play Output")
141
- current_sp_goal_yaml = gr.outputs.Textbox(label="Current Goal (YAML)")
142
  self_play_button = gr.Button("Run Next Step")
 
 
 
 
 
 
 
 
143
 
144
  ds_button.click(ds_chatbot, ds_input_text, ds_response)
145
  us_button.click(us_chatbot, us_input_text, us_response)
146
  self_play_button.click(self_play, None, self_play_response)
147
- new_goal_button.click(change_goal, None, current_goal_yaml)
148
- new_sp_goal_button.click(change_sp_goal, None, current_sp_goal_yaml)
 
 
 
149
 
150
  block.launch(share=True)
 
13
  from scripts.user_model_code.interaction import multiwoz_interact
14
  from scripts.UBAR_code.interaction.UBAR_interact import bcolors
15
 
 
16
  # Initialise agents
17
  UBAR_checkpoint_path = "epoch50_trloss0.59_gpt2"
18
  user_model_checkpoint_path = "MultiWOZ-full_checkpoint_step340k"
 
47
  self_play_history = []
48
 
49
 
50
+ def reset_ds_state():
51
+ ds_history.clear()
52
+ sys_model.init_session()
53
+ return ds_history
54
+
55
+
56
+ def reset_us_state():
57
+ us_history.clear()
58
+ user_model.init_session(ini_goal=current_goal)
59
+ return us_history
60
+
61
+
62
+ def reset_self_play_state():
63
+ self_play_history.clear()
64
+ self_play_sys_model.init_session()
65
+ self_play_user_model.init_session(ini_goal=current_goal)
66
+ return self_play_history
67
+
68
+
69
  def change_goal():
70
  global curr_goal_idx
71
  curr_goal_idx = random.randint(0, n_goals - 1)
72
  current_goal = goals[curr_goal_idx]
73
+ us_history = reset_us_state()
74
  current_goal_yaml = yaml.dump(current_goal, default_flow_style=False)
75
+ return current_goal_yaml, us_history
76
 
77
 
78
  def change_sp_goal():
79
  global curr_sp_goal_idx
80
  curr_sp_goal_idx = random.randint(0, n_goals - 1)
81
  current_sp_goal = goals[curr_sp_goal_idx]
82
+ self_play_history = reset_self_play_state()
83
  current_sp_goal_yaml = yaml.dump(current_sp_goal, default_flow_style=False)
84
+ return current_sp_goal_yaml, self_play_history
85
 
86
 
87
  def ds_chatbot(user_utt):
 
105
  else:
106
  sys_response = self_play_history[-1][1]
107
 
108
+ user_utt = self_play_user_model.response(sys_response)
109
 
110
  turn_id = len(self_play_history)
111
+ sys_response = self_play_sys_model.response(user_utt, turn_id)
112
 
113
  self_play_history.append((user_utt, sys_response))
114
 
 
122
  block = gr.Blocks()
123
 
124
  with block:
125
+ gr.Markdown("#πŸ’¬ Jointly Optimized Task-Oriented Dialogue System And User Simulator")
126
+ gr.Markdown(
127
+ "Created by [Alistair McLeay](https://alistairmcleay.com) for the [Masters in Machine Learning & Machine Intelligence at Cambridge University](https://www.mlmi.eng.cam.ac.uk/). <br/>\
128
+ Thank you to [Professor Bill Byrne](https://sites.google.com/view/bill-byrne/home) for his supervision and guidance. <br/> \
129
+ Thank you to [Andy Tseng](https://github.com/andy194673) and [Alex Coca](https://github.com/alexcoca) who provided code and guidance."
130
+ )
131
+ gr.Markdown(
132
+ "*Both Systems are trained on the [MultiWOZ dataset](https://github.com/budzianowski/multiwoz). <br/> \
133
+ Supported domains are 1. πŸš† Train, 2. 🏨 Hotel, 3. πŸš• Taxi, 4. πŸš“ Police, 5. 🏣 Restaurant, 6. πŸ—Ώ Attraction, 7. πŸ₯ Hospital.*"
134
+ )
135
  with gr.Tabs():
136
  with gr.TabItem("Dialogue System"):
137
  gr.Markdown(
138
+ "This bot is a Task-Oriented Dialogue Systen. \nYou are the user. Go ahead and try to book a train, or a hotel etc."
139
  )
140
  with gr.Row():
141
  ds_input_text = gr.inputs.Textbox(
 
143
  )
144
  ds_response = gr.outputs.Chatbot(label="Dialogue System Response")
145
  ds_button = gr.Button("Submit Message")
146
+ reset_ds_button = gr.Button("Reset Conversation")
147
 
148
  with gr.TabItem("User Simulator"):
149
  gr.Markdown(
150
+ "This bot is a User Simulator. \nYou are the Task-Oriented Dialogue System. Your job is to help the user with their requests. \nIf you want the User Simulator to have a different goal press 'Generate New Goal'"
151
  )
 
152
  with gr.Row():
153
  us_input_text = gr.inputs.Textbox(
154
  label="Dialogue System Message", placeholder="How can I help you today?"
155
  )
156
  us_response = gr.outputs.Chatbot(label="User Simulator Response")
 
157
  us_button = gr.Button("Submit Message")
158
+ reset_us_button = gr.Button("Reset Conversation")
159
+ new_goal_button = gr.Button("Generate New Goal")
160
+ current_goal_yaml = gr.outputs.Textbox(label="New Goal (YAML)")
161
 
162
  with gr.TabItem("Self-Play"):
163
  gr.Markdown(
164
+ "In this case both the User Simulator and the Task-Oriented Dialogue System are agents. \nGet them to interact by pressing 'Run Next Step' \nIf you want the User Simulator to have a different goal press 'Generate New Goal'"
165
  )
166
+ self_play_response = gr.outputs.Chatbot(label="Self-Play Output")
 
 
 
167
  self_play_button = gr.Button("Run Next Step")
168
+ reset_self_play_button = gr.Button("Reset Conversation")
169
+ new_sp_goal_button = gr.Button("Generate New Goal")
170
+ current_sp_goal_yaml = gr.outputs.Textbox(label="New Goal (YAML)")
171
+
172
+ gr.Markdown("## System Architecture Overview")
173
+ gr.Markdown(
174
+ "![System Architecture](https://huggingface.co/spaces/alistairmcleay/cambridge-masters-project/tree/main/system_architecture.png)"
175
+ )
176
 
177
  ds_button.click(ds_chatbot, ds_input_text, ds_response)
178
  us_button.click(us_chatbot, us_input_text, us_response)
179
  self_play_button.click(self_play, None, self_play_response)
180
+ new_goal_button.click(change_goal, None, [current_goal_yaml, us_response])
181
+ new_sp_goal_button.click(change_sp_goal, None, [current_sp_goal_yaml, self_play_response])
182
+ reset_ds_button.click(reset_ds_state, None, ds_response)
183
+ reset_us_button.click(reset_us_state, None, us_response)
184
+ reset_self_play_button.click(reset_self_play_state, None, self_play_response)
185
 
186
  block.launch(share=True)