barbara-multimodal commited on
Commit
fe22d3a
·
1 Parent(s): 08c9450

feat: Add new API endpoints for conversation feedback and update UI text for clarity

Browse files
Files changed (1) hide show
  1. app.py +37 -8
app.py CHANGED
@@ -9,8 +9,9 @@ from bs4 import BeautifulSoup
9
  from constants import JOB_DESCRIPTION, RESUME_TEXT
10
 
11
  API_KEY = os.getenv("API_KEY")
12
- CHATBOT_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
 
15
  # Predefined questions
16
  questions = {
@@ -57,7 +58,7 @@ def chatbot_api_call(interview_question, user_input, conversation_mode, conversa
57
  data["resume_text"] = RESUME_TEXT
58
 
59
  try:
60
- response = requests.post(CHATBOT_API_ENDPOINT, headers=headers, json=data)
61
 
62
  if response.status_code == 200:
63
  json_response = response.json()
@@ -98,6 +99,30 @@ def question_related_feedback_api_call(interview_conversation, feedback_type="st
98
  except Exception as e:
99
  print(f"Error: {str(e)}")
100
  return "Error: Unable to reach the API or invalid response received."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  def enable_send_button(message, selected_question):
103
  if selected_question and message.strip():
@@ -113,7 +138,7 @@ def handle_question_change(history, selected_question, conversation_mode):
113
 
114
  if conversation_mode == 'Interviewer':
115
  updated_label = f"Conversation turns: {current_turns}"
116
- feedback_box_state = gr.update(interactive=False, placeholder="If the conversation is not complete, feedback for each turn will be displayed here", value="")
117
 
118
  else:
119
  updated_label = "Multimodal Coach Agent"
@@ -157,7 +182,7 @@ def reset_interface(conversation_mode):
157
  )
158
  slider_state = gr.update(interactive=True)
159
 
160
- feedback_box_state = gr.update(interactive=False, placeholder="If the conversation is not complete, feedback for each turn will be displayed here", value="")
161
  feedback_type_state = gr.update(interactive=True, value="Standard")
162
 
163
  else:
@@ -226,7 +251,7 @@ def create_demo():
226
  )
227
 
228
  chatbot = gr.Chatbot(label="""The Multimodal Chatbot will be ready once you select a mode""")
229
- feedback_box = gr.Textbox(label="Conversation turn feedback", placeholder="If the conversation is not complete, feedback for each turn will be displayed here", interactive=False)
230
 
231
  msg = gr.Textbox(label="Type your answer here")
232
  send_btn = gr.Button(value="Send", variant="primary", interactive=False)
@@ -239,6 +264,8 @@ def create_demo():
239
  def respond(message, history, conversation_mode, selected_question, conversation_turns_limit, feedback_type, include_company_name, include_resume_text):
240
  global current_turns
241
 
 
 
242
  if not message.strip():
243
  return history, message
244
 
@@ -252,13 +279,15 @@ def create_demo():
252
  if conversation_mode == 'Interviewer':
253
  current_turns += 1
254
  updated_label = f"Conversation turns: {current_turns}"
255
- feedback = remove_html_tags(question_related_feedback_api_call(chat_memory['messages'][:-1], feedback_type.lower())).strip()
256
  else:
257
  updated_label = "Multimodal Coach Agent"
258
- feedback = ""
259
 
260
  if conversation_end_flag:
261
- return history + [(message, bot_message)], "", gr.update(interactive=False), gr.update(interactive=False), gr.update(label=updated_label), ""
 
 
 
262
  else:
263
  return history + [(message, bot_message)], "", gr.update(interactive=True), gr.update(interactive=True), gr.update(label=updated_label), feedback
264
 
 
9
  from constants import JOB_DESCRIPTION, RESUME_TEXT
10
 
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
17
  questions = {
 
58
  data["resume_text"] = RESUME_TEXT
59
 
60
  try:
61
+ response = requests.post(CONVERSATIONAL_MODEL_API_ENDPOINT, headers=headers, json=data)
62
 
63
  if response.status_code == 200:
64
  json_response = response.json()
 
99
  except Exception as e:
100
  print(f"Error: {str(e)}")
101
  return "Error: Unable to reach the API or invalid response received."
102
+
103
+ def conversational_model_feedback_api_call(interview_conversation, feedback_type="standard"):
104
+ headers = {
105
+ "x-api-key": API_KEY,
106
+ "Content-Type": "application/json"
107
+ }
108
+
109
+ data = {
110
+ "job_title": "Senior Product Manager",
111
+ "interview_conversation": interview_conversation,
112
+ "feedback_type": feedback_type
113
+ }
114
+
115
+ try:
116
+ response = requests.post(CONVERSATIONAL_MODEL_FEEDBACK_API_ENDPOINT, headers=headers, json=data)
117
+
118
+ if response.status_code == 200:
119
+ return response.text
120
+ else:
121
+ return f"Error: Received status code {response.status_code} from the API"
122
+
123
+ except Exception as e:
124
+ print(f"Error: {str(e)}")
125
+ return "Error: Unable to reach the API or invalid response received."
126
 
127
  def enable_send_button(message, selected_question):
128
  if selected_question and message.strip():
 
138
 
139
  if conversation_mode == 'Interviewer':
140
  updated_label = f"Conversation turns: {current_turns}"
141
+ 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="")
142
 
143
  else:
144
  updated_label = "Multimodal Coach Agent"
 
182
  )
183
  slider_state = gr.update(interactive=True)
184
 
185
+ 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="")
186
  feedback_type_state = gr.update(interactive=True, value="Standard")
187
 
188
  else:
 
251
  )
252
 
253
  chatbot = gr.Chatbot(label="""The Multimodal Chatbot will be ready once you select a mode""")
254
+ 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)
255
 
256
  msg = gr.Textbox(label="Type your answer here")
257
  send_btn = gr.Button(value="Send", variant="primary", interactive=False)
 
264
  def respond(message, history, conversation_mode, selected_question, conversation_turns_limit, feedback_type, include_company_name, include_resume_text):
265
  global current_turns
266
 
267
+ feedback = ""
268
+
269
  if not message.strip():
270
  return history, message
271
 
 
279
  if conversation_mode == 'Interviewer':
280
  current_turns += 1
281
  updated_label = f"Conversation turns: {current_turns}"
282
+ 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()}"
283
  else:
284
  updated_label = "Multimodal Coach Agent"
 
285
 
286
  if conversation_end_flag:
287
+ if conversation_mode == 'Interviewer':
288
+ feedback = f"Whole conversation feedback\n\n{remove_html_tags(conversational_model_feedback_api_call(chat_memory['messages'], feedback_type.lower())).strip()}"
289
+
290
+ return history + [(message, bot_message)], "", gr.update(interactive=False), gr.update(interactive=False), gr.update(label=updated_label), feedback
291
  else:
292
  return history + [(message, bot_message)], "", gr.update(interactive=True), gr.update(interactive=True), gr.update(label=updated_label), feedback
293