DreamStream-1 commited on
Commit
83dc51e
1 Parent(s): 66f7872

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -49
app.py CHANGED
@@ -51,8 +51,6 @@ def extract_skills_llama(text):
51
  # --- Job Description Processing Function --- #
52
  def process_job_description(text):
53
  """Extracts skills or relevant keywords from the job description."""
54
- # You can customize this function as needed, for now, we'll use a basic extraction
55
- # Using the Llama model or a simple regex-based approach for demonstration
56
  return extract_skills_llama(text)
57
 
58
  # --- Qualification and Experience Extraction --- #
@@ -91,33 +89,32 @@ def categorize_similarity(score):
91
  return "Low Match"
92
 
93
  # --- Communication Generation with Enhanced Response --- #
94
- def communication_generator(resume_skills, job_description_skills, skills_similarity, qualifications_similarity, experience_similarity, max_length=200):
95
- """Generates a more detailed communication response based on similarity scores."""
96
- model_name = "google/flan-t5-base"
97
- tokenizer = AutoTokenizer.from_pretrained(model_name)
98
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
99
-
100
  # Assess candidate fit based on similarity scores
101
  fit_status = "strong fit" if skills_similarity >= 80 and qualifications_similarity >= 80 and experience_similarity >= 80 else \
102
  "moderate fit" if skills_similarity >= 50 else "weak fit"
103
 
104
- # Create a detailed communication message based on match levels
 
 
 
 
 
 
 
105
  message = (
106
  f"After a detailed analysis of the candidate's resume, we found the following insights:\n\n"
107
- f"- **Skills Match**: {skills_similarity:.2f}% ({categorize_similarity(skills_similarity)})\n"
108
- f"- **Qualifications Match**: {qualifications_similarity:.2f}% ({categorize_similarity(qualifications_similarity)})\n"
109
- f"- **Experience Match**: {experience_similarity:.2f}% ({categorize_similarity(experience_similarity)})\n\n"
110
  f"The overall assessment indicates that the candidate is a {fit_status} for the role. "
111
- f"Skills such as {', '.join(resume_skills)} align {categorize_similarity(skills_similarity).lower()} with the job's requirements of {', '.join(job_description_skills)}. "
112
- f"In terms of qualifications and experience, the candidate shows a {categorize_similarity(qualifications_similarity).lower()} match with the role's needs. "
113
- f"Based on these findings, we believe the candidate could potentially excel in the role, "
114
- f"but additional evaluation or interviews are recommended for further clarification."
115
  )
116
 
117
- inputs = tokenizer(message, return_tensors="pt", padding=True, truncation=True)
118
- response = model.generate(**inputs, max_length=max_length, num_beams=4, early_stopping=True)
119
-
120
- return tokenizer.decode(response[0], skip_special_tokens=True)
121
 
122
  # --- Sentiment Analysis --- #
123
  def sentiment_analysis(text):
@@ -155,10 +152,14 @@ def analyze_resume(resume_file, job_description_file):
155
  qualifications_similarity = calculate_semantic_similarity(' '.join(resume_qualifications), ' '.join(job_description_qualifications))
156
  experience_similarity = calculate_semantic_similarity(' '.join([str(e) for e in resume_experience]), ' '.join([str(e) for e in job_description_experience]))
157
 
 
 
 
158
  # Generate a communication response based on the similarity percentages
159
  communication_response = communication_generator(
160
  resume_skills, job_description_skills,
161
- skills_similarity, qualifications_similarity, experience_similarity
 
162
  )
163
 
164
  # Perform Sentiment Analysis
@@ -175,34 +176,19 @@ def analyze_resume(resume_file, job_description_file):
175
  f"Job Description Skills: {', '.join(job_description_skills)}",
176
  f"Resume Qualifications: {', '.join(resume_qualifications)}",
177
  f"Job Description Qualifications: {', '.join(job_description_qualifications)}",
178
- f"Resume Experience: {', '.join([str(e) for e in resume_experience])}",
179
- f"Job Description Experience: {', '.join([str(e) for e in job_description_experience])}"
180
  )
181
 
182
  # --- Gradio Interface --- #
183
- def main():
184
- """Runs the Gradio application for resume analysis."""
185
- interface = gr.Interface(
186
- fn=analyze_resume,
187
- inputs=[gr.File(label="Upload Resume (PDF/TXT)"), gr.File(label="Upload Job Description (PDF/TXT)")],
188
- outputs=[
189
- gr.Textbox(label="Skills Similarity"),
190
- gr.Textbox(label="Qualifications Similarity"),
191
- gr.Textbox(label="Experience Similarity"),
192
- gr.Textbox(label="Communication Response"),
193
- gr.Textbox(label="Sentiment Analysis"),
194
- gr.Textbox(label="Resume Skills"),
195
- gr.Textbox(label="Job Description Skills"),
196
- gr.Textbox(label="Resume Qualifications"),
197
- gr.Textbox(label="Job Description Qualifications"),
198
- gr.Textbox(label="Resume Experience"),
199
- gr.Textbox(label="Job Description Experience")
200
- ],
201
- title="Resume and Job Description Analysis",
202
- description="Analyze a resume against a job description to evaluate skills, qualifications, experience, and generate communication insights."
203
- )
204
-
205
- interface.launch()
206
-
207
- if __name__ == "__main__":
208
- main()
 
