Spaces:
Running
Running
Update app.py
Browse files
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
|
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"
|
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 |
-
|
52 |
-
|
|
|
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)}"
|