File size: 5,991 Bytes
a29607c
655748a
a29607c
 
 
655748a
a29607c
3236cbf
655748a
 
a29607c
 
 
 
655748a
a29607c
655748a
 
 
 
 
 
a29607c
 
 
655748a
 
 
 
 
 
a29607c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
059e7e2
a29607c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655748a
 
a29607c
 
 
655748a
a29607c
 
 
9a31d86
a29607c
 
 
9a31d86
059e7e2
 
9a31d86
059e7e2
 
 
 
a29607c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
059e7e2
a29607c
 
 
 
 
 
 
059e7e2
 
a29607c
 
 
 
 
 
059e7e2
a29607c
059e7e2
a29607c
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import gradio as gr
import requests
import os
import subprocess
import threading

# API credentials for job search
API_KEY = "c1b9b6be0amsh11316ef9a922bdbp1789f5jsn18a0023eef11"
API_HOST = "jsearch.p.rapidapi.com"

# Securely set Groq API key (for Career Counselor)
GROQ_API_KEY = "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"
os.environ["GROQ_API_KEY"] = GROQ_API_KEY

# Function to fetch job openings
def get_job_openings(job_title, location, location_type, employment_type, salary_min, salary_max):
    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": employment_type,
        "salary_min": salary_min,
        "salary_max": salary_max
    }
    headers = {
        "x-rapidapi-key": API_KEY,
        "x-rapidapi-host": API_HOST
    }
    response = requests.get(url, headers=headers, params=querystring)
    return response.json().get('data', []) if response.status_code == 200 else f"Error {response.status_code}: {response.text}"

# Function for job search UI
def search_jobs(job_title, location, location_type, employment_type, salary_min, salary_max):
    jobs = get_job_openings(job_title, location, location_type, employment_type, salary_min, salary_max)
    if isinstance(jobs, str):
        return jobs
    if not jobs:
        return "No job openings found. Please try different inputs."
    return "\n\n".join(
        f"{idx}. {job.get('job_title', 'No Title')}\n"
        f"Company: {job.get('employer_name', 'Unknown')}\n"
        f"Location: {job.get('job_city', 'Unknown')}, {job.get('job_country', '')}\n"
        f"Type: {job.get('job_employment_type', 'N/A')}\n"
        f"Salary: {job.get('job_salary_currency', '')} {job.get('job_salary_min', 'N/A')} - {job.get('job_salary_max', 'N/A')}\n"
        f"Posted On: {job.get('job_posted_at_datetime_utc', 'N/A')}\n"
        f"Deadline: {job.get('job_offer_expiration_datetime_utc', 'N/A')}\n"
        f"[View Job Posting]({job.get('job_apply_link', '#')})"
        for idx, job in enumerate(jobs, start=1)
    )

# Function to launch Career Counselor App in a separate thread
def launch_career_counselor():
    def run_streamlit():
        # Write the Streamlit app code to career_counselor.py
        with open("career_counselor.py", "w") as f:
            f.write("""
import os
import streamlit as st
from groq import Groq

GROQ_API_KEY = os.getenv("GROQ_API_KEY")
client = Groq(api_key=GROQ_API_KEY)

st.title("Career Counselor App")
st.write("Get career guidance based on your skills, interests, and experience.")

st.header("Tell us about yourself")
skills = st.text_area("List your skills (e.g., Python, teamwork, CAD):")
interests = st.text_area("What areas of interest do you have? (e.g., AI, design, civil engineering):")
experience = st.text_area("Describe your experience (if any):")

def suggest_careers_groq(skills, interests, experience):
    try:
        prompt = f"Suggest careers based on Skills: {skills}, Interests: {interests}, Experience: {experience}"
        chat_completion = client.chat.completions.create(
            messages=[{"role": "user", "content": prompt}],
            model="llama-3.3-70b-versatile",
            stream=False,
        )
        return chat_completion.choices[0].message.content
    except Exception as e:
        st.error(f"Error: {e}")
        return None

if st.button("Get Career Advice"):
    if not skills or not interests:
        st.error("Please provide skills and interests for better suggestions.")
    else:
        st.subheader("Career Recommendations")
        response = suggest_careers_groq(skills, interests, experience)
        st.write(response if response else "No recommendations available.")

st.markdown("---")
st.markdown("<p style='text-align: center;'>Designed by Career Expert</p>", unsafe_allow_html=True)
""")
        # Use a clean environment and launch via the Python module to avoid extra flags.
        env = os.environ.copy()
        subprocess.Popen(
            ["python", "-m", "streamlit", "run", "career_counselor.py"],
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
            env=env
        )
    threading.Thread(target=run_streamlit, daemon=True).start()

# Function to handle option selection
def main(option):
    if option == "Career Connect (Job Search)":
        return gr.update(visible=True), gr.update(visible=False), ""
    elif option == "Career Counselor App":
        launch_career_counselor()
        return gr.update(visible=False), gr.update(visible=True), "πŸš€ Career Counselor App is launching..."

# Gradio Interface
with gr.Blocks() as iface:
    gr.Markdown("# 🌟 Career Guidance & Job Search")
    gr.Markdown("Choose between job searching or AI-powered career guidance.")
    option = gr.Radio(["Career Connect (Job Search)", "Career Counselor App"], label="Select an Option")
    
    # Job search UI
    job_search_interface = gr.Interface(
        fn=search_jobs,
        inputs=[
            gr.Textbox(label="Enter Job Title", placeholder="e.g., Node.js Developer"),
            gr.Textbox(label="Enter Location", placeholder="e.g., New York"),
            gr.Radio(["ANY", "ON_SITE", "REMOTE", "HYBRID"], label="Location Type"),
            gr.CheckboxGroup(["FULLTIME", "PARTTIME", "INTERN", "CONTRACTOR"],
                             label="Select Employment Type", value=["FULLTIME", "INTERN"]),
            gr.Number(label="Minimum Salary ($)", value=0, minimum=0),
            gr.Number(label="Maximum Salary ($)", value=100000, minimum=0)
        ],
        outputs=gr.Textbox(label="Job Openings"),
        visible=False
    )
    
    counselor_status = gr.Markdown("", visible=False)
    
    option.change(main, inputs=option, outputs=[job_search_interface, counselor_status, gr.Textbox(label="Status")])

iface.launch()