51
  # --- Job Description Processing Function --- #
52
  def process_job_description(text):
53
  """Extracts skills or relevant keywords from the job description."""
 
 
54
  return extract_skills_llama(text)
55
 
56
  # --- Qualification and Experience Extraction --- #
 
89
  return "Low Match"
90
 
91
  # --- Communication Generation with Enhanced Response --- #
92
+ def communication_generator(resume_skills, job_description_skills, skills_similarity, qualifications_similarity, experience_similarity, candidate_experience):
93
+ """Generates a detailed communication response based on similarity scores and additional criteria."""
 
 
 
 
94
  # Assess candidate fit based on similarity scores
95
  fit_status = "strong fit" if skills_similarity >= 80 and qualifications_similarity >= 80 and experience_similarity >= 80 else \
96
  "moderate fit" if skills_similarity >= 50 else "weak fit"
97
 
98
+ # Build a message that includes a recommendation based on various assessments
99
+ if fit_status == "strong fit":
100
+ recommendation = "We recommend moving forward with this candidate, as they demonstrate a high level of alignment with the role requirements."
101
+ elif fit_status == "moderate fit":
102
+ recommendation = "This candidate shows potential; however, further assessment or interviews are recommended to clarify their fit for the role."
103
+ else:
104
+ recommendation = "We advise against moving forward with this candidate, as they do not meet the key technical requirements for the position."
105
+
106
  message = (
107
  f"After a detailed analysis of the candidate's resume, we found the following insights:\n\n"
108
+ f"- **Skills Match**: {skills_similarity:.2f}% (based on required technologies: {', '.join(job_description_skills)})\n"
109
+ f"- **Experience Match**: {experience_similarity:.2f}% (relevant experience: {candidate_experience} years)\n"
110
+ f"- **Qualifications Match**: {qualifications_similarity:.2f}%\n\n"
111
  f"The overall assessment indicates that the candidate is a {fit_status} for the role. "
112
+ f"Their skills in {', '.join(resume_skills)} align with the job's requirements of {', '.join(job_description_skills)}. "
113
+ f"Based on their experience in web application development, particularly with technologies like {', '.join(resume_skills)}, they could contribute effectively to our team.\n\n"
114
+ f"**Recommendation**: {recommendation}\n"
 
115
  )
116
 
117
+ return message
 
 
 
118
 
119
  # --- Sentiment Analysis --- #
120
  def sentiment_analysis(text):
 
152
  qualifications_similarity = calculate_semantic_similarity(' '.join(resume_qualifications), ' '.join(job_description_qualifications))
153
  experience_similarity = calculate_semantic_similarity(' '.join([str(e) for e in resume_experience]), ' '.join([str(e) for e in job_description_experience]))
154
 
155
+ # Assuming candidate experience is extracted from the resume
156
+ candidate_experience = sum(resume_experience) # Calculate total experience based on extracted years
157
+
158
  # Generate a communication response based on the similarity percentages
159
  communication_response = communication_generator(
160
  resume_skills, job_description_skills,
161
+ skills_similarity, qualifications_similarity, experience_similarity,
162
+ candidate_experience
163
  )
164
 
165
  # Perform Sentiment Analysis
 
176
  f"Job Description Skills: {', '.join(job_description_skills)}",
177
  f"Resume Qualifications: {', '.join(resume_qualifications)}",
178
  f"Job Description Qualifications: {', '.join(job_description_qualifications)}",
179
+ f"Candidate Experience: {candidate_experience} years"
 
180
  )
181
 
182
  # --- Gradio Interface --- #
183
+ with gr.Blocks() as demo:
184
+ gr.Markdown("## Resume and Job Description Analyzer")
185
+ with gr.Row():
186
+ resume_file_input = gr.File(label="Upload Resume (PDF/TXT)", type="file")
187
+ job_description_file_input = gr.File(label="Upload Job Description (PDF/TXT)", type="file")
188
+ analyze_button = gr.Button("Analyze")
189
+ results_output = gr.Output()
190
+
191
+ analyze_button.click(analyze_resume, inputs=[resume_file_input, job_description_file_input], outputs=results_output)
192
+
193
+ # Launch Gradio Interface
194
+ demo.launch()