Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,10 @@
|
|
| 2 |
import PyPDF2
|
| 3 |
from transformers import pipeline
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
# Step 1: Load the pre-trained model
|
| 7 |
-
# You can choose a suitable model for extracting relevant entities like skills, job titles, etc.
|
| 8 |
model = pipeline('ner', model='dbmdz/bert-large-cased-finetuned-conll03-english')
|
| 9 |
|
| 10 |
# Step 2: Extract text from uploaded PDF resume
|
|
@@ -16,29 +17,59 @@ def extract_text_from_pdf(pdf_file):
|
|
| 16 |
text += reader.getPage(page).extract_text()
|
| 17 |
return text
|
| 18 |
|
| 19 |
-
# Step 3:
|
| 20 |
def analyze_resume(resume_text):
|
| 21 |
model_output = model(resume_text)
|
| 22 |
|
| 23 |
-
# Extract
|
| 24 |
skills = [item['word'] for item in model_output if item['entity'] == 'SKILL']
|
| 25 |
job_title = [item['word'] for item in model_output if item['entity'] == 'JOB_TITLE']
|
| 26 |
|
| 27 |
# Returning extracted data
|
| 28 |
return {'skills': skills, 'job_title': job_title}
|
| 29 |
|
| 30 |
-
# Step 4:
|
| 31 |
-
def
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return result
|
| 39 |
|
| 40 |
-
# Step
|
| 41 |
-
interface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
# Step
|
| 44 |
interface.launch()
|
|
|
|
| 2 |
import PyPDF2
|
| 3 |
from transformers import pipeline
|
| 4 |
import gradio as gr
|
| 5 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 6 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
| 7 |
|
| 8 |
+
# Step 1: Load the pre-trained model for Named Entity Recognition (NER)
|
|
|
|
| 9 |
model = pipeline('ner', model='dbmdz/bert-large-cased-finetuned-conll03-english')
|
| 10 |
|
| 11 |
# Step 2: Extract text from uploaded PDF resume
|
|
|
|
| 17 |
text += reader.getPage(page).extract_text()
|
| 18 |
return text
|
| 19 |
|
| 20 |
+
# Step 3: Extract relevant information (skills, job titles, etc.) from text using the model
|
| 21 |
def analyze_resume(resume_text):
|
| 22 |
model_output = model(resume_text)
|
| 23 |
|
| 24 |
+
# Extract skills and job titles
|
| 25 |
skills = [item['word'] for item in model_output if item['entity'] == 'SKILL']
|
| 26 |
job_title = [item['word'] for item in model_output if item['entity'] == 'JOB_TITLE']
|
| 27 |
|
| 28 |
# Returning extracted data
|
| 29 |
return {'skills': skills, 'job_title': job_title}
|
| 30 |
|
| 31 |
+
# Step 4: Calculate similarity between the job description and the resume
|
| 32 |
+
def calculate_similarity(job_desc, resume_text):
|
| 33 |
+
# Create a Tfidf Vectorizer to convert text into vectors
|
| 34 |
+
vectorizer = TfidfVectorizer(stop_words='english')
|
| 35 |
|
| 36 |
+
# Combine the job description and resume text into a single list
|
| 37 |
+
documents = [job_desc, resume_text]
|
| 38 |
|
| 39 |
+
# Convert the texts into TF-IDF vectors
|
| 40 |
+
tfidf_matrix = vectorizer.fit_transform(documents)
|
| 41 |
+
|
| 42 |
+
# Compute cosine similarity between job description and resume
|
| 43 |
+
similarity = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])
|
| 44 |
+
return similarity[0][0]
|
| 45 |
+
|
| 46 |
+
# Step 5: Check if the resume matches the job description and return "Good Fit" or "Not Fit"
|
| 47 |
+
def match_job_description(job_desc, resume_file):
|
| 48 |
+
# Extract text from resume
|
| 49 |
+
resume_text = extract_text_from_pdf(resume_file.name)
|
| 50 |
+
|
| 51 |
+
# Calculate the similarity between job description and resume
|
| 52 |
+
similarity_score = calculate_similarity(job_desc, resume_text)
|
| 53 |
+
|
| 54 |
+
# If the similarity score is greater than a threshold (e.g., 0.7), it's a good fit
|
| 55 |
+
if similarity_score >= 0.7:
|
| 56 |
+
return "Good Fit"
|
| 57 |
+
else:
|
| 58 |
+
return "Not Fit"
|
| 59 |
+
|
| 60 |
+
# Step 6: Gradio Interface function
|
| 61 |
+
def process_resume(job_desc, resume_file):
|
| 62 |
+
# Match the job description with the uploaded resume
|
| 63 |
+
result = match_job_description(job_desc, resume_file)
|
| 64 |
return result
|
| 65 |
|
| 66 |
+
# Step 7: Create Gradio Interface
|
| 67 |
+
interface = gr.Interface(
|
| 68 |
+
fn=process_resume,
|
| 69 |
+
inputs=["text", "file"], # Job Description (text) and Resume (file) as inputs
|
| 70 |
+
outputs="text", # Output will be a simple text response (Good Fit / Not Fit)
|
| 71 |
+
live=True
|
| 72 |
+
)
|
| 73 |
|
| 74 |
+
# Step 8: Launch the app
|
| 75 |
interface.launch()
|