Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,10 +7,9 @@ from huggingface_hub import login
|
|
7 |
# β
Authenticate using HF token stored in secret
|
8 |
login(token=os.environ.get("HUGGINGFACEHUB_API_TOKEN"))
|
9 |
|
10 |
-
# β
|
11 |
summarizer = pipeline("text2text-generation", model="declare-lab/flan-alpaca-base")
|
12 |
|
13 |
-
|
14 |
# β
Highlight matching and find missing keywords
|
15 |
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
|
16 |
|
@@ -30,37 +29,34 @@ def highlight_keywords(resume_text, matched):
|
|
30 |
# π Use LLM to extract missing keywords contextually from JD
|
31 |
def extract_missing_keywords_with_llm(job_desc, resume_text):
|
32 |
prompt = f"""
|
33 |
-
|
34 |
-
|
35 |
-
Given the job description and the resume, identify important skills, tools, and concepts in the job description that are missing or weakly represented in the resume.
|
36 |
-
|
37 |
-
List only the missing or insufficiently addressed keywords in bullet format.
|
38 |
|
39 |
Job Description:
|
40 |
{job_desc}
|
41 |
|
42 |
Resume:
|
43 |
{resume_text}
|
|
|
|
|
44 |
"""
|
45 |
-
result = summarizer(prompt, max_new_tokens=300, do_sample=True
|
46 |
return result.strip()
|
47 |
|
48 |
# π Prompt for dynamic section classification and feedback
|
49 |
def build_dynamic_prompt(job_desc, resume_text, analyze_with_jd):
|
50 |
prompt = f"""
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
60 |
"""
|
61 |
-
if analyze_with_jd and job_desc:
|
62 |
-
prompt += f"\nJob Description:\n{job_desc}\n"
|
63 |
-
prompt += f"\nResume:\n{resume_text}"
|
64 |
return prompt
|
65 |
|
66 |
# π§ Function to call Hugging Face model and get structured resume feedback
|
@@ -71,14 +67,13 @@ def analyze_resume(job_desc, resume_text, analyze_with_jd):
|
|
71 |
user_prompt = build_dynamic_prompt(job_desc, resume_text, analyze_with_jd)
|
72 |
|
73 |
try:
|
74 |
-
response = summarizer(user_prompt, max_new_tokens=
|
75 |
-
cleaned = re.sub(rf".*?{re.escape(resume_text)}", "", response, flags=re.DOTALL).strip()
|
76 |
if analyze_with_jd and job_desc:
|
77 |
matched, _ = compare_keywords(resume_text, job_desc)
|
78 |
highlighted_resume = highlight_keywords(resume_text, matched)
|
79 |
llm_missing_keywords = extract_missing_keywords_with_llm(job_desc, resume_text)
|
80 |
-
return f"### π Resume with Highlighted Matches\n\n{highlighted_resume}\n\n---\n**β
Matched Keywords:** {', '.join(sorted(matched)) or 'None'}\n\n**β LLM-Inferred Missing Keywords:**\n{llm_missing_keywords}\n\n---\n{
|
81 |
-
return
|
82 |
except Exception as e:
|
83 |
return f"β Error: {str(e)}"
|
84 |
|
|
|
7 |
# β
Authenticate using HF token stored in secret
|
8 |
login(token=os.environ.get("HUGGINGFACEHUB_API_TOKEN"))
|
9 |
|
10 |
+
# β
Use a lightweight instruction-tuned model compatible with CPU
|
11 |
summarizer = pipeline("text2text-generation", model="declare-lab/flan-alpaca-base")
|
12 |
|
|
|
13 |
# β
Highlight matching and find missing keywords
|
14 |
from sklearn.feature_extraction.text import ENGLISH_STOP_WORDS
|
15 |
|
|
|
29 |
# π Use LLM to extract missing keywords contextually from JD
|
30 |
def extract_missing_keywords_with_llm(job_desc, resume_text):
|
31 |
prompt = f"""
|
32 |
+
Given the following job description and resume, list the important skills, tools, and concepts from the job description that are missing or weakly represented in the resume.
|
|
|
|
|
|
|
|
|
33 |
|
34 |
Job Description:
|
35 |
{job_desc}
|
36 |
|
37 |
Resume:
|
38 |
{resume_text}
|
39 |
+
|
40 |
+
Only list the missing keywords as bullet points.
|
41 |
"""
|
42 |
+
result = summarizer(prompt, max_new_tokens=300, do_sample=True)[0]['generated_text']
|
43 |
return result.strip()
|
44 |
|
45 |
# π Prompt for dynamic section classification and feedback
|
46 |
def build_dynamic_prompt(job_desc, resume_text, analyze_with_jd):
|
47 |
prompt = f"""
|
48 |
+
Analyze the resume below and organize it into meaningful categories (e.g., Skills, Education, Work Experience, etc.).
|
49 |
+
|
50 |
+
If a job description is provided, compare it against the resume and suggest improvements section by section.
|
51 |
+
|
52 |
+
Job Description:
|
53 |
+
{job_desc if analyze_with_jd else '[None provided]'}
|
54 |
+
|
55 |
+
Resume:
|
56 |
+
{resume_text}
|
57 |
+
|
58 |
+
Return structured Markdown with headers for each section and improvement suggestions.
|
59 |
"""
|
|
|
|
|
|
|
60 |
return prompt
|
61 |
|
62 |
# π§ Function to call Hugging Face model and get structured resume feedback
|
|
|
67 |
user_prompt = build_dynamic_prompt(job_desc, resume_text, analyze_with_jd)
|
68 |
|
69 |
try:
|
70 |
+
response = summarizer(user_prompt, max_new_tokens=512, do_sample=True)[0]['generated_text']
|
|
|
71 |
if analyze_with_jd and job_desc:
|
72 |
matched, _ = compare_keywords(resume_text, job_desc)
|
73 |
highlighted_resume = highlight_keywords(resume_text, matched)
|
74 |
llm_missing_keywords = extract_missing_keywords_with_llm(job_desc, resume_text)
|
75 |
+
return f"### π Resume with Highlighted Matches\n\n{highlighted_resume}\n\n---\n**β
Matched Keywords:** {', '.join(sorted(matched)) or 'None'}\n\n**β LLM-Inferred Missing Keywords:**\n{llm_missing_keywords}\n\n---\n{response.strip()}"
|
76 |
+
return response.strip()
|
77 |
except Exception as e:
|
78 |
return f"β Error: {str(e)}"
|
79 |
|