willn9 commited on
Commit
016231e
·
verified ·
1 Parent(s): 6069dce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -38
app.py CHANGED
@@ -5,44 +5,48 @@ from openai import OpenAI
5
  # Initialize the OpenAI client
6
  client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
7
 
8
- # Response generation with streaming
9
  def respond(
10
  message,
11
- history: list[dict],
12
  system_message,
13
- customer_profile,
14
- customer_goals,
15
- company_solution,
16
- main_topic,
17
- ask_for_topic_suggestions,
 
18
  max_tokens,
19
  temperature,
20
  top_p,
21
  ):
22
- # Compose system message
23
  enhanced_system_message = (
24
  f"{system_message}\n\n"
25
- f"Customer Profile: {customer_profile}\n"
26
- f"Customer Goals, Pain Points, Obstacles, Wishes and Preferences: {customer_goals}\n"
27
- f"Company solutions, products or services, value proposition and differentiators to solve customer problem: {company_solution}\n"
28
- f"Main Topic: {main_topic}\n"
 
29
  )
30
- if ask_for_topic_suggestions:
31
- enhanced_system_message += "\nThe user is also asking for topic suggestions to address their customer's needs."
32
 
33
- # Format messages
 
 
 
34
  messages = [{"role": "system", "content": enhanced_system_message}]
35
- for m in history:
36
- messages.append({"role": "user", "content": m["user"]})
37
- if m.get("assistant"):
38
- messages.append({"role": "assistant", "content": m["assistant"]})
 
39
  messages.append({"role": "user", "content": message})
40
 
41
- # Stream OpenAI response
42
  response_text = ""
43
  try:
44
  response = client.chat.completions.create(
45
- model="gpt-4o-mini", # or other model as available
46
  messages=messages,
47
  max_tokens=max_tokens,
48
  temperature=temperature,
@@ -57,38 +61,37 @@ def respond(
57
  except Exception as e:
58
  yield f"❌ An error occurred: {str(e)}"
59
 
60
- # Gradio interface definition
61
  demo = gr.ChatInterface(
62
  fn=respond,
63
  additional_inputs=[
64
  gr.Textbox(
65
- value="You are a friendly Chatbot, a digital marketing expert and a talented copywriter. You are trying to help a user write a creative post to improve their SEO based on their input.",
66
  label="Instructions to Bot",
67
  ),
68
- gr.Textbox(label="Your Customer Profile", placeholder="Describe your customer profile (e.g., age, interests, profession)"),
 
 
 
 
69
  gr.Textbox(
70
- label="Customer Goals, Pain Points, Obstacles, Wishes and Preferences",
71
- placeholder="Describe your customer's goals, pain points, concerns, obstacles, wishes, and preferences",
72
  ),
73
  gr.Textbox(
74
- label="Company solutions, products or services",
75
- placeholder="Describe your company's solutions, products or services, value proposition and differentiators",
76
  ),
77
- gr.Textbox(label="Main Topic", placeholder="Enter the main topic of the post"),
78
- gr.Checkbox(label="Ask for Topic Suggestions", value=False),
79
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
80
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
81
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
82
  ],
83
- title="SEO Assistant",
84
- description=(
85
- "This app provides customized content that resonates with your customers to improve your SEO. "
86
- "Based on your input. Powered by OpenAI GPT-4o-mini and domain expertise. "
87
- "Expand Additional Inputs by clicking on the arrow, input more details about your customers, then a message describing what you need the assistant to do for you. "
88
- "Developed by wn. Disclaimer: AI can make mistakes. Use with caution and at your own risk!"
89
- ),
90
- type="messages", # ensures compatibility with Gradio streaming ChatInterface
91
  )
92
 
93
  if __name__ == "__main__":
94
  demo.launch()
 
 
5
  # Initialize the OpenAI client
6
  client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
7
 
8
+ # Streaming response function
9
  def respond(
10
  message,
11
+ history: list[tuple[str, str]],
12
  system_message,
13
+ role,
14
+ ad,
15
+ education,
16
+ experience,
17
+ skills,
18
+ ask_for_skills_suggestions,
19
  max_tokens,
20
  temperature,
21
  top_p,
22
  ):
23
+ # Construct the system message
24
  enhanced_system_message = (
25
  f"{system_message}\n\n"
26
+ f"Role, Industry and Type of Organization: {role}\n"
27
+ f"Job Ad Responsibilities and Key Requirements: {ad}\n"
28
+ f"Education, Training and Certifications: {education}\n"
29
+ f"Work Experience: {experience}\n"
30
+ f"Skills: {skills}\n"
31
  )
 
 
32
 
33
+ if ask_for_skills_suggestions:
34
+ enhanced_system_message += " The user is also asking for suggestions of skills related to this role."
35
+
36
+ # Compose the conversation
37
  messages = [{"role": "system", "content": enhanced_system_message}]
38
+ for user_msg, assistant_msg in history:
39
+ if user_msg:
40
+ messages.append({"role": "user", "content": user_msg})
41
+ if assistant_msg:
42
+ messages.append({"role": "assistant", "content": assistant_msg})
43
  messages.append({"role": "user", "content": message})
44
 
45
+ # Generate and stream response
46
  response_text = ""
47
  try:
48
  response = client.chat.completions.create(
49
+ model="gpt-4o", # use "gpt-4o-mini" when officially available
50
  messages=messages,
51
  max_tokens=max_tokens,
52
  temperature=temperature,
 
61
  except Exception as e:
62
  yield f"❌ An error occurred: {str(e)}"
63
 
64
+ # Gradio interface
65
  demo = gr.ChatInterface(
66
  fn=respond,
67
  additional_inputs=[
68
  gr.Textbox(
69
+ value="You are a friendly Chatbot, a career coach and with experience as a recruiter. You are trying to help a user practice STAR-style interview questions customized for a specific role, employer organization and job Ad - based on user input. Include tips if some items are missing.",
70
  label="Instructions to Bot",
71
  ),
72
+ gr.Textbox(label="Role, Industry and Employer", placeholder="Describe the role, industry and employer you are applying to."),
73
+ gr.Textbox(
74
+ label="Job Ad Responsibilities",
75
+ placeholder="Describe the Responsibilities and Key Requirements advertised in the job ad",
76
+ ),
77
  gr.Textbox(
78
+ label=" Job Key Requirements ",
79
+ placeholder="Describe your education, training, certifications and professional designations",
80
  ),
81
  gr.Textbox(
82
+ label="A Summary about your Education and Work Experience",
83
+ placeholder="Describe your education, certifications, skills, work experience, previous responsibilities and key career achievements",
84
  ),
85
+ gr.Textbox(label="Skills", placeholder="List your key skills that match this job or ask for suggestions"),
 
86
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
87
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
88
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
89
  ],
90
+ title="STAR-Style Interview Questions!",
91
+ description="This app generates STAR-Style Job Interview Questions customized to the specific role, industry and employer of the job you are applying to. Based on your input. Powered by OpenAI GPT-4o, design thinking, and domain expertise. Developed by wn. Disclaimer: AI can make mistakes. Use with caution and at your own risk!",
92
+ type="messages", # Required for Gradio ChatInterface streaming
 
 
 
 
 
93
  )
94
 
95
  if __name__ == "__main__":
96
  demo.launch()
97
+