willn9 commited on
Commit
cf9ab13
·
verified ·
1 Parent(s): a1ffe58

Virtual Consumer Persona

Browse files
Files changed (1) hide show
  1. app.py +41 -41
app.py CHANGED
@@ -5,29 +5,30 @@ from openai import OpenAI
5
  # Initialize OpenAI client (expects OPENAI_API_KEY in env)
6
  client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
7
 
8
- def make_system_message(system_message, role, jobad, education, workexp, skills, ask_sugg):
9
  msg = (
10
  f"{system_message}\n\n"
11
- f"Role, Industry and Type of Organization: {role}\n"
12
- f"Job Ad Responsibilities and Key Requirements: {jobad}\n"
13
- f"Education, Training and Certifications: {education}\n"
14
- f"Work Experience: {workexp}\n"
15
- f"Skills: {skills}\n"
 
 
16
  )
17
- if ask_sugg:
18
- msg += " The user is also asking for suggestions of skills related to this role."
19
  return msg
20
 
21
  def stream_chat(
22
  message,
23
  history, # list[list[str, str]] from gr.Chatbot
24
  system_message,
25
- role,
26
- jobad,
27
- education,
28
- workexp,
29
- skills,
30
- ask_sugg,
31
  max_tokens,
32
  temp,
33
  top_p,
@@ -36,7 +37,7 @@ def stream_chat(
36
  Streaming generator that yields the progressively updated chat history.
37
  """
38
  # 1) Build system + conversation messages
39
- sys_msg = make_system_message(system_message, role, jobad, education, workexp, skills, ask_sugg)
40
 
41
  messages = [{"role": "system", "content": sys_msg}]
42
  for user_msg, assistant_msg in (history or []):
@@ -73,58 +74,57 @@ def stream_chat(
73
  yield running_history
74
 
75
 
76
- with gr.Blocks(title="ResumizeCustomize your CV!") as demo:
77
  gr.Markdown("""
78
- # ResumizeCustomize your CV!
79
- This app customizes your resume to best suit a specific role, industry, employer and job ad.
80
- Powered by OpenAI GPT-4o and domain expertise.
 
81
  """)
82
 
83
- chatbot = gr.Chatbot(height=400)
84
 
85
  with gr.Column():
86
  instructions = gr.Textbox(
87
  value=(
88
- "You are a friendly Chatbot, a career coach and a talented copywriter. "
89
- "You are trying to help a user customize their resume according to a specific role, employer organization and job Ad "
90
- "- based on user input. Include tips if some items are missing."
91
  ),
92
- label="Instructions to Bot",
93
- lines=4,
94
  )
95
- role = gr.Textbox(label="Role, Industry and Employer", placeholder="Describe the role, industry and employer you are applying to.")
96
- jobad = gr.Textbox(label="Job Ad Responsibilities and Key Requirements", placeholder="Paste/describe the job ad responsibilities and key requirements", lines=4)
97
- education = gr.Textbox(label="Your Education, Certifications, Training, etc.", placeholder="Degrees, diplomas, certifications, courses", lines=3)
98
- workexp = gr.Textbox(label="Your Work Experience", placeholder="Roles, responsibilities, achievements", lines=4)
99
- skills = gr.Textbox(label="Skills", placeholder="List your key skills that match this job or ask for suggestions")
100
- ask_sugg = gr.Checkbox(label="Ask for Skills Suggestions", value=False)
101
 
102
  with gr.Row():
103
- max_tokens = gr.Slider(minimum=1, maximum=4096, value=512, step=1, label="Max new tokens")
104
- temp = gr.Slider(minimum=0.0, maximum=2.0, value=0.7, step=0.1, label="Temperature")
105
  top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus)")
106
 
107
- msg = gr.Textbox(label="Type your message here...", placeholder="e.g., Draft a tailored resume summary")
108
  with gr.Row():
109
- send = gr.Button("Send", variant="primary")
110
- clear = gr.Button("Clear")
111
 
112
  # Wire up sending (submit or button) → stream_chat → chatbot
113
- inputs = [msg, chatbot, instructions, role, jobad, education, workexp, skills, ask_sugg, max_tokens, temp, top_p]
114
  outputs = [chatbot]
115
 
116
  msg.submit(stream_chat, inputs, outputs)
117
  send.click(stream_chat, inputs, outputs)
118
 
119
- # Clear everything
120
  def do_clear():
121
- return [], "", "", "", "", "", "", False, 512, 0.7, 0.95
122
 
123
  clear.click(
124
  do_clear,
125
  inputs=[],
126
- outputs=[chatbot, msg, instructions, role, jobad, education, workexp, skills, ask_sugg, max_tokens, temp, top_p],
127
  )
128
 
129
  if __name__ == "__main__":
130
- demo.launch()
 
5
  # Initialize OpenAI client (expects OPENAI_API_KEY in env)
6
  client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
7
 
8
+ def make_system_message(system_message, demographics, occupation, psychographics, buying_habits, critical_mode):
9
  msg = (
10
  f"{system_message}\n\n"
11
+ f"Your Demographics (Age, Location, Gender): {demographics}\n"
12
+ f"Your Occupation and Income Level: {occupation}\n"
13
+ f"Your Psychographics (Interests, Values, Lifestyle, Pain Points): {psychographics}\n"
14
+ f"Your Buying Habits: {buying_habits}\n\n"
15
+ "CRITICAL INSTRUCTION: You are NOT an AI assistant. You are a real human consumer with the profile above. "
16
+ "The user is a high school business student conducting market research. Answer their questions strictly in character. "
17
+ "Speak naturally, casually, and honestly based on your profile. Do not break character. Do not be overly helpful like a bot."
18
  )
19
+ if critical_mode:
20
+ msg += " Also, play the role of a highly skeptical and critical consumer. Be hard to impress, ask tough questions about the product, and be very protective of your money."
21
  return msg
22
 
23
  def stream_chat(
24
  message,
25
  history, # list[list[str, str]] from gr.Chatbot
26
  system_message,
27
+ demographics,
28
+ occupation,
29
+ psychographics,
30
+ buying_habits,
31
+ critical_mode,
 
32
  max_tokens,
33
  temp,
34
  top_p,
 
37
  Streaming generator that yields the progressively updated chat history.
38
  """
39
  # 1) Build system + conversation messages
40
+ sys_msg = make_system_message(system_message, demographics, occupation, psychographics, buying_habits, critical_mode)
41
 
42
  messages = [{"role": "system", "content": sys_msg}]
43
  for user_msg, assistant_msg in (history or []):
 
74
  yield running_history
75
 
76
 
77
+ with gr.Blocks(title="Virtual Consumer Persona Live Focus Group!") as demo:
78
  gr.Markdown("""
79
+ # 🎯 Virtual Consumer Persona Live Focus Group!
80
+ Bring your target market to life! Enter the details of your ideal customer from your **Phygital Workbook** into the fields below.
81
+ Once filled out, use the chat box to interview this 'person' about your product, pricing, or marketing ideas.
82
+ *Powered by OpenAI GPT-4o-mini. Developed by wn.*
83
  """)
84
 
85
+ chatbot = gr.Chatbot(height=450)
86
 
87
  with gr.Column():
88
  instructions = gr.Textbox(
89
  value=(
90
+ "You are participating in a market research focus group. Answer the user's questions truthfully based on the persona details provided below."
 
 
91
  ),
92
+ label="Instructions to Bot (Hidden Persona Prompt)",
93
+ lines=2,
94
  )
95
+ demographics = gr.Textbox(label="1. Demographics", placeholder="e.g., 19 years old, female, living in downtown Toronto")
96
+ occupation = gr.Textbox(label="2. Occupation & Income", placeholder="e.g., University student, part-time barista, low disposable income")
97
+ psychographics = gr.Textbox(label="3. Psychographics (Interests & Values)", placeholder="e.g., Highly eco-conscious, loves hiking, vegan, stressed about student debt", lines=2)
98
+ buying_habits = gr.Textbox(label="4. Buying Habits", placeholder="e.g., Willing to pay more for sustainable brands, influenced by TikTok, impulse buyer", lines=2)
99
+
100
+ critical_mode = gr.Checkbox(label="Skeptical Consumer Mode (Check this to make the AI harder to sell to!)", value=False)
101
 
102
  with gr.Row():
103
+ max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
104
+ temp = gr.Slider(minimum=0.0, maximum=2.0, value=0.9, step=0.1, label="Temperature (Creativity)")
105
  top_p = gr.Slider(minimum=0.0, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus)")
106
 
107
+ msg = gr.Textbox(label="Type your interview question here...", placeholder="e.g., How much would you be willing to pay for a smart water bottle?")
108
  with gr.Row():
109
+ send = gr.Button("Ask Question", variant="primary")
110
+ clear = gr.Button("Clear Chat History")
111
 
112
  # Wire up sending (submit or button) → stream_chat → chatbot
113
+ inputs = [msg, chatbot, instructions, demographics, occupation, psychographics, buying_habits, critical_mode, max_tokens, temp, top_p]
114
  outputs = [chatbot]
115
 
116
  msg.submit(stream_chat, inputs, outputs)
117
  send.click(stream_chat, inputs, outputs)
118
 
119
+ # Clear everything (Only clear the chat and message box, leave the persona data intact for better UX)
120
  def do_clear():
121
+ return [], ""
122
 
123
  clear.click(
124
  do_clear,
125
  inputs=[],
126
+ outputs=[chatbot, msg],
127
  )
128
 
129
  if __name__ == "__main__":
130
+ demo.launch()