dindizz commited on
Commit
90def41
·
verified ·
1 Parent(s): 3e68a5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -26
app.py CHANGED
@@ -5,30 +5,38 @@ import gradio as gr
5
  # Load the OpenAI API key from environment variables (kept secret)
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
- # Function to generate potential target audience groups using GPT-4o
9
- def generate_personas(company, industry, product, features_benefits):
10
- # Constructing the prompt using the user inputs (company, industry, product, features, and benefits)
 
 
 
 
 
 
 
 
11
  prompt = f"""
12
- Generate three potential target audience groups for {company} in the {industry} industry.
13
- Focus on their product, {product}, which has features such as {features_benefits}.
14
  """
15
 
16
- # Using the OpenAI API with the GPT-4o engine to generate text based on the constructed prompt
17
  response = openai.ChatCompletion.create(
18
  model="gpt-4o", # Using GPT-4o for optimized performance
19
  messages=[{"role": "system", "content": "You are a helpful assistant."},
20
  {"role": "user", "content": prompt}],
21
  max_tokens=200,
22
  n=1,
23
- temperature=0.7 # Controls creativity (higher = more creative)
24
  )
25
 
26
- # Return the generated text (target audience suggestions)
27
  return response['choices'][0]['message']['content'].strip()
28
 
29
- # Function to handle further persona refinement via GPT-4o
30
  def chat_with_persona_generator(persona_selection, prompt_selection):
31
- # A dictionary mapping prompt options to specific requests for the persona refinement
32
  prompt_map = {
33
  "Expand on the demographic attributes": "Provide detailed demographic attributes for our audience, including age, gender, location, and occupation.",
34
  "Elaborate on the key challenges": "What are the common challenges and pain points faced by the target audience in their daily life?",
@@ -42,10 +50,10 @@ def chat_with_persona_generator(persona_selection, prompt_selection):
42
  "Describe how our customers behave digitally": "How does the target audience behave digitally, including online shopping habits, browsing patterns, and social interactions?"
43
  }
44
 
45
- # Construct the conversation prompt based on user selections
46
  prompt = f"{persona_selection}: {prompt_map.get(prompt_selection, 'Provide details about the target audience.')}"
47
 
