barbara-multimodal commited on
Commit
3cab104
·
1 Parent(s): cc1b7e0

feat: Add ideal answer

Browse files
Files changed (1) hide show
  1. app.py +78 -27
app.py CHANGED
@@ -11,6 +11,7 @@ from constants import JOB_DESCRIPTION, RESUME_TEXT
11
  API_KEY = os.getenv("API_KEY")
12
  CONVERSATIONAL_MODEL_API_ENDPOINT = "https://talent-interview-prep-conversational-model.multimodal.dev/"
13
  QUESTION_RELATED_FEEDBACK_API_ENDPOINT = "https://talent-interview-prep-question-related-feedback.multimodal.dev/"
 
14
  CONVERSATIONAL_MODEL_FEEDBACK_API_ENDPOINT = "https://talent-interview-prep-conversation-feedback.multimodal.dev/"
15
 
16
  # Predefined questions
@@ -33,6 +34,8 @@ first_question_selected = False
33
 
34
  current_turns = 0
35
 
 
 
36
  def chatbot_api_call(interview_question, user_input, conversation_mode, conversation_turns_limit, include_company_name, include_resume_text):
37
  global session_id
38
  print(f"Calling API with session_id: {session_id}")
@@ -81,7 +84,7 @@ def remove_html_tags(text):
81
  cleaned_text = soup.get_text().strip('"').replace('\\"', '"')
82
  return cleaned_text
83
 
