DreamStream-1 commited on
Commit
597bbca
·
verified ·
1 Parent(s): ff5a4e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -59
app.py CHANGED
@@ -133,78 +133,76 @@ def analyze_sentiment(text):
133
 
134
  # --- Updated Resume Analysis Function --- #
135
  def analyze_resume(resume_file, job_description_file):
136
- """Analyzes the resume and job description for skills, qualifications, and experience."""
137
  # Load and preprocess resume and job description
138
  resume_text = extract_text_from_file(resume_file)
139
  job_description_text = extract_text_from_file(job_description_file)
140
 
141
- # Extract skills, qualifications, and experience
142
  resume_skills = extract_skills_llama(resume_text)
143
- job_description_skills = process_job_description(job_description_text)
144
  resume_qualifications = extract_qualifications(resume_text)
 
 
 
 
 
145
  job_description_qualifications = extract_qualifications(job_description_text)
146
- resume_experience, resume_job_titles = extract_experience(resume_text)
147
- job_description_experience, job_description_titles = extract_experience(job_description_text)
148
-
149
- # Calculate semantic similarity for different sections in percentages
150
- skills_similarity = calculate_semantic_similarity(' '.join(resume_skills), ' '.join(job_description_skills))
151
- qualifications_similarity = calculate_semantic_similarity(' '.join(resume_qualifications), ' '.join(job_description_qualifications))
152
- experience_similarity = calculate_semantic_similarity(' '.join([str(e) for e in resume_experience]), ' '.join([str(e) for e in job_description_experience]))
153
-
154
- # Assuming candidate experience is the total of years from the resume
155
- candidate_experience = sum(resume_experience)
156
-
157
- # Generate communication based on analysis
158
- response_message = communication_generator(
159
- resume_skills,
160
- job_description_skills,
161
- skills_similarity,
162
- qualifications_similarity,
163
- experience_similarity,
164
- candidate_experience
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  )
166
 
167
- # Analyze sentiment for the resume
168
- sentiment = analyze_sentiment(resume_text)
169
 
170
- return {
171
- "skills_similarity": skills_similarity,
172
- "qualifications_similarity": qualifications_similarity,
173
- "experience_similarity": experience_similarity,
174
- "response_message": response_message,
175
- "sentiment": sentiment,
176
- "candidate_experience": candidate_experience
177
- }
178
-
179
- # --- Gradio Interface --- #
180
- # --- Gradio Interface --- #
181
  def run_gradio_interface():
182
- """Runs the Gradio app interface."""
183
  with gr.Blocks() as demo:
184
- gr.Markdown("# Resume Analyzer")
185
- with gr.Row():
186
- resume_file_input = gr.File(label="Upload Resume (PDF/TXT)")
187
- job_description_file_input = gr.File(label="Upload Job Description (PDF/TXT)")
188
- analyze_button = gr.Button("Analyze Resume")
189
-
190
- # Change output_display to gr.Markdown for displaying the analysis results
191
- output_display = gr.Markdown("### Analysis Results will be displayed here")
192
-
193
- def analyze_callback(resume_file, job_description_file):
194
- analysis_results = analyze_resume(resume_file, job_description_file)
195
- return (
196
- f"**Skills Similarity**: {analysis_results['skills_similarity']:.2f}%\n"
197
- f"**Qualifications Similarity**: {analysis_results['qualifications_similarity']:.2f}%\n"
198
- f"**Experience Similarity**: {analysis_results['experience_similarity']:.2f}%\n"
199
- f"**Candidate Experience**: {analysis_results['candidate_experience']} years\n"
200
- f"**Sentiment**: {analysis_results['sentiment']}\n"
201
- f"**Response Message**:\n{analysis_results['response_message']}"
202
- )
203
-
204
- analyze_button.click(analyze_callback, inputs=[resume_file_input, job_description_file_input], outputs=output_display)
205
 
206
- demo.launch()
 
 
 
207
 
 
 
 
 
208
 
