ShubhamD95 commited on
Commit
fc823d8
Β·
verified Β·
1 Parent(s): 1221d76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -24
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
- # βœ… Load Hugging Face summarization/chat model
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
- You are an expert resume evaluator.
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, temperature=0.7)[0]['generated_text']
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
- You are an expert resume analyst.
52
- Classify the content of the resume into meaningful categories based on the text (e.g., Technical Skills, Soft Skills, Certifications, Projects, Work Experience, Education, Personal Information).
53
- You do not need a fixed list of section namesβ€”choose the most suitable ones based on the content.
54
- Then:
55
- - For each section, summarize its contents.
56
- - If a job description is provided, compare each section against it.
57
- - Highlight missing or weak areas relevant to the job.
58
- - Provide smart, actionable suggestions to improve each section.
59
- - Output in structured Markdown with headings for each section.
 
 
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=768, do_sample=True, temperature=0.7)[0]['generated_text']
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{cleaned}"
81
- return cleaned
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