File size: 2,894 Bytes
9870b10
1ad68d2
 
 
9870b10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df869ec
1ad68d2
 
 
 
 
 
9870b10
d56882c
9870b10
 
 
 
 
 
 
 
 
 
63b8649
 
2f8fd79
4f056fe
7bf2c01
9870b10
cd20648
5e95df2
cd20648
9870b10
 
 
3390950
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
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
import gradio as gr

# Set OpenAI API key from environment variable

# Function to generate customized career advice
def generate_career_advice(field, position_name, current_qualifications, likes, skills):
    # Craft the prompt for the OpenAI model
    prompt = f"""You are a career advisor AI. Provide customized career advice using the following details:
    - Desired Career Field: {field}
    - Dream Job: {position_name}
    - Current Qualifications: {current_qualifications}
    - Likes: {likes}
    - Skills: {skills}
    Include:
    - Suitable career paths that are a good fit and in demand.
    - Additional qualifications, courses, training, or certifications to pursue.
    - Tips on networking and gaining experience.
    Be concise and limit your response to 512 tokens or less."""

    # Call the OpenAI API
    try:
        response = client.chat.completions.create(model="gpt-4o-mini",  # Use "gpt-3.5-turbo" if desired
        messages=[
            {"role": "system", "content": "You are a helpful and knowledgeable career advisor."},
            {"role": "user", "content": prompt},
        ],
        max_tokens=512,
        temperature=0.7)
        # Extract the response text
        career_advice = response.choices[0].message.content.strip()
    except Exception as e:
        career_advice = f"An error occurred: {str(e)}"

    return career_advice

# Create Gradio interface for the career advice application
career_advice_app = gr.Interface(
    fn=generate_career_advice,
    allow_flagging="never",
    inputs=[
        gr.Textbox(label="Desired Career Field", placeholder="Enter the field you're interested in (e.g., healthcare, trades, IT, ...) or type 'not sure'."),
        gr.Textbox(label="Your Dream Job", placeholder="Enter your dream job (e.g., software developer, plumber, digital marketing specialist, ...) or type 'not sure'."),
        gr.Textbox(label="Current Qualifications and Certifications", placeholder="Enter your qualifications (e.g., studying at high school, college business diploma, ...)"),
        gr.Textbox(label="Likes", placeholder="Enter things you like (e.g., helping people, working with my hands, solving puzzels, caring for animals, building things, etc.)", lines=2),
        gr.Textbox(label="Skills", placeholder="Enter your skills (e.g., math, science, languages, working with tools, ...)", lines=2),
    ],
    outputs=gr.Textbox(label="Customized Career Advice", lines=25),
    title="Customized AI-Powered Career Advice",
    description="This app provides AI-powered customized career advice based on your input. Powered by OpenAI GPT 4. Developed by wn. Disclaimer: AI can make mistakes. Use with caution at your own risk!",
)

# Launch the application
career_advice_app.launch(server_name="0.0.0.0", debug=True, share=True)