barbara-multimodal commited on
Commit
72af144
·
1 Parent(s): 7b91819

feat: Update feedback handling to use highlighted text with categories

Browse files
Files changed (2) hide show
  1. app.py +45 -21
  2. src/api_calls.py +5 -2
app.py CHANGED
@@ -1,4 +1,3 @@
1
- import re
2
  import gradio as gr
3
 
4
  from src.constants import FULL_QUESTIONS
@@ -25,11 +24,11 @@ def handle_question_change(history, selected_question, conversation_mode):
25
 
26
  if conversation_mode == 'Interviewer':
27
  updated_label = f"Conversation turns: {current_turns}"
28
- feedback_box_state = gr.update(interactive=False, placeholder="Feedback for each conversation turn, as well as an overall feedback for the entire conversation, will be displayed here", value="")
29
 
30
  else:
31
  updated_label = "Multimodal Coach Agent"
32
- feedback_box_state = gr.update(interactive=False, placeholder="Coach mode does not provide feedback", value="")
33
 
34
  if len(history) > 1:
35
  first_question_selected = True
@@ -39,7 +38,7 @@ def handle_question_change(history, selected_question, conversation_mode):
39
 
40
  transition_message = f"Alright, let's move on to the next question:\n\n{selected_question}"
41
 
42
- return [("I'm ready for the next question now.", transition_message)], gr.update(interactive=False), gr.update(interactive=True), gr.update(label=updated_label), feedback_box_state
43
  else:
44
  if selected_question:
45
  last_question = f"Great start! Here's your first question:\n\n{selected_question}"
@@ -48,7 +47,7 @@ def handle_question_change(history, selected_question, conversation_mode):
48
 
49
  new_history = history + [("One moment...", last_question)]
50
 
51
- return [entry for entry in new_history if entry[1] is not None], gr.update(interactive=False), gr.update(interactive=True), gr.update(label=updated_label), feedback_box_state
52
 
53
  def reset_interface(conversation_mode):
54
  global session_id, first_question_selected, current_turns, interview_data_with_feedback
@@ -69,9 +68,8 @@ def reset_interface(conversation_mode):
69
  )
70
  slider_state = gr.update(interactive=True)
71
 
72
- feedback_box_state = gr.update(interactive=False, placeholder="Feedback for each conversation turn, as well as an overall feedback for the entire conversation, will be displayed here", value="")
73
  feedback_type_state = gr.update(interactive=True, value="Standard")
74
-
75
  else:
76
  chatbot_label = "Multimodal Coach Agent"
77
  session_id = generate_session_id()
@@ -85,7 +83,7 @@ def reset_interface(conversation_mode):
85
  )
86
  slider_state = gr.update(interactive=False)
87
 
88
- feedback_box_state = gr.update(interactive=False, placeholder="Coach mode does not provide feedback", value="")
89
  feedback_type_state = gr.update(interactive=False, value=" ")
90
 
91
  return (
@@ -94,10 +92,15 @@ def reset_interface(conversation_mode):
94
  "",
95
  gr.update(value="Send", interactive=False),
96
  slider_state,
97
- feedback_box_state,
98
  feedback_type_state
99
  )
100
 
 
 
 
 
 
101
  # Gradio interface
102
  def create_demo():
103
  with gr.Blocks() as demo:
@@ -127,9 +130,15 @@ def create_demo():
127
  interactive=False,
128
  allow_custom_value=True
129
  )
130
-
131
  chatbot = gr.Chatbot(label="""The Multimodal Chatbot will be ready once you select a mode""")
132
- feedback_box = gr.Textbox(label="Conversation feedback", placeholder="Feedback for each conversation turn, as well as an overall feedback for the entire conversation, will be displayed here", interactive=False)
 
 
 
 
 
 
133
 
134
  msg = gr.Textbox(label="Type your answer here")
135
  send_btn = gr.Button(value="Send", variant="primary", interactive=False)
@@ -142,7 +151,8 @@ def create_demo():
142
  def respond(message, history, conversation_mode, selected_question, conversation_turns_limit, feedback_type, include_company_name, include_resume_text):
143
  global session_id, current_turns, interview_data_with_feedback
144
 
145
- feedback = ""
 
146
 
147
  if not message.strip():
148
  return history, message
@@ -158,17 +168,22 @@ def create_demo():
158
 
159
  if conversation_end_flag:
160
  if conversation_mode == 'Interviewer':
