Spaces:
Running
Running
changes made in app.py
Browse files
app.py
CHANGED
@@ -234,20 +234,41 @@ except Exception as e:
|
|
234 |
traceback.print_exc()
|
235 |
|
236 |
def submit_response(response, state):
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
return state["conversation"], state
|
239 |
|
240 |
-
|
|
|
|
|
241 |
state["conversation"].append({"role": "System", "content": "⚠️ Please answer the question before proceeding."})
|
242 |
return state["conversation"], state
|
243 |
|
|
|
244 |
if response.strip().lower() == "exit":
|
|
|
245 |
return end_interview(state)
|
246 |
|
|
|
247 |
state["conversation"].append({"role": "Candidate", "content": response})
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
249 |
rating, suggestion = evaluate_response(response, last_q)
|
250 |
|
|
|
251 |
state["evaluations"].append({
|
252 |
"question": last_q,
|
253 |
"response": response,
|
@@ -256,9 +277,14 @@ def submit_response(response, state):
|
|
256 |
})
|
257 |
|
258 |
state["conversation"].append({"role": "Evaluator", "content": f"Rating: {rating}\nSuggestion: {suggestion}"})
|
|
|
|
|
259 |
prompt = f"Domain: {state['domain']}. Candidate's last response: {response}. Generate a follow-up question:"
|
260 |
follow_up = generate_question(prompt, state["domain"], state)
|
|
|
|
|
261 |
state["conversation"].append({"role": "Interviewer", "content": follow_up})
|
|
|
262 |
return state["conversation"], state
|
263 |
|
264 |
def end_interview(state):
|
|
|
234 |
traceback.print_exc()
|
235 |
|
236 |
def submit_response(response, state):
|
237 |
+
print("Submit Response Called")
|
238 |
+
print("Response:", response)
|
239 |
+
print("Current State:", state)
|
240 |
+
|
241 |
+
# Ensure state is not None and interview is active
|
242 |
+
if state is None:
|
243 |
+
print("State is None, resetting")
|
244 |
+
state = reset_state("", "", "", "Entry-Level")
|
245 |
+
|
246 |
+
if not state.get("interview_active", False):
|
247 |
+
print("Interview not active")
|
248 |
return state["conversation"], state
|
249 |
|
250 |
+
# Handle empty response
|
251 |
+
if not response or not response.strip():
|
252 |
+
print("Empty response")
|
253 |
state["conversation"].append({"role": "System", "content": "⚠️ Please answer the question before proceeding."})
|
254 |
return state["conversation"], state
|
255 |
|
256 |
+
# Exit condition
|
257 |
if response.strip().lower() == "exit":
|
258 |
+
print("Exit requested")
|
259 |
return end_interview(state)
|
260 |
|
261 |
+
# Add candidate response to conversation
|
262 |
state["conversation"].append({"role": "Candidate", "content": response})
|
263 |
+
|
264 |
+
# Find the last interviewer question
|
265 |
+
last_q = next((msg["content"] for msg in reversed(state["conversation"]) if msg["role"] == "Interviewer"), "")
|
266 |
+
|
267 |
+
# Evaluate response
|
268 |
+
print("Evaluating response to question:", last_q)
|
269 |
rating, suggestion = evaluate_response(response, last_q)
|
270 |
|
271 |
+
# Add evaluation to conversation and state
|
272 |
state["evaluations"].append({
|
273 |
"question": last_q,
|
274 |
"response": response,
|
|
|
277 |
})
|
278 |
|
279 |
state["conversation"].append({"role": "Evaluator", "content": f"Rating: {rating}\nSuggestion: {suggestion}"})
|
280 |
+
|
281 |
+
# Generate follow-up question
|
282 |
prompt = f"Domain: {state['domain']}. Candidate's last response: {response}. Generate a follow-up question:"
|
283 |
follow_up = generate_question(prompt, state["domain"], state)
|
284 |
+
|
285 |
+
print("Generated Follow-up Question:", follow_up)
|
286 |
state["conversation"].append({"role": "Interviewer", "content": follow_up})
|
287 |
+
|
288 |
return state["conversation"], state
|
289 |
|
290 |
def end_interview(state):
|