File size: 1,030 Bytes
b1c3d5f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3903b71
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import gradio as gr
from sentence_transformers import SentenceTransformer, util
import re

model = SentenceTransformer("./model")

def preprocess(text):
    text = text.lower()
    text = re.sub(r"[^\w\s]", "", text)

    remove_words = [
        "summary", "experience", "experiences",
        "education", "educations", "skill", "skills",
        "role", "roles"
    ]

    for word in remove_words:
        text = re.sub(rf"\b{word}\b", "", text)

    text = re.sub(r"\s+", " ", text).strip()
    return text

def match(cv, job):
    cv = preprocess(cv)
    job = preprocess(job)

    cv_emb = model.encode(cv)
    job_emb = model.encode(job)

    score = util.cos_sim(cv_emb, job_emb).item()

    return {"score": round(score, 4)}

interface = gr.Interface(
    fn=match,
    inputs=[
        gr.Textbox(label="CV Text"),
        gr.Textbox(label="Job Description")
    ],
    outputs=gr.JSON(),
    title="CV Matching API"
)

interface.launch(
    server_name="0.0.0.0",   # required for hosted Spaces
    server_port=7860,
)