Spaces:
Sleeping
Sleeping
new commit
Browse files
app.py
CHANGED
@@ -1,14 +1,10 @@
|
|
1 |
-
import os
|
2 |
from openai import OpenAI
|
3 |
-
|
4 |
-
client = OpenAI(api_key=os.environ.get("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"))
|
5 |
import gradio as gr
|
6 |
|
7 |
-
#
|
|
|
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}
|
@@ -21,37 +17,35 @@ def generate_career_advice(field, position_name, current_qualifications, likes,
|
|
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 = client.chat.completions.create(
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
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="
|
46 |
-
gr.Textbox(label="Your Dream Job", placeholder="
|
47 |
-
gr.Textbox(label="Current Qualifications and Certifications", placeholder="
|
48 |
-
gr.Textbox(label="Likes", placeholder="
|
49 |
-
gr.Textbox(label="Skills", placeholder="
|
50 |
],
|
51 |
outputs=gr.Textbox(label="Customized Career Advice", lines=25),
|
52 |
title="Customized AI-Powered Career Advice",
|
53 |
-
description="This app provides AI-powered customized career advice based on your input. Powered by OpenAI GPT
|
54 |
)
|
55 |
|
56 |
-
|
57 |
-
career_advice_app.launch(server_name="0.0.0.0", debug=True, share=True)
|
|
|
|
|
1 |
from openai import OpenAI
|
|
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Directly use your API key here (for quick testing only)
|
5 |
+
client = OpenAI(api_key="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")
|
6 |
|
|
|
7 |
def generate_career_advice(field, position_name, current_qualifications, likes, skills):
|
|
|
8 |
prompt = f"""You are a career advisor AI. Provide customized career advice using the following details:
|
9 |
- Desired Career Field: {field}
|
10 |
- Dream Job: {position_name}
|
|
|
17 |
- Tips on networking and gaining experience.
|
18 |
Be concise and limit your response to 512 tokens or less."""
|
19 |
|
|
|
20 |
try:
|
21 |
+
response = client.chat.completions.create(
|
22 |
+
model="gpt-4o",
|
23 |
+
messages=[
|
24 |
+
{"role": "system", "content": "You are a helpful and knowledgeable career advisor."},
|
25 |
+
{"role": "user", "content": prompt},
|
26 |
+
],
|
27 |
+
max_tokens=512,
|
28 |
+
temperature=0.7
|
29 |
+
)
|
30 |
career_advice = response.choices[0].message.content.strip()
|
31 |
except Exception as e:
|
32 |
career_advice = f"An error occurred: {str(e)}"
|
33 |
|
34 |
return career_advice
|
35 |
|
|
|
36 |
career_advice_app = gr.Interface(
|
37 |
fn=generate_career_advice,
|
38 |
allow_flagging="never",
|
39 |
inputs=[
|
40 |
+
gr.Textbox(label="Desired Career Field", placeholder="e.g., IT, healthcare, trades..."),
|
41 |
+
gr.Textbox(label="Your Dream Job", placeholder="e.g., software developer, doctor, plumber..."),
|
42 |
+
gr.Textbox(label="Current Qualifications and Certifications", placeholder="e.g., high school, college diploma..."),
|
43 |
+
gr.Textbox(label="Likes", placeholder="e.g., helping people, solving puzzles, building things...", lines=2),
|
44 |
+
gr.Textbox(label="Skills", placeholder="e.g., math, coding, communication...", lines=2),
|
45 |
],
|
46 |
outputs=gr.Textbox(label="Customized Career Advice", lines=25),
|
47 |
title="Customized AI-Powered Career Advice",
|
48 |
+
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.",
|
49 |
)
|
50 |
|
51 |
+
career_advice_app.launch(debug=True, share=True)
|
|