ats-score-analyzer / ai_suggestions.py
Dev1012's picture
fix
d9745bf
import os
import requests
HF_API_URL = "https://api-inference.huggingface.co/models/google/gemma-2b-it"
HF_TOKEN = os.environ.get("HF_TOKEN")
HEADERS = {
"Authorization": f"Bearer {HF_TOKEN}",
"Content-Type": "application/json"
}
def build_prompt(resume_text, jd_text, ats_result):
return f"""
You are an ATS resume improvement assistant.
Your task:
Help improve the resume to increase ATS score while staying truthful.
Do NOT invent experience.
Resume:
{resume_text}
Job Description:
{jd_text}
ATS Analysis:
- ATS Score: {ats_result["ats_score"]}
- Verdict: {ats_result["verdict"]}
- Missing Keywords: {", ".join(ats_result["missing_keywords"])}
- Skill Match Score: {ats_result["score_breakdown"]["skill_match"]["score"]}
- Keyword Match Score: {ats_result["score_breakdown"]["keyword_match"]["score"]}
- Experience Match Score: {ats_result["score_breakdown"]["experience_match"]["score"]}
- Formatting Score: {ats_result["score_breakdown"]["formatting"]["score"]}
Instructions:
1. Suggest concrete improvements (not generic advice).
2. Suggest where metrics like accuracy, scale, or performance can be added IF reasonable.
3. Replace weak verbs with strong ATS-friendly verbs.
4. Suggest missing skills ONLY if they logically fit the resume.
5. Rewrite 3 example resume bullets showing improvement.
6. Output in clean bullet points.
"""
def generate_suggestions(resume_text, jd_text, ats_result):
payload = {
"inputs": build_prompt(resume_text, jd_text, ats_result),
"parameters": {
"max_new_tokens": 300,
"temperature": 0.4,
"return_full_text": False
}
}
try:
response = requests.post(
HF_API_URL,
headers=HEADERS,
json=payload,
timeout=60
)
response.raise_for_status()
return response.json()[0]["generated_text"]
except Exception as e:
return (
"AI suggestions are temporarily unavailable.\n"
"General advice:\n"
"- Add measurable results (accuracy, scale, impact)\n"
"- Use strong action verbs\n"
"- Align skills with job description\n"
)