DreamStream-1 commited on
Commit
ebdf65e
1 Parent(s): 9708aa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -59
app.py CHANGED
@@ -3,7 +3,7 @@ import re
3
  from datetime import datetime
4
  import PyPDF2
5
  import torch
6
- from transformers import AutoTokenizer, AutoModelForSequenceClassification, AutoModelForSeq2SeqLM
7
  from sentence_transformers import SentenceTransformer, util
8
  from groq import Groq
9
  import gradio as gr
@@ -65,59 +65,6 @@ def extract_experience(text):
65
  experience_years = [int(year[0]) for year in experience_years]
66
  return experience_years, job_titles
67
 
68
- # --- Sentiment Analysis --- #
69
- def analyze_sentiment(text):
70
- """Analyzes the sentiment of the text."""
71
- model_name = "mrm8488/distiluse-base-multilingual-cased-v2-finetuned-stsb_multi_mt-es"
72
- tokenizer = AutoTokenizer.from_pretrained(model_name)
73
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
74
-
75
- inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
76
- with torch.no_grad():
77
- outputs = model(**inputs)
78
- predicted_sentiment = torch.argmax(outputs.logits).item()
79
- return ["Negative", "Neutral", "Positive"][predicted_sentiment]
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."""
84
- model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
85
- embeddings1 = model.encode(text1, convert_to_tensor=True)
86
- embeddings2 = model.encode(text2, convert_to_tensor=True)
87
- similarity_score = util.pytorch_cos_sim(embeddings1, embeddings2).item()
88
-
89
- # Convert similarity score to percentage
90
- similarity_percentage = similarity_score * 100
91
- return similarity_percentage
92
-
93
- # --- Communication Generation --- #
94
- def communication_generator(resume_skills, job_description_skills, skills_similarity, qualifications_similarity, experience_similarity, candidate_experience):
95
- """Generates a detailed communication response based on similarity scores and additional criteria."""
96
- # Assess candidate fit based on similarity scores
97
- fit_status = "strong fit" if skills_similarity >= 80 and qualifications_similarity >= 80 and experience_similarity >= 80 else \
98
- "moderate fit" if skills_similarity >= 50 else "weak fit"
99
-
100
- # Build a message that includes a recommendation based on various assessments
101
- if fit_status == "strong fit":
102
- recommendation = "We recommend moving forward with this candidate, as they demonstrate a high level of alignment with the role requirements."
103
- elif fit_status == "moderate fit":
104
- recommendation = "This candidate shows potential; however, further assessment or interviews are recommended to clarify their fit for the role."
105
- else:
106
- recommendation = "We advise against moving forward with this candidate, as they do not meet the key technical requirements for the position."
107
-
108
- message = (
109
- f"After a detailed analysis of the candidate's resume, we found the following insights:\n\n"
110
- f"- **Skills Match**: {skills_similarity:.2f}% (based on required technologies: {', '.join(job_description_skills)})\n"
111
- f"- **Experience Match**: {experience_similarity:.2f}% (relevant experience: {candidate_experience} years)\n"
112
- f"- **Qualifications Match**: {qualifications_similarity:.2f}%\n\n"
113
- f"The overall assessment indicates that the candidate is a {fit_status} for the role. "
114
- f"Their skills in {', '.join(resume_skills)} align with the job's requirements of {', '.join(job_description_skills)}. "
115
- 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"
116
- f"**Recommendation**: {recommendation}\n"
117
- )
118
-
119
- return message
120
-
121
  # --- Updated Resume Analysis Function --- #
122
  def analyze_resume(resume_file, job_description_file):
123
  if not resume_file or not job_description_file:
@@ -192,6 +139,7 @@ def analyze_resume(resume_file, job_description_file):
192
  return summary_message, skills_message, qualifications_message, experience_message
193
 
194
 
 
195
  def run_gradio_interface():
196
  with gr.Blocks() as demo:
197
  gr.Markdown("## Resume and Job Description Analyzer")
@@ -223,14 +171,15 @@ def run_gradio_interface():
223
 
224
  analyze_button = gr.Button("Analyze")
225
 
226
- def analyze(resume, job_desc):
 
 
 
 
 
227
  # Always ensure the correct number of return values
228
  summary, skills, qualifications, experience = analyze_resume(resume, job_desc)
229
  return summary, skills, qualifications, experience
230
 
231
-
232
- demo.launch()
233
-
234
  if __name__ == "__main__":
235
  run_gradio_interface()
236
-
 
3
  from datetime import datetime
4
  import PyPDF2
5
  import torch
6
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
7
  from sentence_transformers import SentenceTransformer, util
8
  from groq import Groq
9
  import gradio as gr
 
65
  experience_years = [int(year[0]) for year in experience_years]
66
  return experience_years, job_titles
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  # --- Updated Resume Analysis Function --- #
69
  def analyze_resume(resume_file, job_description_file):
70
  if not resume_file or not job_description_file:
 
139
  return summary_message, skills_message, qualifications_message, experience_message
140
 
141
 
142
+ # --- Gradio Interface --- #
143
  def run_gradio_interface():
144
  with gr.Blocks() as demo:
145
  gr.Markdown("## Resume and Job Description Analyzer")
 
171
 
172
  analyze_button = gr.Button("Analyze")
173
 
174
+ # Button action
175
+ analyze_button.click(analyze, inputs=[resume_file, job_description_file], outputs=[summary_output, skills_output, qualifications_output, experience_output])
176
+
177
+ demo.launch()
178
+
179
+ def analyze(resume, job_desc):
180
  # Always ensure the correct number of return values
181
  summary, skills, qualifications, experience = analyze_resume(resume, job_desc)
182
  return summary, skills, qualifications, experience
183
 
 
 
 
184
  if __name__ == "__main__":
185
  run_gradio_interface()