Dhanush S Gowda commited on
Commit
224ee9a
·
verified ·
1 Parent(s): 0d4683a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -55
app.py CHANGED
@@ -41,23 +41,16 @@ def extract_skills_and_location(text):
41
 
42
  return skills, location
43
 
44
- # Fetch job listings from an external source
45
  def fetch_job_listings(job_title, location, retries=3):
46
- base_url = "https://www.careerjet.co.in/search/jobs"
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, params=params, headers=headers, timeout=10)
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('article', class_='job clicky')[:5]
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').find('a')
78
- company_tag = job.find('p', class_='company').find('a')
79
- location_tag = job.find('ul', class_='location').find('li')
80
- description_tag = job.find('div', class_='desc')
81
- date_posted_tag = job.find('span', class_='badge badge-r badge-s badge-icon')
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': f"https://www.careerjet.co.in{title_tag['href']}" if title_tag else ''
90
  }
91
  job_listings.append(job_info)
92
 
93
  return job_listings
94
 
95
- # Main function to handle resume processing with loading bar
96
- def process_resume_with_notification(file):
97
- with gr.Progress() as progress:
98
- progress(0, desc="Extracting text from PDF...")
99
- resume_text = extract_text_from_pdf(file)
100
-
101
- progress(0.3, desc="Analyzing resume content...")
102
- skills, location = extract_skills_and_location(resume_text)
103
-
104
- progress(0.6, desc="Fetching job listings...")
105
- job_title = skills[0] if skills else "Software Engineer"
106
- job_listings = fetch_job_listings(job_title, location if location else "India")
107
-
108
- progress(1, desc="Formatting results...")
109
- html_content = "<h2>Extracted Skills</h2>"
110
- html_content += f"<p>{', '.join(skills)}</p>" if skills else "<p>No specific skills found.</p>"
111
- html_content += "<h2>Location</h2>"
112
- html_content += f"<p>{location}</p>" if location else "<p>Location not identified.</p>"
113
- html_content += "<h2>Job Listings</h2>"
114
-
115
- if isinstance(job_listings, str):
116
- html_content += f"<p>{job_listings}</p>"
117
- else:
118
- for job in job_listings:
119
- html_content += f"""
120
- <div style='border:1px solid #ccc; padding:10px; margin-bottom:10px;'>
121
- <h3><a href='{job['URL']}' target='_blank'>{job['Title']}</a></h3>
122
- <p><strong>Company:</strong> {job['Company']}</p>
123
- <p><strong>Location:</strong> {job['Location']}</p>
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=process_resume_with_notification,
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()