84
- def question_related_feedback_api_call(interview_conversation, feedback_type="standard"):
85
  headers = {
86
  "x-api-key": API_KEY,
87
  "Content-Type": "application/json"
@@ -89,7 +92,7 @@ def question_related_feedback_api_call(interview_conversation, feedback_type="st
89
 
90
  data = {
91
  "job_title": "Senior Product Manager",
92
- "interview_conversation": interview_conversation,
93
  "feedback_type": feedback_type
94
  }
95
 
@@ -105,7 +108,31 @@ def question_related_feedback_api_call(interview_conversation, feedback_type="st
105
  print(f"Error: {str(e)}")
106
  return "Error: Unable to reach the API or invalid response received."
107
 
108
- def conversational_model_feedback_api_call(interview_conversation, feedback_type="standard"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  headers = {
110
  "x-api-key": API_KEY,
111
  "Content-Type": "application/json"
@@ -113,7 +140,7 @@ def conversational_model_feedback_api_call(interview_conversation, feedback_type
113
 
114
  data = {
115
  "job_title": "Senior Product Manager",
116
- "interview_conversation": interview_conversation,
117
  "feedback_type": feedback_type
118
  }
119
 
@@ -137,9 +164,10 @@ def enable_send_button(message, selected_question):
137
  return gr.update(interactive=False), gr.update(label="Choose an interview question (Required)")
138
 
139
  def handle_question_change(history, selected_question, conversation_mode):
140
- global session_id, first_question_selected, current_turns
141
 
142
  current_turns = 0
 
143
 
144
  if conversation_mode == 'Interviewer':
145
  updated_label = f"Conversation turns: {current_turns}"
@@ -169,10 +197,11 @@ def handle_question_change(history, selected_question, conversation_mode):
169
  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
170
 
171
  def reset_interface(conversation_mode):
172
- global session_id, first_question_selected, current_turns
173
 
174
  first_question_selected = False
175
  current_turns = 0
 
176
 
177
  if conversation_mode == "Interviewer":
178
  # chatbot_label = "Multimodal Interviewer Agent"
@@ -221,15 +250,6 @@ def create_demo():
221
  with gr.Blocks() as demo:
222
  gr.Markdown("# Talent Interview Prep - Conversational Model")
223
 
224
- # gr.Markdown("**Some details**")
225
- # gr.Markdown("""
226
- # - Job title: Senior Product Manager
227
- # - Fictional company name: InnovateTech Solutions
228
- # - Fictional job description [here](<link>)
229
- # - Fictional candidate resume [here](<link>)
230
- # - The questions are predefined and generated previously
231
- # """)
232
-
233
  gr.Markdown("""### Please select a conversation mode to begin""")
234
 
235
  with gr.Row():
@@ -267,7 +287,7 @@ def create_demo():
267
  question_dropdown.change(fn=handle_question_change, inputs=[chatbot, question_dropdown, conversation_mode], outputs=[chatbot, send_btn, msg, chatbot, feedback_box])
268
 
269
  def respond(message, history, conversation_mode, selected_question, conversation_turns_limit, feedback_type, include_company_name, include_resume_text):
270
- global current_turns
271
 
272
  feedback = ""
273
 
@@ -278,23 +298,54 @@ def create_demo():
278
 
279
  bot_message, conversation_end_flag, chat_memory = chatbot_api_call(clean_question, message, conversation_mode, conversation_turns_limit, include_company_name, include_resume_text)
280
 
281
- print(f"Conversation end? {conversation_end_flag}")
282
  print(f"{chat_memory=}\n")
283
 
284
- if conversation_mode == 'Interviewer':
285
- current_turns += 1
286
- updated_label = f"Conversation turns: {current_turns}"
287
- feedback = f"{current_turns}º conversation turn feedback\n\n{remove_html_tags(question_related_feedback_api_call(chat_memory['messages'][:-1], feedback_type.lower())).strip()}"
288
- else:
289
- updated_label = "Multimodal Coach Agent"
290
 
291
  if conversation_end_flag:
292
  if conversation_mode == 'Interviewer':
293
- feedback = f"Whole conversation feedback\n\n{remove_html_tags(conversational_model_feedback_api_call(chat_memory['messages'], feedback_type.lower())).strip()}"
 
 
 
 
 
 
 
 
 
 
 
294
 
295
- return history + [(message, bot_message)], "", gr.update(interactive=False), gr.update(interactive=False), gr.update(label=updated_label), feedback
296
- else:
297
- return history + [(message, bot_message)], "", gr.update(interactive=True), gr.update(interactive=True), gr.update(label=updated_label), feedback
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
 
299
  conversation_mode.change(fn=reset_interface, inputs=conversation_mode, outputs=[chatbot, question_dropdown, msg, send_btn, conversation_turns_limit, feedback_box, feedback_type_dropdown])
300
 
 
11
  API_KEY = os.getenv("API_KEY")
12
  CONVERSATIONAL_MODEL_API_ENDPOINT = "https://talent-interview-prep-conversational-model.multimodal.dev/"
13
  QUESTION_RELATED_FEEDBACK_API_ENDPOINT = "https://talent-interview-prep-question-related-feedback.multimodal.dev/"
14
+ QUESTION_RELATED_IDEAL_ANSWER_API_ENDPOINT = "https://talent-interview-prep-question-related-ideal-answer.multimodal.dev/"
15
  CONVERSATIONAL_MODEL_FEEDBACK_API_ENDPOINT = "https://talent-interview-prep-conversation-feedback.multimodal.dev/"
16
 
17
  # Predefined questions
 
34
 
35
  current_turns = 0
36
 
37
+ interview_data_with_feedback = []
38
+
39
  def chatbot_api_call(interview_question, user_input, conversation_mode, conversation_turns_limit, include_company_name, include_resume_text):
40
  global session_id
41
  print(f"Calling API with session_id: {session_id}")
 
84
  cleaned_text = soup.get_text().strip('"').replace('\\"', '"')
85
  return cleaned_text
86
 
87
+ def question_related_feedback_api_call(interview_data, feedback_type="standard"):
88
  headers = {
89
  "x-api-key": API_KEY,
90
  "Content-Type": "application/json"
 
92
 
93
  data = {
94
  "job_title": "Senior Product Manager",
95
+ "interview_data": interview_data,
96
  "feedback_type": feedback_type
97
  }
98
 
 
108
  print(f"Error: {str(e)}")
109
  return "Error: Unable to reach the API or invalid response received."
110
 
111
+ def question_related_ideal_answer_api_call(interview_data_with_feedback, feedback_type="standard"):
112
+ headers = {
113
+ "x-api-key": API_KEY,
114
+ "Content-Type": "application/json"
115
+ }
116
+
117
+ data = {
118
+ "job_title": "Senior Product Manager",
119
+ "interview_data_with_feedback": interview_data_with_feedback,
120
+ "feedback_type": feedback_type
121
+ }
122
+
123
+ try:
124
+ response = requests.post(QUESTION_RELATED_IDEAL_ANSWER_API_ENDPOINT, headers=headers, json=data)
125
+
126
+ if response.status_code == 200:
127
+ return response.text
128
+ else:
129
+ return f"Error: Received status code {response.status_code} from the API"
130
+
131
+ except Exception as e:
132
+ print(f"Error: {str(e)}")
133
+ return "Error: Unable to reach the API or invalid response received."
134
+
135
+ def conversational_model_feedback_api_call(interview_data, feedback_type="standard"):
136
  headers = {
137
  "x-api-key": API_KEY,
138
  "Content-Type": "application/json"
 
140
 
141
  data = {
142
  "job_title": "Senior Product Manager",
143
+ "interview_data": interview_data,
144
  "feedback_type": feedback_type
145
  }
146
 
 
164
  return gr.update(interactive=False), gr.update(label="Choose an interview question (Required)")
165
 
166
  def handle_question_change(history, selected_question, conversation_mode):
167
+ global session_id, first_question_selected, current_turns, interview_data_with_feedback
168
 
169
  current_turns = 0
170
+ interview_data_with_feedback = []
171
 
172
  if conversation_mode == 'Interviewer':
173
  updated_label = f"Conversation turns: {current_turns}"
 
197
  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
198
 
199
  def reset_interface(conversation_mode):
200
+ global session_id, first_question_selected, current_turns, interview_data_with_feedback
201
 
202
  first_question_selected = False
203
  current_turns = 0
204
+ interview_data_with_feedback = []
205
 
206
  if conversation_mode == "Interviewer":
207
  # chatbot_label = "Multimodal Interviewer Agent"
 
250
  with gr.Blocks() as demo:
251
  gr.Markdown("# Talent Interview Prep - Conversational Model")
252
 
 
 
 
 
 
 
 
 
 
253
  gr.Markdown("""### Please select a conversation mode to begin""")
254
 
255
  with gr.Row():
 
287
  question_dropdown.change(fn=handle_question_change, inputs=[chatbot, question_dropdown, conversation_mode], outputs=[chatbot, send_btn, msg, chatbot, feedback_box])
288
 
289
  def respond(message, history, conversation_mode, selected_question, conversation_turns_limit, feedback_type, include_company_name, include_resume_text):
290
+ global current_turns, interview_data_with_feedback
291
 
292
  feedback = ""
293
 
 
298
 
299
  bot_message, conversation_end_flag, chat_memory = chatbot_api_call(clean_question, message, conversation_mode, conversation_turns_limit, include_company_name, include_resume_text)
300
 
301
+ print(f"Conversation end? {conversation_end_flag}\n")
302
  print(f"{chat_memory=}\n")
303
 
304
+ updated_label = f"Conversation turns: {current_turns}" if conversation_mode == 'Interviewer' else "Multimodal Coach Agent"
 
 
 
 
 
305
 
306
  if conversation_end_flag:
307
  if conversation_mode == 'Interviewer':
308
+ feedback = (
309
+ f"Whole conversation feedback\n\n"
310
+ f"{remove_html_tags(conversational_model_feedback_api_call(chat_memory['messages'], feedback_type.lower())).strip()}"
311
+ )
312
+ return (
313
+ history + [(message, bot_message)],
314
+ "",
315
+ gr.update(interactive=False),
316
+ gr.update(interactive=False),
317
+ gr.update(label=updated_label),
318
+ feedback,
319
+ )
320
 
321
+ if conversation_mode == 'Interviewer':
322
+ current_turns += 1
323
+ interview_data = chat_memory['messages'][:-1]
324
+
325
+ raw_feedback = question_related_feedback_api_call(interview_data, feedback_type.lower())
326
+ feedback = f"{current_turns}º conversation turn feedback{remove_html_tags(raw_feedback).strip()}"
327
+
328
+ interview_data_with_feedback.extend(interview_data)
329
+ interview_data_with_feedback.append({"type": "feedback", "content": raw_feedback})
330
+
331
+ print(f"{interview_data_with_feedback=}\n")
332
+
333
+ ideal_answer = question_related_ideal_answer_api_call(interview_data_with_feedback, feedback_type.lower())
334
+
335
+ bot_message += f"\n\n---"
336
+ bot_message += f"\n**Ideal answer:**"
337
+ bot_message += f"\n>{ideal_answer}"
338
+
339
+ updated_label = f"Conversation turns: {current_turns}" if conversation_mode == 'Interviewer' else "Multimodal Coach Agent"
340
+
341
+ return (
342
+ history + [(message, bot_message)],
343
+ "",
344
+ gr.update(interactive=True),
345
+ gr.update(interactive=True),
346
+ gr.update(label=updated_label),
347
+ feedback,
348
+ )
349
 
350
  conversation_mode.change(fn=reset_interface, inputs=conversation_mode, outputs=[chatbot, question_dropdown, msg, send_btn, conversation_turns_limit, feedback_box, feedback_type_dropdown])
351