Anushree1 commited on
Commit
c475914
·
verified ·
1 Parent(s): b89d032

create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pdfplumber
3
+ import spacy
4
+ from sentence_transformers import SentenceTransformer, util
5
+
6
+ # Load spaCy model and Sentence Transformer model
7
+ nlp = spacy.load('en_core_web_md')
8
+ model = SentenceTransformer('all-MiniLM-L6-v2')
9
+
10
+ def extract_text_from_pdf(pdf_path):
11
+ text = ''
12
+ with pdfplumber.open(pdf_path) as pdf:
13
+ for page in pdf.pages:
14
+ text += page.extract_text()
15
+ return text
16
+
17
+ def extract_text_from_txt(txt_path):
18
+ with open(txt_path, 'r') as file:
19
+ return file.read()
20
+
21
+ def analyze_resume(resume_file, job_description_file):
22
+ # Extract text from the PDF resume
23
+ resume_text = extract_text_from_pdf(resume_file.name)
24
+
25
+ # Extract text from the job description text file
26
+ job_description = extract_text_from_txt(job_description_file.name)
27
+
28
+ # Process the text with spaCy
29
+ doc = nlp(resume_text)
30
+
31
+ # Extract named entities from the resume
32
+ entities = [(ent.text, ent.label_) for ent in doc.ents]
33
+
34
+ # Get embeddings and compute similarity
35
+ resume_embedding = model.encode(resume_text)
36
+ job_description_embedding = model.encode(job_description)
37
+ similarity = util.pytorch_cos_sim(resume_embedding, job_description_embedding).item()
38
+
39
+ return entities, similarity, job_description
40
+
41
+ # Create a Gradio interface
42
+ iface = gr.Interface(
43
+ fn=analyze_resume,
44
+ inputs=[
45
+ gr.File(label="Upload Resume (PDF)"),
46
+ gr.File(label="Upload Job Description (TXT)")
47
+ ],
48
+ outputs=[
49
+ gr.JSON(label="Extracted Entities"),
50
+ gr.Textbox(label="Resume and Job Description Similarity"),
51
+ gr.Textbox(label="Job Description Text", interactive=False)
52
+ ],
53
+ title="Resume and Job Description Analyzer",
54
+ description="Upload your PDF resume and a TXT job description to extract entities and calculate similarity."
55
+ )
56
+
57
+ # Launch the interface
58
+ iface.launch()