Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,15 +43,7 @@ def load_models():
|
|
43 |
truncation=True
|
44 |
)
|
45 |
|
46 |
-
#
|
47 |
-
models['evaluator'] = pipeline(
|
48 |
-
"text2text-generation",
|
49 |
-
model="google-t5/t5-small",
|
50 |
-
max_length=200,
|
51 |
-
num_beams=2,
|
52 |
-
early_stopping=True
|
53 |
-
)
|
54 |
-
|
55 |
return models
|
56 |
|
57 |
# Preload models immediately when app starts
|
@@ -397,7 +389,7 @@ def calculate_google_match_score(candidate_summary):
|
|
397 |
#####################################
|
398 |
def generate_template_feedback(category_scores):
|
399 |
"""
|
400 |
-
Generate comprehensive template-based feedback without using ML model for speed.
|
401 |
"""
|
402 |
start_time = time.time()
|
403 |
|
@@ -504,53 +496,6 @@ def generate_template_feedback(category_scores):
|
|
504 |
|
505 |
return feedback, execution_time
|
506 |
|
507 |
-
#####################################
|
508 |
-
# Function: Generate Aspect-Based Feedback with T5 - Enhanced with Fallback
|
509 |
-
#####################################
|
510 |
-
@st.cache_data(show_spinner=False)
|
511 |
-
def generate_aspect_feedback(candidate_summary, category_scores, _evaluator=None):
|
512 |
-
"""
|
513 |
-
Use T5-small model to generate feedback with robust fallback to template-based feedback.
|
514 |
-
"""
|
515 |
-
start_time = time.time()
|
516 |
-
|
517 |
-
evaluator = _evaluator or models['evaluator']
|
518 |
-
|
519 |
-
# Sort categories by score
|
520 |
-
sorted_categories = sorted(category_scores.items(), key=lambda x: x[1], reverse=True)
|
521 |
-
top_categories = sorted_categories[:2]
|
522 |
-
bottom_categories = sorted_categories[-2:]
|
523 |
-
|
524 |
-
# Create a more explicit prompt for T5
|
525 |
-
prompt = f"""
|
526 |
-
Generate a complete paragraph evaluating a job candidate for Google.
|
527 |
-
The candidate is strong in: {', '.join([cat for cat, _ in top_categories])}.
|
528 |
-
The candidate needs improvement in: {', '.join([cat for cat, _ in bottom_categories])}.
|
529 |
-
Start with 'This candidate' and write at least 3 sentences about their fit for Google.
|
530 |
-
"""
|
531 |
-
|
532 |
-
# Generate focused feedback with error handling
|
533 |
-
try:
|
534 |
-
feedback_result = evaluator(prompt, max_length=200, do_sample=False)
|
535 |
-
feedback = feedback_result[0]['generated_text']
|
536 |
-
|
537 |
-
# Validate the response - ensure it's not empty or too short
|
538 |
-
if len(feedback.strip()) < 20 or feedback.strip() == "This candidate" or feedback.strip() == "This candidate.":
|
539 |
-
# Fall back to template-based if T5 output is too short
|
540 |
-
return generate_template_feedback(category_scores)
|
541 |
-
|
542 |
-
# Ensure third-person tone
|
543 |
-
if not any(feedback.lower().startswith(start) for start in ["the candidate", "this candidate"]):
|
544 |
-
feedback = f"This candidate {feedback}"
|
545 |
-
except Exception as e:
|
546 |
-
# Fall back to template if there's an error
|
547 |
-
print(f"Error generating T5 feedback: {e}")
|
548 |
-
return generate_template_feedback(category_scores)
|
549 |
-
|
550 |
-
execution_time = time.time() - start_time
|
551 |
-
|
552 |
-
return feedback, execution_time
|
553 |
-
|
554 |
#####################################
|
555 |
# Main Streamlit Interface - with Progress Reporting
|
556 |
#####################################
|
@@ -571,10 +516,6 @@ with st.expander("Google's Requirements", expanded=False):
|
|
571 |
# File uploader
|
572 |
uploaded_file = st.file_uploader("Upload your resume (.docx, .doc, or .txt)", type=["docx", "doc", "txt"])
|
573 |
|
574 |
-
# Add a checkbox for template-based feedback (faster)
|
575 |
-
use_template_feedback = st.checkbox("Use faster template-based feedback (no ML)", value=False,
|
576 |
-
help="Generate feedback using pre-defined templates instead of T5 model")
|
577 |
-
|
578 |
# Process button with optimized flow
|
579 |
if uploaded_file is not None and st.button("Analyze My Google Fit"):
|
580 |
# Create a placeholder for the progress bar
|
@@ -603,13 +544,8 @@ if uploaded_file is not None and st.button("Analyze My Google Fit"):
|
|
603 |
status_text.text("Step 3/3: Calculating Google fit scores...")
|
604 |
overall_score, category_scores, score_breakdown = calculate_google_match_score(summary)
|
605 |
|
606 |
-
#
|
607 |
-
|
608 |
-
feedback, feedback_time = generate_template_feedback(category_scores)
|
609 |
-
else:
|
610 |
-
feedback, feedback_time = generate_aspect_feedback(
|
611 |
-
summary, category_scores, _evaluator=models['evaluator']
|
612 |
-
)
|
613 |
|
614 |
progress_bar.progress(100)
|
615 |
|
|
|
43 |
truncation=True
|
44 |
)
|
45 |
|
46 |
+
# We don't need T5 model anymore since we're using template-based feedback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
return models
|
48 |
|
49 |
# Preload models immediately when app starts
|
|
|
389 |
#####################################
|
390 |
def generate_template_feedback(category_scores):
|
391 |
"""
|
392 |
+
Generate comprehensive template-based feedback without using ML model for speed and reliability.
|
393 |
"""
|
394 |
start_time = time.time()
|
395 |
|
|
|
496 |
|
497 |
return feedback, execution_time
|
498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
#####################################
|
500 |
# Main Streamlit Interface - with Progress Reporting
|
501 |
#####################################
|
|
|
516 |
# File uploader
|
517 |
uploaded_file = st.file_uploader("Upload your resume (.docx, .doc, or .txt)", type=["docx", "doc", "txt"])
|
518 |
|
|
|
|
|
|
|
|
|
519 |
# Process button with optimized flow
|
520 |
if uploaded_file is not None and st.button("Analyze My Google Fit"):
|
521 |
# Create a placeholder for the progress bar
|
|
|
544 |
status_text.text("Step 3/3: Calculating Google fit scores...")
|
545 |
overall_score, category_scores, score_breakdown = calculate_google_match_score(summary)
|
546 |
|
547 |
+
# Always use template-based feedback (more reliable)
|
548 |
+
feedback, feedback_time = generate_template_feedback(category_scores)
|
|
|
|
|
|
|
|
|
|
|
549 |
|
550 |
progress_bar.progress(100)
|
551 |
|