48
- # Using the GPT-4o model to generate a refined response based on the user prompt
49
  response = openai.ChatCompletion.create(
50
  model="gpt-4o", # Using GPT-4o for optimized performance
51
  messages=[{"role": "system", "content": "You are a helpful assistant."},
@@ -63,20 +71,21 @@ def persona_generator_interface():
63
  with gr.Blocks() as interface:
64
  gr.Markdown("## Welcome to the Customer Persona Generator!\nLet's get started with creating detailed personas for your marketing campaigns.")
65
 
 
 
 
66
  # Input section to collect company and product details
67
  company = gr.Textbox(label="Company Name")
68
- industry = gr.Textbox(label="Industry")
69
  product = gr.Textbox(label="Product")
70
  features_benefits = gr.Textbox(label="Features and Benefits")
71
 
72
- # Button to generate the target audience groups
73
- generate_btn = gr.Button("Generate Target Audience Groups")
74
 
75
- # Output textbox to display generated audience groups
76
- personas_output = gr.Textbox(label="Suggested Target Audience Groups", interactive=False)
77
 
78
- # Dropdowns to select an audience group and a refinement prompt
79
- persona_selection = gr.Dropdown(["Audience Group 1", "Audience Group 2", "Audience Group 3"], label="Select Audience Group")
80
  prompt_selection = gr.Dropdown([
81
  "Expand on the demographic attributes",
82
  "Elaborate on the key challenges",
@@ -88,17 +97,17 @@ def persona_generator_interface():
88
  "Suggest innovative communication channels",
89
  "Analyze the factors contributing to purchasing decisions",
90
  "Describe how our customers behave digitally"],
91
- label="Select Prompt")
92
 
93
- # Button to initiate persona refinement chat
94
- chat_btn = gr.Button("Ask")
95
 
96
- # Output textbox to display refined persona insights
97
- chat_output = gr.Textbox(label="Persona Insights", interactive=False)
98
 
99
  # Actions when buttons are clicked
100
- generate_btn.click(fn=generate_personas, inputs=[company, industry, product, features_benefits], outputs=personas_output)
101
- chat_btn.click(fn=chat_with_persona_generator, inputs=[persona_selection, prompt_selection], outputs=chat_output)
102
 
103
  return interface
104
 
 
5
  # Load the OpenAI API key from environment variables (kept secret)
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
+ # Predefined audience groups for the user to choose from
9
+ predefined_audience_groups = [
10
+ "Tech-savvy Millennials (Aged 25-40, working in IT or creative industries)",
11
+ "Young Parents (Aged 30-45, seeking convenience in family products)",
12
+ "Retirees (Aged 60+, looking for comfort and health-focused products)",
13
+ "Environmentally Conscious Consumers (Aged 20-40, highly concerned about sustainability)",
14
+ "Luxury Shoppers (Aged 30-50, interested in premium brands and experiences)"
15
+ ]
16
+
17
+ # Function to generate persona insights based on the chosen audience group and user input
18
+ def generate_personas(audience_group, company, product, features_benefits):
19
  prompt = f"""
20
+ Based on the selected audience group, {audience_group}, generate a detailed persona for the company {company}.
21
+ Their product is {product}, which has features and benefits like {features_benefits}.
22
  """
23
 
24
+ # Call OpenAI's GPT-4o model to generate the persona insights
25
  response = openai.ChatCompletion.create(
26
  model="gpt-4o", # Using GPT-4o for optimized performance
27
  messages=[{"role": "system", "content": "You are a helpful assistant."},
28
  {"role": "user", "content": prompt}],
29
  max_tokens=200,
30
  n=1,
31
+ temperature=0.7
32
  )
33
 
34
+ # Return the generated persona insights
35
  return response['choices'][0]['message']['content'].strip()
36
 
37
+ # Function to handle further persona refinement using GPT-4o
38
  def chat_with_persona_generator(persona_selection, prompt_selection):
39
+ # A dictionary mapping prompt options to specific requests for persona refinement
40
  prompt_map = {
41
  "Expand on the demographic attributes": "Provide detailed demographic attributes for our audience, including age, gender, location, and occupation.",
42
  "Elaborate on the key challenges": "What are the common challenges and pain points faced by the target audience in their daily life?",
 
50
  "Describe how our customers behave digitally": "How does the target audience behave digitally, including online shopping habits, browsing patterns, and social interactions?"
51
  }
52
 
53
+ # Construct the prompt based on user selections
54
  prompt = f"{persona_selection}: {prompt_map.get(prompt_selection, 'Provide details about the target audience.')}"
55
 
56
+ # Using the GPT-4o model to generate a refined response based on the user's query
57
  response = openai.ChatCompletion.create(
58
  model="gpt-4o", # Using GPT-4o for optimized performance
59
  messages=[{"role": "system", "content": "You are a helpful assistant."},
 
71
  with gr.Blocks() as interface:
72
  gr.Markdown("## Welcome to the Customer Persona Generator!\nLet's get started with creating detailed personas for your marketing campaigns.")
73
 
74
+ # Dropdown to select predefined audience group
75
+ audience_group = gr.Dropdown(predefined_audience_groups, label="Select Predefined Audience Group")
76
+
77
  # Input section to collect company and product details
78
  company = gr.Textbox(label="Company Name")
 
79
  product = gr.Textbox(label="Product")
80
  features_benefits = gr.Textbox(label="Features and Benefits")
81
 
82
+ # Button to generate persona insights based on the selected audience group
83
+ generate_btn = gr.Button("Generate Persona Insights")
84
 
85
+ # Output textbox to display generated persona insights
86
+ personas_output = gr.Textbox(label="Persona Insights", interactive=False)
87
 
88
+ # Dropdown to select an aspect of the persona for further refinement
 
89
  prompt_selection = gr.Dropdown([
90
  "Expand on the demographic attributes",
91
  "Elaborate on the key challenges",
 
97
  "Suggest innovative communication channels",
98
  "Analyze the factors contributing to purchasing decisions",
99
  "Describe how our customers behave digitally"],
100
+ label="Select Persona Aspect to Refine")
101
 
102
+ # Button to refine persona details
103
+ chat_btn = gr.Button("Refine Persona")
104
 
105
+ # Output textbox to display refined persona details
106
+ chat_output = gr.Textbox(label="Refined Persona Insights", interactive=False)
107
 
108
  # Actions when buttons are clicked
109
+ generate_btn.click(fn=generate_personas, inputs=[audience_group, company, product, features_benefits], outputs=personas_output)
110
+ chat_btn.click(fn=chat_with_persona_generator, inputs=[audience_group, prompt_selection], outputs=chat_output)
111
 
112
  return interface
113