Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
# API credentials | |
API_KEY = "c1b9b6be0amsh11316ef9a922bdbp1789f5jsn18a0023eef11" | |
API_HOST = "jsearch.p.rapidapi.com" | |
# Function to fetch job openings | |
def get_job_openings(job_title, location, location_type, experience): | |
url = "https://jsearch.p.rapidapi.com/search" | |
querystring = { | |
"query": f"{job_title} in {location}", | |
"page": "1", | |
"num_pages": "1", | |
"remote_jobs_only": "true" if location_type == "REMOTE" else "false", | |
"employment_types": experience | |
} | |
headers = { | |
"x-rapidapi-key": API_KEY, | |
"x-rapidapi-host": API_HOST | |
} | |
response = requests.get(url, headers=headers, params=querystring) | |
if response.status_code == 200: | |
data = response.json() | |
if data and 'data' in data: | |
jobs = data['data'] | |
job_cards = "" | |
if jobs: | |
for job in jobs: | |
job_cards += f""" | |
<div style="border: 2px solid #ddd; padding: 15px; border-radius: 10px; margin-bottom: 15px; background-color: #f9f9f9;"> | |
<h3 style="color: #333;">{job.get('job_title', 'No Title')}</h3> | |
<p style="color: #333;"><strong style="color: #333;">Company:</strong> {job.get('employer_name', 'Unknown')}</p> | |
<p style="color: #333;"><strong style="color: #333;">Location:</strong> {job.get('job_city', 'Unknown')}, {job.get('job_country', '')}</p> | |
<p style="color: #333;"><strong style="color: #333;">Type:</strong> {job.get('job_employment_type', 'N/A')}</p> | |
<p style="color: #333;"><strong style="color: #333;">Posted On:</strong> {job.get('job_posted_at_datetime_utc', 'N/A')}</p> | |
<p style="color: #333;"><strong style="color: #333;">Deadline:</strong> {job.get('job_offer_expiration_datetime_utc', 'N/A')}</p> | |
<a href="{job.get('job_apply_link', '#')}" target="_blank" style="color: #007bff; text-decoration: none;">π Apply Now</a> | |
</div> | |
""" | |
return job_cards | |
else: | |
return "<p style='color: red;'>β οΈ No job openings found. Try different inputs.</p>" | |
else: | |
return "<p style='color: red;'>β οΈ No job data found. Try again.</p>" | |
else: | |
return f"<p style='color: red;'>β Error {response.status_code}: {response.text}</p>" | |
# Gradio UI | |
with gr.Blocks(theme=gr.themes.Base()) as demo: | |
gr.Markdown("# π― Career Connect") | |
gr.Markdown("Find the latest job openings based on your preferences.") | |
job_title = gr.Textbox(label="Enter Job Title", placeholder="e.g., Node.js Developer") | |
location = gr.Textbox(label="Enter Location", placeholder="e.g., New York") | |
location_type = gr.Dropdown(["ANY", "ON_SITE", "REMOTE", "HYBRID"], label="Location Type") | |
experience = gr.Dropdown(["FULLTIME", "PARTTIME", "INTERN", "CONTRACTOR"], label="Experience Level") | |
submit = gr.Button("π Search Jobs") | |
result = gr.HTML() | |
submit.click(get_job_openings, inputs=[job_title, location, location_type, experience], outputs=result) | |
# Launch the Gradio app | |
if __name__ == "__main__": | |
demo.launch() | |