Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pdfplumber | |
import spacy | |
from sentence_transformers import SentenceTransformer, util | |
# Load spaCy model and Sentence Transformer model | |
nlp = spacy.load('en_core_web_md') | |
model = SentenceTransformer('all-MiniLM-L6-v2') | |
def extract_text_from_pdf(pdf_path): | |
text = '' | |
with pdfplumber.open(pdf_path) as pdf: | |
for page in pdf.pages: | |
text += page.extract_text() | |
return text | |
def extract_text_from_txt(txt_path): | |
with open(txt_path, 'r') as file: | |
return file.read() | |
def analyze_resume(resume_file, job_description_file): | |
# Extract text from the PDF resume | |
resume_text = extract_text_from_pdf(resume_file.name) | |
# Extract text from the job description text file | |
job_description = extract_text_from_txt(job_description_file.name) | |
# Process the text with spaCy | |
doc = nlp(resume_text) | |
# Extract named entities from the resume | |
entities = [(ent.text, ent.label_) for ent in doc.ents] | |
# Get embeddings and compute similarity | |
resume_embedding = model.encode(resume_text) | |
job_description_embedding = model.encode(job_description) | |
similarity = util.pytorch_cos_sim(resume_embedding, job_description_embedding).item() | |
return entities, similarity, job_description | |
# Create a Gradio interface | |
iface = gr.Interface( | |
fn=analyze_resume, | |
inputs=[ | |
gr.File(label="Upload Resume (PDF)"), | |
gr.File(label="Upload Job Description (TXT)") | |
], | |
outputs=[ | |
gr.JSON(label="Extracted Entities"), | |
gr.Textbox(label="Resume and Job Description Similarity"), | |
gr.Textbox(label="Job Description Text", interactive=False) | |
], | |
title="Resume and Job Description Analyzer", | |
description="Upload your PDF resume and a TXT job description to extract entities and calculate similarity." | |
) | |
# Launch the interface | |
iface.launch() | |