ArchiMathur commited on
Commit
de0fe44
·
verified ·
1 Parent(s): 8f7816d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -29
app.py CHANGED
@@ -6,7 +6,6 @@ import sklearn
6
  from datasets import load_dataset
7
  import joblib
8
  import requests
9
- import os
10
 
11
  # Read the data
12
  data = pd.read_csv("mldata.csv")
@@ -50,45 +49,121 @@ career_interest_references = create_embedding_dict('interested career area ')
50
  company_intends_references = create_embedding_dict('Type of company want to settle in?')
51
  book_interest_references = create_embedding_dict('Interested Type of Books')
52
 
53
- # Function to fetch job listings
54
  def fetch_job_listings(job_title):
55
- # Use environment variable for API key (more secure)
56
- api_key = os.environ.get('RAPIDAPI_KEY', '714f5a2539msh798d996c3243876p19c71ajsnfcd7ce481cb9')
 
 
57
 
58
- url = "https://jobs-api14.p.rapidapi.com/v2/list"
59
  querystring = {
60
- "query": job_title,
61
- "location": "India",
62
- "autoTranslateLocation": "false",
63
- "remoteOnly": "false",
64
- "employmentTypes": "fulltime;parttime;intern;contractor"
65
  }
 
66
  headers = {
67
  "x-rapidapi-key": api_key,
68
- "x-rapidapi-host": "jobs-api14.p.rapidapi.com"
69
  }
70
 
71
  try:
72
- response = requests.get(url, headers=headers, params=querystring, timeout=10)
73
- response.raise_for_status()
74
- job_data = response.json()
75
 
76
- # Process and format job listings
77
- if job_data.get('jobs'):
78
- job_listings = []
79
- for job in job_data['jobs'][:5]: # Limit to 5 job listings
80
- job_listings.append([
81
- job.get('title', 'N/A'),
82
- job.get('company', 'N/A'),
83
- job.get('location', 'N/A'),
84
- job.get('salary', 'Not specified')
85
- ])
86
- return job_listings
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  else:
88
- return [['No job listings', 'found', 'for this', 'career path']]
 
89
 
90
- except requests.RequestException as e:
91
- return [['Error', 'fetching', 'job listings', str(e)]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  # Prediction function (modified to return job suggestions)
94
  def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
@@ -250,4 +325,4 @@ demo = gr.Interface(
250
 
251
  # Main execution
252
  if __name__ == "__main__":
253
- demo.launch(share=False) # share=True not supported on HF Spaces
 
6
  from datasets import load_dataset
7
  import joblib
8
  import requests
 
9
 
10
  # Read the data
11
  data = pd.read_csv("mldata.csv")
 
49
  company_intends_references = create_embedding_dict('Type of company want to settle in?')
50
  book_interest_references = create_embedding_dict('Interested Type of Books')
51
 
52
+ # Function to fetch job listings using JSearch API
53
  def fetch_job_listings(job_title):
54
+ """Fetch job listings using JSearch API from RapidAPI"""
55
+ api_key = '714f5a2539msh798d996c3243876p19c71ajsnfcd7ce481cb9'
56
+
57
+ url = "https://jsearch.p.rapidapi.com/search"
58
 
 
59
  querystring = {
60
+ "query": f"{job_title} in India",
61
+ "page": "1",
62
+ "num_pages": "1",
63
+ "date_posted": "all"
 
64
  }
65
+
66
  headers = {
67
  "x-rapidapi-key": api_key,
68
+ "x-rapidapi-host": "jsearch.p.rapidapi.com"
69
  }
70
 
71
  try:
72
+ response = requests.get(url, headers=headers, params=querystring, timeout=15)
73
+
74
+ print(f"JSearch API Response Status: {response.status_code}")
75
 
76
+ if response.status_code == 200:
77
+ job_data = response.json()
78
+
79
+ # Process JSearch response format
80
+ if job_data.get('data') and len(job_data['data']) > 0:
81
+ job_listings = []
82
+ for job in job_data['data'][:5]: # Limit to 5 job listings
83
+ # Extract salary information
84
+ salary = "Not specified"
85
+ if job.get('job_min_salary') and job.get('job_max_salary'):
86
+ min_sal = job.get('job_min_salary')
87
+ max_sal = job.get('job_max_salary')
88
+ currency = job.get('job_salary_currency', 'INR')
89
+ if currency == 'INR':
90
+ salary = f"₹{min_sal:,.0f} - ₹{max_sal:,.0f}"
91
+ else:
92
+ salary = f"{currency} {min_sal:,.0f} - {max_sal:,.0f}"
93
+ elif job.get('job_min_salary'):
94
+ min_sal = job.get('job_min_salary')
95
+ currency = job.get('job_salary_currency', 'INR')
96
+ if currency == 'INR':
97
+ salary = f"₹{min_sal:,.0f}+"
98
+ else:
99
+ salary = f"{currency} {min_sal:,.0f}+"
100
+
101
+ # Extract location
102
+ location_parts = []
103
+ if job.get('job_city'):
104
+ location_parts.append(job.get('job_city'))
105
+ if job.get('job_state'):
106
+ location_parts.append(job.get('job_state'))
107
+ if not location_parts and job.get('job_country'):
108
+ location_parts.append(job.get('job_country'))
109
+ location = ', '.join(location_parts) if location_parts else 'India'
110
+
111
+ job_listings.append([
112
+ job.get('job_title', 'N/A'),
113
+ job.get('employer_name', 'N/A'),
114
+ location,
115
+ salary
116
+ ])
117
+
118
+ print(f"Successfully fetched {len(job_listings)} jobs")
119
+ return job_listings
120
+ else:
121
+ print("No jobs found in API response")
122
+ return generate_placeholder_jobs(job_title)
123
  else:
124
+ print(f"JSearch API Error: {response.status_code} - {response.text[:200]}")
125
+ return generate_placeholder_jobs(job_title)
126
 
127
+ except Exception as e:
128
+ print(f"JSearch Exception: {str(e)}")
129
+ return generate_placeholder_jobs(job_title)
130
+
131
+ # Function to generate placeholder job suggestions
132
+ def generate_placeholder_jobs(career_title):
133
+ """Generate helpful placeholder job suggestions when API fails"""
134
+ job_resources = [
135
+ [
136
+ f"{career_title} (Entry Level)",
137
+ "Various Companies",
138
+ "India (Remote/Onsite)",
139
+ "Check: LinkedIn, Naukri.com, Indeed"
140
+ ],
141
+ [
142
+ f"{career_title} (Mid Level)",
143
+ "Various Companies",
144
+ "India (Remote/Onsite)",
145
+ "Check: LinkedIn, Naukri.com, Indeed"
146
+ ],
147
+ [
148
+ f"{career_title} Intern",
149
+ "Various Companies",
150
+ "India (Remote/Onsite)",
151
+ "Check: Internshala, AngelList"
152
+ ],
153
+ [
154
+ "Job Search Tips",
155
+ "💡 Recommended Platforms:",
156
+ "LinkedIn • Naukri • Indeed",
157
+ "Glassdoor • AngelList • Instahyre"
158
+ ],
159
+ [
160
+ "Next Steps",
161
+ "Build portfolio projects",
162
+ "Network on LinkedIn",
163
+ "Apply to 10+ positions daily"
164
+ ]
165
+ ]
166
+ return job_resources
167
 
168
  # Prediction function (modified to return job suggestions)
169
  def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
 
325
 
326
  # Main execution
327
  if __name__ == "__main__":
328
+ demo.launch(share=False)