Spaces:
Sleeping
Sleeping
saifeddinemk
commited on
Commit
•
3efbf71
1
Parent(s):
f71b7ff
Init Commit
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from sentence_transformers import SentenceTransformer, util
|
2 |
import gradio as gr
|
3 |
-
import nltk
|
4 |
|
5 |
# Load the SentenceTransformer model for sentence similarity
|
6 |
try:
|
@@ -8,68 +7,53 @@ try:
|
|
8 |
except Exception as e:
|
9 |
print(f"Error loading SentenceTransformer model: {e}")
|
10 |
|
11 |
-
|
12 |
-
nltk.download('punkt_tab')
|
13 |
-
|
14 |
-
def match_cv_to_jobs(cv_text, job_descriptions):
|
15 |
debug_info = "Debug Info:\n"
|
16 |
-
results = []
|
17 |
|
18 |
-
# Encode the CV text
|
19 |
try:
|
20 |
cv_embedding = model.encode(cv_text, convert_to_tensor=True)
|
21 |
debug_info += f"CV Embedding: {cv_embedding}\n"
|
22 |
except Exception as e:
|
23 |
debug_info += f"Error encoding CV text: {e}\n"
|
24 |
-
return
|
25 |
|
26 |
-
#
|
27 |
try:
|
28 |
-
|
|
|
29 |
except Exception as e:
|
30 |
-
debug_info += f"Error
|
31 |
-
return
|
32 |
-
|
33 |
-
for sentence in description_sentences:
|
34 |
-
try:
|
35 |
-
# Encode each sentence from the job description
|
36 |
-
sentence_embedding = model.encode(sentence, convert_to_tensor=True)
|
37 |
-
debug_info += f"\nJob Description Sentence Embedding: {sentence_embedding}\n"
|
38 |
-
|
39 |
-
# Compute similarity score
|
40 |
-
similarity_score = util.pytorch_cos_sim(cv_embedding, sentence_embedding).item()
|
41 |
-
debug_info += f"Similarity Score for sentence: {similarity_score}\n"
|
42 |
-
|
43 |
-
results.append({
|
44 |
-
"Job Description Sentence": sentence,
|
45 |
-
"Similarity Score": similarity_score
|
46 |
-
})
|
47 |
-
except Exception as e:
|
48 |
-
debug_info += f"Error processing sentence '{sentence}': {e}\n"
|
49 |
-
continue
|
50 |
|
51 |
-
#
|
52 |
try:
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
54 |
except Exception as e:
|
55 |
-
debug_info += f"Error
|
|
|
56 |
|
57 |
-
return
|
58 |
|
59 |
# Gradio interface
|
60 |
with gr.Blocks() as demo:
|
61 |
-
gr.Markdown("# CV and Job Description Matcher with
|
62 |
|
63 |
-
# Input fields for CV and job
|
64 |
cv_text = gr.Textbox(label="CV Text", placeholder="Enter the CV text here", lines=10)
|
65 |
-
|
66 |
|
67 |
# Button and output area
|
68 |
-
match_button = gr.Button("Match
|
69 |
-
output = gr.JSON(label="Match
|
70 |
-
debug_output = gr.Textbox(label="Debug Info", lines=10) #
|
71 |
|
72 |
# Set button click to run the function
|
73 |
-
match_button.click(fn=
|
74 |
|
75 |
demo.launch()
|
|
|
1 |
from sentence_transformers import SentenceTransformer, util
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
# Load the SentenceTransformer model for sentence similarity
|
5 |
try:
|
|
|
7 |
except Exception as e:
|
8 |
print(f"Error loading SentenceTransformer model: {e}")
|
9 |
|
10 |
+
def match_cv_to_job(cv_text, job_description):
|
|
|
|
|
|
|
11 |
debug_info = "Debug Info:\n"
|
|
|
12 |
|
13 |
+
# Encode the entire CV text
|
14 |
try:
|
15 |
cv_embedding = model.encode(cv_text, convert_to_tensor=True)
|
16 |
debug_info += f"CV Embedding: {cv_embedding}\n"
|
17 |
except Exception as e:
|
18 |
debug_info += f"Error encoding CV text: {e}\n"
|
19 |
+
return None, debug_info
|
20 |
|
21 |
+
# Encode the entire job description
|
22 |
try:
|
23 |
+
job_description_embedding = model.encode(job_description, convert_to_tensor=True)
|
24 |
+
debug_info += f"Job Description Embedding: {job_description_embedding}\n"
|
25 |
except Exception as e:
|
26 |
+
debug_info += f"Error encoding job description: {e}\n"
|
27 |
+
return None, debug_info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
# Compute similarity score between the entire CV and the entire job description
|
30 |
try:
|
31 |
+
similarity_score = util.pytorch_cos_sim(cv_embedding, job_description_embedding).item()
|
32 |
+
debug_info += f"Overall Similarity Score: {similarity_score}\n"
|
33 |
+
|
34 |
+
# Convert similarity score to a percentage for easier interpretation
|
35 |
+
match_percentage = similarity_score * 100
|
36 |
+
debug_info += f"Overall Match Percentage: {match_percentage:.2f}%\n"
|
37 |
except Exception as e:
|
38 |
+
debug_info += f"Error calculating similarity score: {e}\n"
|
39 |
+
return None, debug_info
|
40 |
|
41 |
+
return {"Match Percentage": f"{match_percentage:.2f}%"}, debug_info
|
42 |
|
43 |
# Gradio interface
|
44 |
with gr.Blocks() as demo:
|
45 |
+
gr.Markdown("# CV and Job Description Matcher with Overall Similarity Score")
|
46 |
|
47 |
+
# Input fields for CV and job description
|
48 |
cv_text = gr.Textbox(label="CV Text", placeholder="Enter the CV text here", lines=10)
|
49 |
+
job_description = gr.Textbox(label="Job Description", placeholder="Enter the entire job description text here", lines=10)
|
50 |
|
51 |
# Button and output area
|
52 |
+
match_button = gr.Button("Calculate Match Percentage")
|
53 |
+
output = gr.JSON(label="Match Result")
|
54 |
+
debug_output = gr.Textbox(label="Debug Info", lines=10) # Debug box for detailed output
|
55 |
|
56 |
# Set button click to run the function
|
57 |
+
match_button.click(fn=match_cv_to_job, inputs=[cv_text, job_description], outputs=[output, debug_output])
|
58 |
|
59 |
demo.launch()
|