Update app.py
Browse files
app.py
CHANGED
|
@@ -404,69 +404,100 @@ def generate_evaluation_report(metrics_data, average_rating, feedback_list, inte
|
|
| 404 |
|
| 405 |
# --- Gradio UI Components and Logic (Interview) ---
|
| 406 |
|
|
|
|
| 407 |
def process_resume(file_obj):
|
| 408 |
"""Handles resume upload and processing."""
|
|
|
|
| 409 |
if not file_obj:
|
| 410 |
-
# Return exactly 13 values
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
return (
|
| 412 |
-
"Please upload a PDF resume.",
|
| 413 |
-
gr.update(visible=False),
|
| 414 |
-
gr.update(visible=False),
|
| 415 |
-
gr.update(visible=False),
|
| 416 |
-
gr.update(visible=False),
|
| 417 |
-
gr.update(visible=False),
|
| 418 |
-
gr.update(visible=False),
|
| 419 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
)
|
| 421 |
|
| 422 |
try:
|
|
|
|
| 423 |
if hasattr(file_obj, 'name'):
|
| 424 |
file_path = file_obj.name
|
| 425 |
else:
|
|
|
|
| 426 |
file_path = str(file_obj)
|
|
|
|
| 427 |
|
| 428 |
-
|
|
|
|
|
|
|
| 429 |
if not raw_text or not raw_text.strip():
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
"Could not extract text from the PDF.",
|
| 433 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 434 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 435 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 436 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 437 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 438 |
-
gr.update(visible=False), gr.update(visible=False)
|
| 439 |
-
# 13 values
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
#
|
| 444 |
-
|
|
|
|
|
|
|
|
|
|
| 445 |
return (
|
| 446 |
-
f"File processed successfully!",
|
| 447 |
-
gr.update(visible=True),
|
| 448 |
-
gr.update(visible=
|
| 449 |
-
gr.update(visible=False),
|
| 450 |
-
gr.update(visible=False),
|
| 451 |
-
gr.update(visible=False),
|
| 452 |
-
|
| 453 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
)
|
| 455 |
except Exception as e:
|
| 456 |
error_msg = f"Error processing file: {str(e)}"
|
| 457 |
-
print(error_msg)
|
|
|
|
|
|
|
| 458 |
# Ensure exactly 13 values are returned even on error
|
| 459 |
return (
|
| 460 |
-
error_msg,
|
| 461 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 462 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 463 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 464 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 465 |
-
gr.update(visible=False), gr.update(visible=False),
|
| 466 |
-
gr.update(visible=False), gr.update(visible=False)
|
| 467 |
-
# 13 values
|
| 468 |
)
|
| 469 |
|
|
|
|
| 470 |
def start_interview(roles, processed_resume_data):
|
| 471 |
"""Starts the interview process."""
|
| 472 |
if not roles or (isinstance(roles, list) and not any(roles)) or not processed_resume_data or not processed_resume_data.strip():
|
|
|
|
| 404 |
|
| 405 |
# --- Gradio UI Components and Logic (Interview) ---
|
| 406 |
|
| 407 |
+
|
| 408 |
def process_resume(file_obj):
|
| 409 |
"""Handles resume upload and processing."""
|
| 410 |
+
print(f"process_resume called with: {file_obj}") # Debug print
|
| 411 |
if not file_obj:
|
| 412 |
+
# Return exactly 13 values to match the outputs list
|
| 413 |
+
# [file_status_interview, role_selection, start_interview_btn,
|
| 414 |
+
# question_display, answer_instructions, audio_input,
|
| 415 |
+
# submit_answer_btn, next_question_btn, submit_interview_btn,
|
| 416 |
+
# answer_display, feedback_display, metrics_display,
|
| 417 |
+
# processed_resume_data_hidden_interview]
|
| 418 |
+
print("No file uploaded.")
|
| 419 |
return (
|
| 420 |
+
"Please upload a PDF resume.", # file_status_interview
|
| 421 |
+
gr.update(visible=False), # role_selection
|
| 422 |
+
gr.update(visible=False), # start_interview_btn
|
| 423 |
+
gr.update(visible=False), # question_display
|
| 424 |
+
gr.update(visible=False), # answer_instructions
|
| 425 |
+
gr.update(visible=False), # audio_input
|
| 426 |
+
gr.update(visible=False), # submit_answer_btn
|
| 427 |
+
gr.update(visible=False), # next_question_btn
|
| 428 |
+
gr.update(visible=False), # submit_interview_btn
|
| 429 |
+
gr.update(visible=False), # answer_display
|
| 430 |
+
gr.update(visible=False), # feedback_display
|
| 431 |
+
gr.update(visible=False), # metrics_display
|
| 432 |
+
gr.update(visible=False) # processed_resume_data_hidden_interview
|
| 433 |
+
# Total: 13 values
|
| 434 |
)
|
| 435 |
|
| 436 |
try:
|
| 437 |
+
# --- Correctly handle the file path from Gradio ---
|
| 438 |
if hasattr(file_obj, 'name'):
|
| 439 |
file_path = file_obj.name
|
| 440 |
else:
|
| 441 |
+
# Fallback if it's somehow a direct path string (less likely)
|
| 442 |
file_path = str(file_obj)
|
| 443 |
+
print(f"File path to process: {file_path}")
|
| 444 |
|
| 445 |
+
# --- Process the PDF ---
|
| 446 |
+
raw_text = file_processing(file_path) # Use the path
|
| 447 |
+
print(f"Raw text extracted (length: {len(raw_text) if raw_text else 0})")
|
| 448 |
if not raw_text or not raw_text.strip():
|
| 449 |
+
print("Failed to extract text or text is empty.")
|
| 450 |
+
return (
|
| 451 |
+
"Could not extract text from the PDF.", # file_status_interview
|
| 452 |
+
gr.update(visible=False), gr.update(visible=False), # role_selection, start_interview_btn
|
| 453 |
+
gr.update(visible=False), gr.update(visible=False), # question_display, answer_instructions
|
| 454 |
+
gr.update(visible=False), gr.update(visible=False), # audio_input, submit_answer_btn
|
| 455 |
+
gr.update(visible=False), gr.update(visible=False), # next_question_btn, submit_interview_btn
|
| 456 |
+
gr.update(visible=False), gr.update(visible=False), # answer_display, feedback_display
|
| 457 |
+
gr.update(visible=False), gr.update(visible=False) # metrics_display, processed_resume_data_hidden_interview
|
| 458 |
+
# Total: 13 values
|
| 459 |
+
)
|
| 460 |
+
|
| 461 |
+
# --- Format the resume data ---
|
| 462 |
+
processed_data = getallinfo(raw_text) # Use the new model instance if corrected
|
| 463 |
+
print(f"Resume processed (length: {len(processed_data) if processed_data else 0})")
|
| 464 |
+
|
| 465 |
+
# --- Return success state and values ---
|
| 466 |
+
# Make sure to return the processed_data as the LAST value
|
| 467 |
return (
|
| 468 |
+
f"File processed successfully!", # file_status_interview
|
| 469 |
+
gr.update(visible=True), # role_selection (make visible)
|
| 470 |
+
gr.update(visible=True), # start_interview_btn (make visible)
|
| 471 |
+
gr.update(visible=False), # question_display (initially hidden)
|
| 472 |
+
gr.update(visible=False), # answer_instructions (initially hidden)
|
| 473 |
+
gr.update(visible=False), # audio_input (initially hidden)
|
| 474 |
+
gr.update(visible=False), # submit_answer_btn (initially hidden)
|
| 475 |
+
gr.update(visible=False), # next_question_btn (initially hidden)
|
| 476 |
+
gr.update(visible=False), # submit_interview_btn (initially hidden)
|
| 477 |
+
gr.update(visible=False), # answer_display (initially hidden)
|
| 478 |
+
gr.update(visible=False), # feedback_display (initially hidden)
|
| 479 |
+
gr.update(visible=False), # metrics_display (initially hidden)
|
| 480 |
+
processed_data # processed_resume_data_hidden_interview (pass the data!)
|
| 481 |
+
# Total: 13 values
|
| 482 |
)
|
| 483 |
except Exception as e:
|
| 484 |
error_msg = f"Error processing file: {str(e)}"
|
| 485 |
+
print(f"Exception in process_resume: {error_msg}")
|
| 486 |
+
import traceback
|
| 487 |
+
traceback.print_exc() # Print full traceback for debugging
|
| 488 |
# Ensure exactly 13 values are returned even on error
|
| 489 |
return (
|
| 490 |
+
error_msg, # file_status_interview
|
| 491 |
+
gr.update(visible=False), gr.update(visible=False), # role_selection, start_interview_btn
|
| 492 |
+
gr.update(visible=False), gr.update(visible=False), # question_display, answer_instructions
|
| 493 |
+
gr.update(visible=False), gr.update(visible=False), # audio_input, submit_answer_btn
|
| 494 |
+
gr.update(visible=False), gr.update(visible=False), # next_question_btn, submit_interview_btn
|
| 495 |
+
gr.update(visible=False), gr.update(visible=False), # answer_display, feedback_display
|
| 496 |
+
gr.update(visible=False), gr.update(visible=False) # metrics_display, processed_resume_data_hidden_interview
|
| 497 |
+
# Total: 13 values
|
| 498 |
)
|
| 499 |
|
| 500 |
+
|
| 501 |
def start_interview(roles, processed_resume_data):
|
| 502 |
"""Starts the interview process."""
|
| 503 |
if not roles or (isinstance(roles, list) and not any(roles)) or not processed_resume_data or not processed_resume_data.strip():
|