Spaces:
Sleeping
Sleeping
Create app1.py
Browse filesmigrate to openAi
app1.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Set OpenAI API key from environment variable
|
| 6 |
+
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
| 7 |
+
|
| 8 |
+
# Function to generate customized career advice
|
| 9 |
+
def generate_career_advice(field, position_name, current_qualifications, likes, skills):
|
| 10 |
+
# Craft the prompt for the OpenAI model
|
| 11 |
+
prompt = f"""You are a career advisor AI. Provide customized career advice using the following details:
|
| 12 |
+
- Desired Career Field: {field}
|
| 13 |
+
- Dream Job: {position_name}
|
| 14 |
+
- Current Qualifications: {current_qualifications}
|
| 15 |
+
- Likes: {likes}
|
| 16 |
+
- Skills: {skills}
|
| 17 |
+
|
| 18 |
+
Include:
|
| 19 |
+
- Suitable career paths that are a good fit and in demand.
|
| 20 |
+
- Additional qualifications, courses, training, or certifications to pursue.
|
| 21 |
+
- Tips on networking and gaining experience.
|
| 22 |
+
Be concise and limit your response to 512 tokens or less."""
|
| 23 |
+
|
| 24 |
+
# Call the OpenAI API
|
| 25 |
+
try:
|
| 26 |
+
response = openai.ChatCompletion.create(
|
| 27 |
+
model="gpt-4", # Use "gpt-3.5-turbo" if desired
|
| 28 |
+
messages=[{"role": "system", "content": "You are a helpful and knowledgeable career advisor."},
|
| 29 |
+
{"role": "user", "content": prompt}],
|
| 30 |
+
max_tokens=512,
|
| 31 |
+
temperature=0.7,
|
| 32 |
+
)
|
| 33 |
+
# Extract the response text
|
| 34 |
+
career_advice = response["choices"][0]["message"]["content"].strip()
|
| 35 |
+
except Exception as e:
|
| 36 |
+
career_advice = f"An error occurred: {str(e)}"
|
| 37 |
+
|
| 38 |
+
return career_advice
|
| 39 |
+
|
| 40 |
+
# Create Gradio interface for the career advice application
|
| 41 |
+
career_advice_app = gr.Interface(
|
| 42 |
+
fn=generate_career_advice,
|
| 43 |
+
allow_flagging="never",
|
| 44 |
+
inputs=[
|
| 45 |
+
gr.Textbox(label="Desired Career Field", placeholder="Enter the field you're interested in or type 'not sure'."),
|
| 46 |
+
gr.Textbox(label="Your Dream Job", placeholder="Enter your dream job or type 'not sure'."),
|
| 47 |
+
gr.Textbox(label="Current Qualifications and Certifications", placeholder="Enter your qualifications..."),
|
| 48 |
+
gr.Textbox(label="Likes", placeholder="Enter things you like (e.g., helping others, working with hands)...", lines=10),
|
| 49 |
+
gr.Textbox(label="Skills", placeholder="Enter your skills (e.g., math, science, languages)...", lines=10),
|
| 50 |
+
],
|
| 51 |
+
outputs=gr.Textbox(label="Customized Career Advice"),
|
| 52 |
+
title="Customized AI-Powered Career Advice",
|
| 53 |
+
description="This app provides AI-powered customized career advice based on your input. Note: even AI can make mistakes!",
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Launch the application
|
| 57 |
+
career_advice_app.launch(server_name="0.0.0.0", debug=True, server_port=7860, share=True)
|