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": "2", "num_pages": "2", "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"""
Company: {job.get('employer_name', 'Unknown')}
Location: {job.get('job_city', 'Unknown')}, {job.get('job_country', '')}
Type: {job.get('job_employment_type', 'N/A')}
Posted On: {job.get('job_posted_at_datetime_utc', 'N/A')}
Deadline: {job.get('job_offer_expiration_datetime_utc', 'N/A')}
🔗 Apply Now⚠️ No job openings found. Try different inputs.
" else: return "⚠️ No job data found. Try again.
" else: return f"❌ Error {response.status_code}: {response.text}
" # 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()