209
  if __name__ == "__main__":
210
- run_gradio_interface()
 
133
 
134
  # --- Updated Resume Analysis Function --- #
135
  def analyze_resume(resume_file, job_description_file):
 
136
  # Load and preprocess resume and job description
137
  resume_text = extract_text_from_file(resume_file)
138
  job_description_text = extract_text_from_file(job_description_file)
139
 
140
+ # Extract skills, qualifications, and experience from the resume
141
  resume_skills = extract_skills_llama(resume_text)
 
142
  resume_qualifications = extract_qualifications(resume_text)
143
+ resume_experience, _ = extract_experience(resume_text)
144
+ total_experience = sum(resume_experience) # Assuming this returns a list of experiences
145
+
146
+ # Extract required skills, qualifications, and experience from the job description
147
+ job_description_skills = process_job_description(job_description_text)
148
  job_description_qualifications = extract_qualifications(job_description_text)
149
+ job_description_experience, _ = extract_experience(job_description_text)
150
+ required_experience = sum(job_description_experience) # Assuming total years required
151
+
152
+ # Calculate similarity scores
153
+ skills_similarity = len(set(resume_skills).intersection(set(job_description_skills))) / len(job_description_skills) * 100
154
+ qualifications_similarity = len(set(resume_qualifications).intersection(set(job_description_qualifications))) / len(job_description_qualifications) * 100
155
+ experience_similarity = 1.0 if total_experience >= required_experience else 0.0
156
+
157
+ # Fit assessment logic
158
+ fit_score = 0
159
+ if total_experience >= required_experience:
160
+ fit_score += 1
161
+ if skills_similarity > 50: # Define a threshold for skills match
162
+ fit_score += 1
163
+ if qualifications_similarity > 50: # Define a threshold for qualifications match
164
+ fit_score += 1
165
+
166
+ # Determine fit
167
+ if fit_score == 3:
168
+ fit_assessment = "Strong fit"
169
+ elif fit_score == 2:
170
+ fit_assessment = "Moderate fit"
171
+ else:
172
+ fit_assessment = "Not a fit"
173
+
174
+ # Prepare output message
175
+ response_message = (
176
+ f"Skills Similarity: {skills_similarity:.2f}%\n"
177
+ f"Qualifications Similarity: {qualifications_similarity:.2f}%\n"
178
+ f"Experience Similarity: {experience_similarity * 100:.2f}%\n"
179
+ f"Candidate Experience: {total_experience} years\n"
180
+ f"Sentiment: Neutral\n"
181
+ f"Response Message: After a detailed analysis of the candidate's resume, we found the following insights:\n\n"
182
+ f"Skills Match: {skills_similarity:.2f}% (based on required technologies: {', '.join(job_description_skills)})\n"
183
+ f"Qualifications Match: {qualifications_similarity:.2f}%\n"
184
+ f"Experience Match: {experience_similarity * 100:.2f}% (relevant experience: {total_experience} years)\n"
185
+ f"The overall assessment indicates that the candidate is a {fit_assessment} for the role."
186
  )
187
 
188
+ return response_message
 
189
 
 
 
 
 
 
 
 
 
 
 
 
190
  def run_gradio_interface():
 
191
  with gr.Blocks() as demo:
192
+ gr.Markdown("## Resume and Job Description Analyzer")
193
+ resume_file = gr.File(label="Upload Resume")
194
+ job_description_file = gr.File(label="Upload Job Description")
195
+ output_display = gr.Textbox(label="Analysis Output", interactive=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
 
197
+ def analyze(resume, job_desc):
198
+ if resume and job_desc:
199
+ return analyze_resume(resume, job_desc)
200
+ return "Please upload both files."
201
 
202
+ analyze_button = gr.Button("Analyze")
203
+ analyze_button.click(analyze, inputs=[resume_file, job_description_file], outputs=output_display)
204
+
205
+ demo.launch()
206
 
207
  if __name__ == "__main__":
208
+ run_gradio_interface()