Spaces:
Sleeping
Sleeping
File size: 2,496 Bytes
f5d2489 9208e17 b397dc0 f5d2489 289726b 725f549 3efbf71 f65dc03 9208e17 3efbf71 289726b ce96780 289726b 3efbf71 732403f 3efbf71 289726b 3efbf71 289726b 3efbf71 f5d2489 3efbf71 289726b 3efbf71 289726b 3efbf71 9208e17 3efbf71 9208e17 3efbf71 9208e17 3efbf71 9208e17 3efbf71 9208e17 e079d59 3efbf71 9f26a6c e079d59 3efbf71 91207a8 9208e17 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 |
from sentence_transformers import SentenceTransformer, util
import gradio as gr
# Load the SentenceTransformer model for sentence similarity
try:
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
except Exception as e:
print(f"Error loading SentenceTransformer model: {e}")
def match_cv_to_job(cv_text, job_description):
debug_info = "Debug Info:\n"
# Encode the entire CV text
try:
cv_embedding = model.encode(cv_text, convert_to_tensor=True)
debug_info += f"CV Embedding: {cv_embedding}\n"
except Exception as e:
debug_info += f"Error encoding CV text: {e}\n"
return None, debug_info
# Encode the entire job description
try:
job_description_embedding = model.encode(job_description, convert_to_tensor=True)
debug_info += f"Job Description Embedding: {job_description_embedding}\n"
except Exception as e:
debug_info += f"Error encoding job description: {e}\n"
return None, debug_info
# Compute similarity score between the entire CV and the entire job description
try:
similarity_score = util.pytorch_cos_sim(cv_embedding, job_description_embedding).item()
debug_info += f"Overall Similarity Score: {similarity_score}\n"
# Convert similarity score to a percentage for easier interpretation
match_percentage = similarity_score * 100
debug_info += f"Overall Match Percentage: {match_percentage:.2f}%\n"
except Exception as e:
debug_info += f"Error calculating similarity score: {e}\n"
return None, debug_info
return {"Match Percentage": f"{match_percentage:.2f}%"}, debug_info
# Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# CV and Job Description Matcher with Overall Similarity Score")
# Input fields for CV and job description
cv_text = gr.Textbox(label="CV Text", placeholder="Enter the CV text here", lines=10)
job_description = gr.Textbox(label="Job Description", placeholder="Enter the entire job description text here", lines=10)
# Button and output area
match_button = gr.Button("Calculate Match Percentage")
output = gr.JSON(label="Match Result")
debug_output = gr.Textbox(label="Debug Info", lines=10) # Debug box for detailed output
# Set button click to run the function
match_button.click(fn=match_cv_to_job, inputs=[cv_text, job_description], outputs=[output, debug_output])
demo.launch()
|