Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from sentence_transformers import SentenceTransformer, util
|
3 |
+
|
4 |
+
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
5 |
+
|
6 |
+
def match_resume(resume, job1, job2, job3):
|
7 |
+
# Calculate similarity
|
8 |
+
resume_embedding = model.encode(resume, convert_to_tensor=True)
|
9 |
+
|
10 |
+
# Encode each job description using a loop
|
11 |
+
job_embeddings = []
|
12 |
+
for job in [job1, job2, job3]:
|
13 |
+
job_embeddings.append(model.encode(job, convert_to_tensor=True))
|
14 |
+
|
15 |
+
# Calculate the similarities using a loop
|
16 |
+
similarities = []
|
17 |
+
for job_emb in job_embeddings:
|
18 |
+
similarity = util.pytorch_cos_sim(resume_embedding, job_emb).item() * 100
|
19 |
+
similarities.append(similarity)
|
20 |
+
|
21 |
+
best_job_index = 1
|
22 |
+
best_match = similarities[0]
|
23 |
+
|
24 |
+
for i in range(1, len(similarities)):
|
25 |
+
if similarities[i] > best_match:
|
26 |
+
best_match = similarities[i]
|
27 |
+
best_job_index = i + 1
|
28 |
+
|
29 |
+
|
30 |
+
results = []
|
31 |
+
for i, sim in enumerate(similarities):
|
32 |
+
results.append(f"Job {i+1}: {sim:.2f}% match")
|
33 |
+
|
34 |
+
results.append(f"Best Match: Job {best_job_index} with {best_match:.2f}%")
|
35 |
+
|
36 |
+
return "\n".join(results)
|
37 |
+
|
38 |
+
# Gradio interface
|
39 |
+
interface = gr.Interface(fn=match_resume,
|
40 |
+
inputs=["text", "text", "text", "text"],
|
41 |
+
outputs="text",
|
42 |
+
examples=[
|
43 |
+
["Experienced software developer skilled in Python and AI.",
|
44 |
+
"Looking for a Python developer with experience in AI and ML.",
|
45 |
+
"Seeking a data scientist with expertise in deep learning.",
|
46 |
+
"Hiring a web developer proficient in JavaScript and React."],
|
47 |
+
|
48 |
+
["Marketing specialist with a focus on digital campaigns.",
|
49 |
+
"Seeking a social media expert to manage brand presence.",
|
50 |
+
"Hiring a digital marketer with experience in SEO and PPC.",
|
51 |
+
"Looking for a content writer to create engaging blog posts."]
|
52 |
+
]
|
53 |
+
)
|
54 |
+
|
55 |
+
interface.launch()
|