career_advisor / app.py
ASNVS's picture
update
a2a42d7 verified
from openai import OpenAI
import gradio as gr
# Directly use your API key here (for quick testing only)
client = OpenAI(api_key="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")
def generate_career_advice(field, position_name, current_qualifications, likes, skills):
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."""
try:
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful and knowledgeable career advisor."},
{"role": "user", "content": prompt},
],
max_tokens=512,
temperature=0.7
)
career_advice = response.choices[0].message.content.strip()
except Exception as e:
career_advice = f"An error occurred: {str(e)}"
return career_advice
career_advice_app = gr.Interface(
fn=generate_career_advice,
allow_flagging="never",
inputs=[
gr.Textbox(label="Desired Career Field", placeholder="e.g., IT, healthcare, trades..."),
gr.Textbox(label="Your Dream Job", placeholder="e.g., software developer, doctor, plumber..."),
gr.Textbox(label="Current Qualifications and Certifications", placeholder="e.g., high school, college diploma..."),
gr.Textbox(label="Likes", placeholder="e.g., helping people, solving puzzles, building things...", lines=2),
gr.Textbox(label="Skills", placeholder="e.g., math, coding, communication...", 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-4o. Developed by wn. Disclaimer: AI can make mistakes. Use with caution.",
)
career_advice_app.launch(debug=True, share=True)