Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +51 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
4 |
+
|
5 |
+
# Load model and tokenizer
|
6 |
+
model_name = "AventIQ-AI/bert-talentmatchai"
|
7 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
8 |
+
model = BertForSequenceClassification.from_pretrained(model_name, torch_dtype=torch.float16)
|
9 |
+
|
10 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
+
model.to(device)
|
12 |
+
model.eval()
|
13 |
+
|
14 |
+
# Label mapping
|
15 |
+
label_mapping = {0: "No Fit", 1: "Low Fit", 2: "Potential Fit", 3: "Good Fit"}
|
16 |
+
|
17 |
+
def preprocess_text(text, max_length=256):
|
18 |
+
"""Truncate input text to avoid exceeding model limits."""
|
19 |
+
return " ".join(text.split()[:max_length])
|
20 |
+
|
21 |
+
def talent_match(resume, job_description):
|
22 |
+
resume = preprocess_text(resume)
|
23 |
+
job_description = preprocess_text(job_description)
|
24 |
+
|
25 |
+
input_text = f"Resume: {resume} Job Description: {job_description}"
|
26 |
+
inputs = tokenizer([input_text], padding="max_length", truncation=True, return_tensors="pt").to(device)
|
27 |
+
with torch.no_grad():
|
28 |
+
outputs = model(**inputs)
|
29 |
+
prediction = outputs.logits.argmax(dim=1).item()
|
30 |
+
|
31 |
+
return label_mapping[prediction]
|
32 |
+
|
33 |
+
iface = gr.Interface(
|
34 |
+
fn=talent_match,
|
35 |
+
inputs=[
|
36 |
+
gr.Textbox(label="📄 Resume", placeholder="Paste the candidate's resume here...", lines=5),
|
37 |
+
gr.Textbox(label="📌 Job Description", placeholder="Paste the job description here...", lines=5)
|
38 |
+
],
|
39 |
+
outputs=gr.Textbox(label="✅ Match Result"),
|
40 |
+
title="🤖 AI-Powered Talent Matching System",
|
41 |
+
description="🔍 Enter a candidate's resume and a job description to check if they are a good match using AI.",
|
42 |
+
theme="compact",
|
43 |
+
allow_flagging="never",
|
44 |
+
examples=[
|
45 |
+
["Experienced Python developer skilled in machine learning and data science.", "Looking for a Python developer with ML experience."],
|
46 |
+
["Project manager with 5 years in Agile methodologies.", "Seeking a Scrum Master with Agile experience."]
|
47 |
+
],
|
48 |
+
)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
gradio
|
4 |
+
sentencepiece
|