161
- feedback = (
162
- f"Whole conversation feedback\n\n"
163
- f"{remove_html_tags(conversation_feedback_api_call(chat_memory['messages'], feedback_type.lower(), include_resume_text)).strip()}"
164
- )
 
 
 
 
 
165
  return (
166
  history + [(message, bot_message)],
167
  "",
168
  gr.update(interactive=False),
169
  gr.update(interactive=False),
170
  gr.update(label=updated_label),
171
- feedback,
172
  )
173
 
174
  if conversation_mode == 'Interviewer':
@@ -176,11 +191,20 @@ def create_demo():
176
  interview_data = chat_memory['messages'][:-1]
177
  print(f"{interview_data=}\n")
178
 
179
- raw_feedback = feedback_api_call(interview_data, feedback_type.lower(), include_resume_text)
180
- feedback = f"{current_turns}º conversation turn feedback\n\n{remove_html_tags(raw_feedback).strip()}"
 
 
 
 
 
 
 
 
 
181
 
182
  interview_data_with_feedback.extend(interview_data)
183
- interview_data_with_feedback.append({"type": "feedback", "content": raw_feedback})
184
 
185
  print(f"{interview_data_with_feedback=}\n")
186
 
@@ -201,7 +225,7 @@ def create_demo():
201
  gr.update(interactive=True),
202
  gr.update(interactive=True),
203
  gr.update(label=updated_label),
204
- feedback,
205
  )
206
 
207
  conversation_mode.change(fn=reset_interface, inputs=conversation_mode, outputs=[chatbot, question_dropdown, msg, send_btn, conversation_turns_limit, feedback_box, feedback_type_dropdown])
 
 
1
  import gradio as gr
2
 
3
  from src.constants import FULL_QUESTIONS
 
24
 
25
  if conversation_mode == 'Interviewer':
26
  updated_label = f"Conversation turns: {current_turns}"
27
+ feedback_box = gr.update(value=None)
28
 
29
  else:
30
  updated_label = "Multimodal Coach Agent"
31
+ feedback_box = gr.update(value=None, show_legend=False)
32
 
33
  if len(history) > 1:
34
  first_question_selected = True
 
38
 
39
  transition_message = f"Alright, let's move on to the next question:\n\n{selected_question}"
40
 
41
+ return [("I'm ready for the next question now.", transition_message)], gr.update(interactive=False), gr.update(interactive=True), gr.update(label=updated_label), feedback_box
42
  else:
43
  if selected_question:
44
  last_question = f"Great start! Here's your first question:\n\n{selected_question}"
 
47
 
48
  new_history = history + [("One moment...", last_question)]
49
 
50
+ return [entry for entry in new_history if entry[1] is not None], gr.update(interactive=False), gr.update(interactive=True), gr.update(label=updated_label), feedback_box
51
 
52
  def reset_interface(conversation_mode):
53
  global session_id, first_question_selected, current_turns, interview_data_with_feedback
 
68
  )
69
  slider_state = gr.update(interactive=True)
70
 
71
+ feedback_box = gr.update(value=None)
72
  feedback_type_state = gr.update(interactive=True, value="Standard")
 
73
  else:
74
  chatbot_label = "Multimodal Coach Agent"
75
  session_id = generate_session_id()
 
83
  )
84
  slider_state = gr.update(interactive=False)
85
 
86
+ feedback_box = gr.update(value=None, show_legend=False)
87
  feedback_type_state = gr.update(interactive=False, value=" ")
88
 
89
  return (
 
92
  "",
93
  gr.update(value="Send", interactive=False),
94
  slider_state,
95
+ feedback_box,
96
  feedback_type_state
97
  )
98
 
99
+ def highlight_feedback(feedback_output):
100
+ if not feedback_output["feedback_by_category"]:
101
+ return False, [(feedback_output["feedback_text"], None)]
102
+ return True, [(item["text"], item["category"]) for item in feedback_output["feedback_by_category"]]
103
+
104
  # Gradio interface
105
  def create_demo():
106
  with gr.Blocks() as demo:
 
130
  interactive=False,
131
  allow_custom_value=True
132
  )
133
+
134
  chatbot = gr.Chatbot(label="""The Multimodal Chatbot will be ready once you select a mode""")
135
+ # feedback_box = gr.Textbox(label="Conversation feedback", placeholder="Feedback for each conversation turn, as well as an overall feedback for the entire conversation, will be displayed here", interactive=False)
136
+
137
+ feedback_box = gr.HighlightedText(
138
+ label="Conversation feedback",
139
+ show_legend=True,
140
+ color_map={"Strength": "green", "Area for Improvement": "orange", "Action Item": "blue"}
141
+ )
142
 
