File size: 3,331 Bytes
522eb27
655748a
 
4a89a1a
3236cbf
655748a
 
 
4a89a1a
655748a
 
 
2258d5c
 
655748a
4a89a1a
655748a
 
 
 
 
a29607c
4a89a1a
522eb27
4a89a1a
522eb27
 
 
 
a29607c
522eb27
 
 
 
 
 
 
 
 
 
 
 
 
 
4a89a1a
522eb27
 
 
4a89a1a
522eb27
 
 
 
994b631
522eb27
 
994b631
 
 
 
 
 
522eb27
 
 
 
 
58d180e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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"""
                        <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()