Spaces:
Configuration error
Configuration error
Dhanush S Gowda
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -41,23 +41,16 @@ def extract_skills_and_location(text):
|
|
41 |
|
42 |
return skills, location
|
43 |
|
44 |
-
#
|
45 |
def fetch_job_listings(job_title, location, retries=3):
|
46 |
-
base_url = "https://www.
|
47 |
-
params = {
|
48 |
-
's': job_title,
|
49 |
-
'l': location,
|
50 |
-
'p': 1,
|
51 |
-
'ps': 5
|
52 |
-
}
|
53 |
-
|
54 |
headers = {
|
55 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
|
56 |
}
|
57 |
|
58 |
for attempt in range(retries):
|
59 |
try:
|
60 |
-
response = requests.get(base_url,
|
61 |
response.raise_for_status()
|
62 |
break # Exit loop if request is successful
|
63 |
except requests.RequestException as e:
|
@@ -67,18 +60,18 @@ def fetch_job_listings(job_title, location, retries=3):
|
|
67 |
return f"Failed to retrieve job listings. Error: {str(e)}"
|
68 |
|
69 |
soup = BeautifulSoup(response.text, 'html.parser')
|
70 |
-
job_cards = soup.find_all('
|
71 |
|
72 |
if not job_cards:
|
73 |
return "No job listings found."
|
74 |
|
75 |
job_listings = []
|
76 |
for job in job_cards:
|
77 |
-
title_tag = job.find('h2'
|
78 |
-
company_tag = job.find('
|
79 |
-
location_tag = job.find('
|
80 |
-
description_tag = job.find('
|
81 |
-
date_posted_tag = job.find('
|
82 |
|
83 |
job_info = {
|
84 |
'Title': title_tag.text.strip() if title_tag else 'N/A',
|
@@ -86,58 +79,51 @@ def fetch_job_listings(job_title, location, retries=3):
|
|
86 |
'Location': location_tag.text.strip() if location_tag else 'N/A',
|
87 |
'Description': description_tag.text.strip() if description_tag else 'N/A',
|
88 |
'Date Posted': date_posted_tag.text.strip() if date_posted_tag else 'N/A',
|
89 |
-
'URL':
|
90 |
}
|
91 |
job_listings.append(job_info)
|
92 |
|
93 |
return job_listings
|
94 |
|
95 |
-
# Main function to handle resume processing
|
96 |
-
def
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
html_content += f"<p>{
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
<p><strong>Date Posted:</strong> {job['Date Posted']}</p>
|
125 |
-
<p>{job['Description']}</p>
|
126 |
-
</div>
|
127 |
-
"""
|
128 |
-
|
129 |
-
return html_content
|
130 |
|
131 |
# Create a Gradio interface for deployment
|
132 |
gr_interface = gr.Interface(
|
133 |
-
fn=
|
134 |
inputs=gr.File(label="Upload your resume (PDF format)"),
|
135 |
outputs=gr.HTML(),
|
136 |
title="Resume-Based Job Recommender",
|
137 |
description="Upload your resume and get job recommendations based on your skills and location.",
|
138 |
-
theme="default"
|
139 |
)
|
140 |
|
141 |
-
# Run the interface
|
142 |
if __name__ == "__main__":
|
143 |
gr_interface.launch()
|
|
|
41 |
|
42 |
return skills, location
|
43 |
|
44 |
+
# Web scraper function for job listings
|
45 |
def fetch_job_listings(job_title, location, retries=3):
|
46 |
+
base_url = f"https://www.examplejobboard.com/jobs?query={job_title}&location={location}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
headers = {
|
48 |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
|
49 |
}
|
50 |
|
51 |
for attempt in range(retries):
|
52 |
try:
|
53 |
+
response = requests.get(base_url, headers=headers, timeout=10)
|
54 |
response.raise_for_status()
|
55 |
break # Exit loop if request is successful
|
56 |
except requests.RequestException as e:
|
|
|
60 |
return f"Failed to retrieve job listings. Error: {str(e)}"
|
61 |
|
62 |
soup = BeautifulSoup(response.text, 'html.parser')
|
63 |
+
job_cards = soup.find_all('div', class_='job-card')[:5] # Adjust to match the website's structure
|
64 |
|
65 |
if not job_cards:
|
66 |
return "No job listings found."
|
67 |
|
68 |
job_listings = []
|
69 |
for job in job_cards:
|
70 |
+
title_tag = job.find('h2', class_='job-title')
|
71 |
+
company_tag = job.find('div', class_='company')
|
72 |
+
location_tag = job.find('span', class_='job-location')
|
73 |
+
description_tag = job.find('p', class_='job-description')
|
74 |
+
date_posted_tag = job.find('time', class_='date-posted')
|
75 |
|
76 |
job_info = {
|
77 |
'Title': title_tag.text.strip() if title_tag else 'N/A',
|
|
|
79 |
'Location': location_tag.text.strip() if location_tag else 'N/A',
|
80 |
'Description': description_tag.text.strip() if description_tag else 'N/A',
|
81 |
'Date Posted': date_posted_tag.text.strip() if date_posted_tag else 'N/A',
|
82 |
+
'URL': title_tag.a['href'] if title_tag and title_tag.a else ''
|
83 |
}
|
84 |
job_listings.append(job_info)
|
85 |
|
86 |
return job_listings
|
87 |
|
88 |
+
# Main function to handle resume processing
|
89 |
+
def process_resume(file):
|
90 |
+
resume_text = extract_text_from_pdf(file)
|
91 |
+
skills, location = extract_skills_and_location(resume_text)
|
92 |
+
|
93 |
+
job_title = skills[0] if skills else "Software Engineer"
|
94 |
+
job_listings = fetch_job_listings(job_title, location if location else "India")
|
95 |
+
|
96 |
+
html_content = "<h2>Extracted Skills</h2>"
|
97 |
+
html_content += f"<p>{', '.join(skills)}</p>" if skills else "<p>No specific skills found.</p>"
|
98 |
+
html_content += "<h2>Location</h2>"
|
99 |
+
html_content += f"<p>{location}</p>" if location else "<p>Location not identified.</p>"
|
100 |
+
html_content += "<h2>Job Listings</h2>"
|
101 |
+
|
102 |
+
if isinstance(job_listings, str):
|
103 |
+
html_content += f"<p>{job_listings}</p>"
|
104 |
+
else:
|
105 |
+
for job in job_listings:
|
106 |
+
html_content += f"""
|
107 |
+
<div style='border:1px solid #ccc; padding:10px; margin-bottom:10px;'>
|
108 |
+
<h3><a href='{job['URL']}' target='_blank'>{job['Title']}</a></h3>
|
109 |
+
<p><strong>Company:</strong> {job['Company']}</p>
|
110 |
+
<p><strong>Location:</strong> {job['Location']}</p>
|
111 |
+
<p><strong>Date Posted:</strong> {job['Date Posted']}</p>
|
112 |
+
<p>{job['Description']}</p>
|
113 |
+
</div>
|
114 |
+
"""
|
115 |
+
|
116 |
+
return html_content
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
# Create a Gradio interface for deployment
|
119 |
gr_interface = gr.Interface(
|
120 |
+
fn=process_resume,
|
121 |
inputs=gr.File(label="Upload your resume (PDF format)"),
|
122 |
outputs=gr.HTML(),
|
123 |
title="Resume-Based Job Recommender",
|
124 |
description="Upload your resume and get job recommendations based on your skills and location.",
|
|
|
125 |
)
|
126 |
|
127 |
+
# Run the interface in the cloud
|
128 |
if __name__ == "__main__":
|
129 |
gr_interface.launch()
|