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)