DreamStream-1 commited on
Commit
2481da5
1 Parent(s): 83dc51e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -22
app.py CHANGED
@@ -66,6 +66,18 @@ def extract_experience(text):
66
  experience_years = [int(year[0]) for year in experience_years]
67
  return experience_years, job_titles
68
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  # --- Semantic Similarity Calculation --- #
70
  def calculate_semantic_similarity(text1, text2):
71
  """Calculates semantic similarity using a sentence transformer model and returns the score as a percentage."""
@@ -147,37 +159,37 @@ def analyze_resume(resume_file, job_description_file):
147
  resume_experience, resume_job_titles = extract_experience(resume_text)
148
  job_description_experience, job_description_titles = extract_experience(job_description_text)
149
 
 
 
 
 
150
  # Calculate semantic similarity for different sections in percentages
151
  skills_similarity = calculate_semantic_similarity(' '.join(resume_skills), ' '.join(job_description_skills))
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
166
- sentiment = sentiment_analysis(resume_text)
167
-
168
- # Return the results including thresholds and percentage scores
169
- return (
170
- f"Skills Similarity: {skills_similarity:.2f}% ({categorize_similarity(skills_similarity)})",
171
- f"Qualifications Similarity: {qualifications_similarity:.2f}% ({categorize_similarity(qualifications_similarity)})",
172
- f"Experience Similarity: {experience_similarity:.2f}% ({categorize_similarity(experience_similarity)})",
173
- communication_response,
174
- f"Sentiment Analysis: {sentiment}",
175
- f"Resume Skills: {', '.join(resume_skills)}",
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:
 
66
  experience_years = [int(year[0]) for year in experience_years]
67
  return experience_years, job_titles
68
 
69
+ # --- Summarization Function --- #
70
+ def summarize_experience(experience_text):
71
+ """Summarizes the experience text using a pre-trained model."""
72
+ model_name = "facebook/bart-large-cnn"
73
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
74
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
75
+
76
+ inputs = tokenizer(experience_text, return_tensors="pt", max_length=1024, truncation=True)
77
+ summary_ids = model.generate(inputs['input_ids'], max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
78
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
79
+ return summary
80
+
81
  # --- Semantic Similarity Calculation --- #
82
  def calculate_semantic_similarity(text1, text2):
83
  """Calculates semantic similarity using a sentence transformer model and returns the score as a percentage."""
 
159
  resume_experience, resume_job_titles = extract_experience(resume_text)
160
  job_description_experience, job_description_titles = extract_experience(job_description_text)
161
 
162
+ # Summarize experiences
163
+ resume_experience_summary = summarize_experience(resume_text)
164
+ job_description_experience_summary = summarize_experience(job_description_text)
165
+
166
  # Calculate semantic similarity for different sections in percentages
167
  skills_similarity = calculate_semantic_similarity(' '.join(resume_skills), ' '.join(job_description_skills))
168
  qualifications_similarity = calculate_semantic_similarity(' '.join(resume_qualifications), ' '.join(job_description_qualifications))
169
  experience_similarity = calculate_semantic_similarity(' '.join([str(e) for e in resume_experience]), ' '.join([str(e) for e in job_description_experience]))
170
 
171
+ # Assuming candidate experience is the total of years from the resume
172
+ candidate_experience = sum(resume_experience)
173
 
174
+ # Generate communication based on analysis
175
+ response_message = communication_generator(
176
+ resume_skills,
177
+ job_description_skills,
178
+ skills_similarity,
179
+ qualifications_similarity,
180
+ experience_similarity,
181
  candidate_experience
182
  )
183
 
184
+ return {
185
+ "Resume Experience Summary": resume_experience_summary,
186
+ "Job Description Experience Summary": job_description_experience_summary,
187
+ "Skills Similarity": skills_similarity,
188
+ "Qualifications Similarity": qualifications_similarity,
189
+ "Experience Similarity": experience_similarity,
190
+ "Candidate Experience": candidate_experience,
191
+ "Response Message": response_message,
192
+ }
 
 
 
 
 
 
 
193
 
194
  # --- Gradio Interface --- #
195
  with gr.Blocks() as demo: