Spaces:
Running
Running
Dhanush S Gowda
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import spacy
|
3 |
+
import requests
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
import PyPDF2
|
6 |
+
from io import BytesIO
|
7 |
+
|
8 |
+
# Load SpaCy model for NLP processing
|
9 |
+
nlp = spacy.load("en_core_web_sm")
|
10 |
+
|
11 |
+
def extract_text_from_pdf(pdf_file):
|
12 |
+
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
13 |
+
text = ""
|
14 |
+
for page in pdf_reader.pages:
|
15 |
+
text += page.extract_text() or ""
|
16 |
+
return text
|
17 |
+
|
18 |
+
def extract_skills_and_location(text):
|
19 |
+
doc = nlp(text)
|
20 |
+
skills = []
|
21 |
+
location = None
|
22 |
+
|
23 |
+
# Sample skill keywords; can be expanded for a more comprehensive list
|
24 |
+
skill_keywords = ['Python', 'Data Analysis', 'Machine Learning', 'SQL', 'Java', 'Project Management']
|
25 |
+
|
26 |
+
for token in doc:
|
27 |
+
if token.text in skill_keywords and token.text not in skills:
|
28 |
+
skills.append(token.text)
|
29 |
+
|
30 |
+
for ent in doc.ents:
|
31 |
+
if ent.label_ == 'GPE': # GPE (Geopolitical Entity) is often used for cities/countries
|
32 |
+
location = ent.text
|
33 |
+
break
|
34 |
+
|
35 |
+
return skills, location
|
36 |
+
|
37 |
+
def fetch_job_listings(job_title, location):
|
38 |
+
base_url = "https://www.careerjet.co.in/jobs"
|
39 |
+
params = {
|
40 |
+
's': job_title.replace(' ', '+'),
|
41 |
+
'l': location.replace(' ', '+')
|
42 |
+
}
|
43 |
+
|
44 |
+
response = requests.get(base_url, params=params)
|
45 |
+
|
46 |
+
if response.status_code != 200:
|
47 |
+
st.error("Failed to retrieve the job listings.")
|
48 |
+
return []
|
49 |
+
|
50 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
51 |
+
job_cards = soup.find_all('article', class_='job clicky')
|
52 |
+
|
53 |
+
job_listings = []
|
54 |
+
for job in job_cards:
|
55 |
+
title_tag = job.find('h2').find('a')
|
56 |
+
company_tag = job.find('p', class_='company').find('a')
|
57 |
+
location_tag = job.find('ul', class_='location').find('li')
|
58 |
+
description_tag = job.find('div', class_='desc')
|
59 |
+
date_posted_tag = job.find('span', class_='badge badge-r badge-s badge-icon')
|
60 |
+
|
61 |
+
job_info = {
|
62 |
+
'title': title_tag.text.strip() if title_tag else 'N/A',
|
63 |
+
'company': company_tag.text.strip() if company_tag else 'N/A',
|
64 |
+
'location': location_tag.text.strip() if location_tag else 'N/A',
|
65 |
+
'description': description_tag.text.strip() if description_tag else 'N/A',
|
66 |
+
'date_posted': date_posted_tag.text.strip() if date_posted_tag else 'N/A',
|
67 |
+
'url': f"https://www.careerjet.co.in{title_tag['href']}" if title_tag else ''
|
68 |
+
}
|
69 |
+
job_listings.append(job_info)
|
70 |
+
|
71 |
+
return job_listings
|
72 |
+
|
73 |
+
# Streamlit app
|
74 |
+
st.title("Resume-Based Job Recommender")
|
75 |
+
|
76 |
+
uploaded_file = st.file_uploader("Upload your resume (PDF format)", type=["pdf"])
|
77 |
+
|
78 |
+
if uploaded_file is not None:
|
79 |
+
# Extract text from the uploaded resume
|
80 |
+
resume_text = extract_text_from_pdf(uploaded_file)
|
81 |
+
st.text_area("Extracted Resume Text", resume_text, height=300)
|
82 |
+
|
83 |
+
# Extract skills and location
|
84 |
+
skills, location = extract_skills_and_location(resume_text)
|
85 |
+
st.write("### Extracted Skills")
|
86 |
+
st.write(", ".join(skills) if skills else "No skills found.")
|
87 |
+
st.write("### Extracted Location")
|
88 |
+
st.write(location if location else "No location found.")
|
89 |
+
|
90 |
+
# Prompt user to enter their preferred job title if necessary
|
91 |
+
job_title = st.text_input("Enter the job title (e.g., 'Data Scientist')", value=skills[0] if skills else "")
|
92 |
+
|
93 |
+
if st.button("Find Jobs"):
|
94 |
+
if location and job_title:
|
95 |
+
job_listings = fetch_job_listings(job_title, location)
|
96 |
+
if job_listings:
|
97 |
+
st.write("### Job Listings")
|
98 |
+
for job in job_listings:
|
99 |
+
st.write(f"**Title**: {job['title']}")
|
100 |
+
st.write(f"**Company**: {job['company']}")
|
101 |
+
st.write(f"**Location**: {job['location']}")
|
102 |
+
st.write(f"**Posted**: {job['date_posted']}")
|
103 |
+
st.write(f"**Description**: {job['description']}")
|
104 |
+
st.write(f"[Job Link]({job['url']})")
|
105 |
+
st.write("---")
|
106 |
+
else:
|
107 |
+
st.write("No job listings found for the given job title and location.")
|
108 |
+
else:
|
109 |
+
st.warning("Please ensure your resume has a detectable location and skills or enter them manually.")
|