ASNVS commited on
Commit
d4e972e
·
verified ·
1 Parent(s): a34bf90

new commit

Browse files
Files changed (1) hide show
  1. app.py +18 -24
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
- # 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}
@@ -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(model="gpt-4o-mini", # Use "gpt-3.5-turbo" if desired
27
- messages=[
28
- {"role": "system", "content": "You are a helpful and knowledgeable career advisor."},
29
- {"role": "user", "content": prompt},
30
- ],
31
- max_tokens=512,
32
- temperature=0.7)
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 (e.g., healthcare, trades, IT, ...) or type 'not sure'."),
46
- gr.Textbox(label="Your Dream Job", placeholder="Enter your dream job (e.g., software developer, plumber, digital marketing specialist, ...) or type 'not sure'."),
47
- gr.Textbox(label="Current Qualifications and Certifications", placeholder="Enter your qualifications (e.g., studying at high school, college business diploma, ...)"),
48
- 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),
49
- gr.Textbox(label="Skills", placeholder="Enter your skills (e.g., math, science, languages, working with tools, ...)", lines=2),
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 4. Developed by wn. Disclaimer: AI can make mistakes. Use with caution at your own risk!",
54
  )
55
 
56
- # Launch the application
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)