CoolFace
Apppublic

TKM03/ResumeMatching

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
app.py41 linesDownload Raw Back to root
1import gradio as gr2from transformers import AutoModel, AutoTokenizer3from peft import PeftModel4import torch5import torch.nn.functional as F6 7# Load models8base_model = AutoModel.from_pretrained("BAAI/bge-large-en-v1.5")9model = PeftModel.from_pretrained(base_model, "shashu2325/resume-job-matcher-lora")10tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-large-en-v1.5")11 12def get_match_score(resume_text, job_text):13    resume_inputs = tokenizer(resume_text, return_tensors="pt", max_length=512, padding="max_length", truncation=True)14    job_inputs = tokenizer(job_text, return_tensors="pt", max_length=512, padding="max_length", truncation=True)15 16    with torch.no_grad():17        resume_outputs = model(**resume_inputs)18        job_outputs = model(**job_inputs)19 20        resume_emb = resume_outputs.last_hidden_state.mean(dim=1)21        job_emb = job_outputs.last_hidden_state.mean(dim=1)22 23        resume_emb = F.normalize(resume_emb, p=2, dim=1)24        job_emb = F.normalize(job_emb, p=2, dim=1)25 26        similarity = torch.sum(resume_emb * job_emb, dim=1)27        score = torch.sigmoid(similarity).item()28 29    return f"Match Score: {score*100:.2f}%"30 31gr.Interface(32    fn=get_match_score,33    inputs=[34        gr.Textbox(label="Resume Text", lines=12, placeholder="Paste resume here..."),35        gr.Textbox(label="Job Description", lines=12, placeholder="Paste job description here...")36    ],37    outputs="text",38    title="Resume-Job Matcher",39    description="Upload resume and job description to get a match score using LoRA fine-tuned BGE model."40).launch()41