|
import os |
|
from dotenv import load_dotenv |
|
from sentence_transformers import SentenceTransformer, util |
|
import gradio as gr |
|
from huggingface_hub import login |
|
import requests |
|
from huggingface_hub import HfApi |
|
|
|
|
|
import os |
|
from huggingface_hub import HfApi |
|
|
|
hf_token = os.getenv("hf_token") |
|
api = HfApi(token=hf_token) |
|
|
|
|
|
embed_model = SentenceTransformer("sentence-transformers/all-mpnet-base-v2") |
|
|
|
|
|
def call_zephyr_api(prompt): |
|
url = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta" |
|
headers = { |
|
"Authorization": f"Bearer {hf_token}", |
|
"Content-Type": "application/json" |
|
} |
|
payload = { |
|
"inputs": prompt, |
|
"parameters": { |
|
"max_new_tokens": 512, |
|
"temperature": 0.7 |
|
} |
|
} |
|
try: |
|
response = requests.post(url, headers=headers, json=payload) |
|
response.raise_for_status() |
|
return response.json()[0]["generated_text"] |
|
except Exception as e: |
|
return f"⚠️ Error generating suggestions: {e}" |
|
|
|
|
|
def resume_matcher_and_advisor(resume_text, job_desc): |
|
embeddings = embed_model.encode([resume_text, job_desc], convert_to_tensor=True) |
|
similarity_score = util.pytorch_cos_sim(embeddings[0], embeddings[1]).item() |
|
res_score = round(similarity_score * 100, 2) |
|
|
|
if res_score > 85: |
|
suggestions = "✅ This resume is a good fit for the job description!" |
|
else: |
|
prompt = f"""<|system|> |
|
You are a professional resume reviewer. |
|
<|user|> |
|
Compare the following resume with the job description and give bullet-point suggestions to improve the resume so that it better fits the job requirements. |
|
- Be critical and constructive. |
|
- Do NOT assume the resume matches the job. |
|
- DO NOT rewrite the resume or job. |
|
- DO NOT hallucinate skills. |
|
Job Description: |
|
{job_desc} |
|
Resume: |
|
{resume_text} |
|
</s>""" |
|
suggestions = call_zephyr_api(prompt) |
|
|
|
return res_score, suggestions |
|
|
|
|
|
iface = gr.Interface( |
|
fn=resume_matcher_and_advisor, |
|
inputs=[ |
|
gr.Textbox(lines=15, label="Paste Resume Text"), |
|
gr.Textbox(lines=15, label="Paste Job Description") |
|
], |
|
outputs=[ |
|
gr.Number(label="Similarity Score (%)"), |
|
gr.Textbox(label="Improvement Suggestions") |
|
], |
|
title="🧠 Resume Matcher & Advisor", |
|
description="Paste a resume and job description. Get a match score and improvement suggestions." |
|
) |
|
|
|
iface.launch(share=True) |
|
|