Spaces:
Sleeping
Sleeping
old April
Browse files- app_apr.py +58 -0
app_apr.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
|
| 4 |
+
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
# Set OpenAI API key from environment variable
|
| 8 |
+
|
| 9 |
+
# Function to generate customized career advice
|
| 10 |
+
def generate_career_advice(field, position_name, current_qualifications, likes, skills):
|
| 11 |
+
# Craft the prompt for the OpenAI model
|
| 12 |
+
prompt = f"""You are a career advisor AI. Provide customized career advice using the following details:
|
| 13 |
+
- Desired Career Field: {field}
|
| 14 |
+
- Dream Job: {position_name}
|
| 15 |
+
- Current Qualifications: {current_qualifications}
|
| 16 |
+
- Likes: {likes}
|
| 17 |
+
- Skills: {skills}
|
| 18 |
+
Include:
|
| 19 |
+
- Suitable career paths that are a good fit and in demand.
|
| 20 |
+
- Additional requirements such as qualifications, new skills to acquire, courses, training, or certifications to pursue.
|
| 21 |
+
- How to build experience, through internships, apprenticeships, volunteering, etc., as applicable.
|
| 22 |
+
- Tips on networking and gaining experience.
|
| 23 |
+
Be concise and limit your response to 1024 tokens or less."""
|
| 24 |
+
|
| 25 |
+
# Call the OpenAI API
|
| 26 |
+
try:
|
| 27 |
+
response = client.chat.completions.create(model="gpt-4o-mini", # Use "gpt-3.5-turbo" if desired
|
| 28 |
+
messages=[
|
| 29 |
+
{"role": "system", "content": "You are a helpful and knowledgeable career advisor."},
|
| 30 |
+
{"role": "user", "content": prompt},
|
| 31 |
+
],
|
| 32 |
+
max_tokens=512,
|
| 33 |
+
temperature=0.7)
|
| 34 |
+
# Extract the response text
|
| 35 |
+
career_advice = response.choices[0].message.content.strip()
|
| 36 |
+
except Exception as e:
|
| 37 |
+
career_advice = f"An error occurred: {str(e)}"
|
| 38 |
+
|
| 39 |
+
return career_advice
|
| 40 |
+
|
| 41 |
+
# Create Gradio interface for the career advice application
|
| 42 |
+
career_advice_app = gr.Interface(
|
| 43 |
+
fn=generate_career_advice,
|
| 44 |
+
allow_flagging="never",
|
| 45 |
+
inputs=[
|
| 46 |
+
gr.Textbox(label="Desired Career Field", placeholder="Enter the field you're interested in (e.g., healthcare, trades, IT, ...) or type 'not sure'."),
|
| 47 |
+
gr.Textbox(label="Your Dream Job", placeholder="Enter your dream job (e.g., software developer, plumber, digital marketing specialist, ...) or type 'not sure'."),
|
| 48 |
+
gr.Textbox(label="Current Qualifications and Certifications", placeholder="Enter your qualifications (e.g., studying at high school, college business diploma, ...)"),
|
| 49 |
+
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),
|
| 50 |
+
gr.Textbox(label="Skills", placeholder="Enter your skills (e.g., math, science, languages, working with tools, ...)", lines=2),
|
| 51 |
+
],
|
| 52 |
+
outputs=gr.Textbox(label="Customized Career Advice", lines=25),
|
| 53 |
+
title="Customized AI-Powered Career Advice",
|
| 54 |
+
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!",
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Launch the application
|
| 58 |
+
career_advice_app.launch(server_name="0.0.0.0", debug=True, share=True)
|