TKM03 commited on
Commit
46c5a58
·
verified ·
1 Parent(s): 113d04e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -17
app.py CHANGED
@@ -1,28 +1,40 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
 
3
  import torch
 
4
 
5
- # Load model
6
- model_name = "shashu2325/resume-job-matcher-lora"
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForSequenceClassification.from_pretrained(model_name)
 
 
 
 
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
- outputs = model(**inputs)
14
- score = torch.nn.functional.softmax(outputs.logits, dim=1)[0][1].item()
 
 
 
 
 
 
 
 
 
 
15
  return f"Match Score: {score*100:.2f}%"
16
 
17
- demo = gr.Interface(
18
- fn=match_resume,
19
  inputs=[
20
- gr.Textbox(label="Resume Text", lines=15),
21
- gr.Textbox(label="Job Description", lines=15),
22
  ],
23
  outputs="text",
24
  title="Resume-Job Matcher",
25
- description="Paste a resume and a job description to get a match score."
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()