Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,40 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
|
|
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
def match_resume(resume_text, job_text):
|
| 11 |
-
inputs = tokenizer(resume_text, job_text, return_tensors="pt", truncation=True)
|
| 12 |
with torch.no_grad():
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
return f"Match Score: {score*100:.2f}%"
|
| 16 |
|
| 17 |
-
|
| 18 |
-
fn=
|
| 19 |
inputs=[
|
| 20 |
-
gr.Textbox(label="Resume Text", lines=
|
| 21 |
-
gr.Textbox(label="Job Description", lines=
|
| 22 |
],
|
| 23 |
outputs="text",
|
| 24 |
title="Resume-Job Matcher",
|
| 25 |
-
description="
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModel, AutoTokenizer
|
| 3 |
+
from peft import PeftModel
|
| 4 |
import torch
|
| 5 |
+
import torch.nn.functional as F
|
| 6 |
|
| 7 |
+
# Load models
|
| 8 |
+
base_model = AutoModel.from_pretrained("BAAI/bge-large-en-v1.5")
|
| 9 |
+
model = PeftModel.from_pretrained(base_model, "shashu2325/resume-job-matcher-lora")
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained("BAAI/bge-large-en-v1.5")
|
| 11 |
+
|
| 12 |
+
def 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 |
|
| 31 |
+
gr.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()
|
|
|
|
|
|