143
  msg = gr.Textbox(label="Type your answer here")
144
  send_btn = gr.Button(value="Send", variant="primary", interactive=False)
 
151
  def respond(message, history, conversation_mode, selected_question, conversation_turns_limit, feedback_type, include_company_name, include_resume_text):
152
  global session_id, current_turns, interview_data_with_feedback
153
 
154
+ feedback_value = None
155
+ feedback_show_legend = False
156
 
157
  if not message.strip():
158
  return history, message
 
168
 
169
  if conversation_end_flag:
170
  if conversation_mode == 'Interviewer':
171
+ feedback_output = conversation_feedback_api_call(chat_memory['messages'], feedback_type.lower(), include_resume_text)
172
+
173
+ feedback_show_legend, highlighted_feedback = highlight_feedback(feedback_output)
174
+ feedback_value = [("Whole conversation feedback\n\n", None)] + highlighted_feedback
175
+
176
+ print()
177
+ print(feedback_output)
178
+ print()
179
+ print(highlighted_feedback)
180
  return (
181
  history + [(message, bot_message)],
182
  "",
183
  gr.update(interactive=False),
184
  gr.update(interactive=False),
185
  gr.update(label=updated_label),
186
+ gr.update(value=feedback_value, show_legend=feedback_show_legend)
187
  )
188
 
189
  if conversation_mode == 'Interviewer':
 
191
  interview_data = chat_memory['messages'][:-1]
192
  print(f"{interview_data=}\n")
193
 
194
+ feedback_output = feedback_api_call(interview_data, feedback_type.lower(), include_resume_text)
195
+
196
+ feedback_show_legend, highlighted_feedback = highlight_feedback(feedback_output)
197
+ feedback_value = [(f"{current_turns}º conversation turn feedback\n\n", None)] + highlighted_feedback
198
+
199
+ print()
200
+ print(feedback_output)
201
+ print()
202
+ print(highlighted_feedback)
203
+
204
+ # feedback = f"{current_turns}º conversation turn feedback\n\n{remove_html_tags(feedback_output).strip()}"
205
 
206
  interview_data_with_feedback.extend(interview_data)
207
+ interview_data_with_feedback.append({"type": "feedback", "content": feedback_output["feedback_text"]})
208
 
209
  print(f"{interview_data_with_feedback=}\n")
210
 
 
225
  gr.update(interactive=True),
226
  gr.update(interactive=True),
227
  gr.update(label=updated_label),
228
+ gr.update(value=feedback_value, show_legend=feedback_show_legend)
229
  )
230
 
231
  conversation_mode.change(fn=reset_interface, inputs=conversation_mode, outputs=[chatbot, question_dropdown, msg, send_btn, conversation_turns_limit, feedback_box, feedback_type_dropdown])
src/api_calls.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from .constants import (
2
  JOB_DESCRIPTION,
3
  RESUME_TEXT
@@ -51,7 +53,8 @@ def feedback_api_call(interview_data, feedback_type, include_resume_text):
51
  response = api_call(QUESTION_RELATED_FEEDBACK_API_ENDPOINT, data)
52
 
53
  if response.status_code == 200:
54
- return response.text
 
55
  else:
56
  return f"Error: Received status code {response.status_code} from the API"
57
 
@@ -85,6 +88,6 @@ def conversation_feedback_api_call(interview_data, feedback_type, include_resume
85
  response = api_call(CONVERSATIONAL_MODEL_FEEDBACK_API_ENDPOINT, data)
86
 
87
  if response.status_code == 200:
88
- return response.text
89
  else:
90
  return f"Error: Received status code {response.status_code} from the API"
 
1
+ import json
2
+
3
  from .constants import (
4
  JOB_DESCRIPTION,
5
  RESUME_TEXT
 
53
  response = api_call(QUESTION_RELATED_FEEDBACK_API_ENDPOINT, data)
54
 
55
  if response.status_code == 200:
56
+ print(response.text)
57
+ return json.loads(response.text)
58
  else:
59
  return f"Error: Received status code {response.status_code} from the API"
60
 
 
88
  response = api_call(CONVERSATIONAL_MODEL_FEEDBACK_API_ENDPOINT, data)
89
 
90
  if response.status_code == 200:
91
+ return json.loads(response.text)
92
  else:
93
  return f"Error: Received status code {response.status_code} from the API"