ShubhamD95 commited on
Commit
749f56d
Β·
verified Β·
1 Parent(s): 9332f7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -5,16 +5,20 @@ import re
5
  # βœ… Load Hugging Face summarization/chat model
6
  summarizer = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
7
 
8
- # βœ… Highlight matching keywords
9
  from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
10
 
11
- def highlight_keywords(resume_text, job_desc):
12
  resume_words = set(re.findall(r"\b\w{3,}\b", resume_text.lower())) - ENGLISH_STOP_WORDS
13
  job_words = set(re.findall(r"\b\w{3,}\b", job_desc.lower())) - ENGLISH_STOP_WORDS
14
  matched = resume_words & job_words
 
 
 
 
15
  highlighted = resume_text
16
  for word in sorted(matched, key=len, reverse=True):
17
- highlighted = re.sub(rf"\\b({re.escape(word)})\\b", r"**\1**", highlighted, flags=re.IGNORECASE)
18
  return highlighted
19
 
20
  # πŸ” Prompt for dynamic section classification and feedback
@@ -48,8 +52,9 @@ def analyze_resume(job_desc, resume_text, analyze_with_jd):
48
  response = summarizer(user_prompt, max_new_tokens=768, do_sample=True, temperature=0.7)[0]['generated_text']
49
  cleaned = re.sub(rf".*?{re.escape(resume_text)}", "", response, flags=re.DOTALL).strip()
50
  if analyze_with_jd and job_desc:
51
- highlighted_resume = highlight_keywords(resume_text, job_desc)
52
- return f"### πŸ” Resume with Highlighted Matches\n\n{highlighted_resume}\n\n---\n{cleaned}"
 
53
  return cleaned
54
  except Exception as e:
55
  return f"❌ Error: {str(e)}"
 
5
  # βœ… Load Hugging Face summarization/chat model
6
  summarizer = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1")
7
 
8
+ # βœ… Highlight matching and find missing keywords
9
  from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
10
 
11
+ def compare_keywords(resume_text, job_desc):
12
  resume_words = set(re.findall(r"\b\w{3,}\b", resume_text.lower())) - ENGLISH_STOP_WORDS
13
  job_words = set(re.findall(r"\b\w{3,}\b", job_desc.lower())) - ENGLISH_STOP_WORDS
14
  matched = resume_words & job_words
15
+ missing = job_words - resume_words
16
+ return matched, missing
17
+
18
+ def highlight_keywords(resume_text, matched):
19
  highlighted = resume_text
20
  for word in sorted(matched, key=len, reverse=True):
21
+ highlighted = re.sub(rf"\b({re.escape(word)})\b", r"**\1**", highlighted, flags=re.IGNORECASE)
22
  return highlighted
23
 
24
  # πŸ” Prompt for dynamic section classification and feedback
 
52
  response = summarizer(user_prompt, max_new_tokens=768, do_sample=True, temperature=0.7)[0]['generated_text']
53
  cleaned = re.sub(rf".*?{re.escape(resume_text)}", "", response, flags=re.DOTALL).strip()
54
  if analyze_with_jd and job_desc:
55
+ matched, missing = compare_keywords(resume_text, job_desc)
56
+ highlighted_resume = highlight_keywords(resume_text, matched)
57
+ return f"### πŸ” Resume with Highlighted Matches\n\n{highlighted_resume}\n\n---\n**βœ… Matched Keywords:** {', '.join(sorted(matched)) or 'None'}\n\n**❌ Missing Keywords from Resume:** {', '.join(sorted(missing)) or 'None'}\n\n---\n{cleaned}"
58
  return cleaned
59
  except Exception as e:
60
  return f"❌ Error: {str(e)}"