Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
prompt = f"""
|
| 12 |
-
|
| 13 |
-
|
| 14 |
"""
|
| 15 |
|
| 16 |
-
#
|
| 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
|
| 24 |
)
|
| 25 |
|
| 26 |
-
# Return the generated
|
| 27 |
return response['choices'][0]['message']['content'].strip()
|
| 28 |
|
| 29 |
-
# Function to handle further persona refinement
|
| 30 |
def chat_with_persona_generator(persona_selection, prompt_selection):
|
| 31 |
-
# A dictionary mapping prompt options to specific requests for
|
| 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
|
| 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
|
| 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
|
| 73 |
-
generate_btn = gr.Button("Generate
|
| 74 |
|
| 75 |
-
# Output textbox to display generated
|
| 76 |
-
personas_output = gr.Textbox(label="
|
| 77 |
|
| 78 |
-
#
|
| 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
|
| 92 |
|
| 93 |
-
# Button to
|
| 94 |
-
chat_btn = gr.Button("
|
| 95 |
|
| 96 |
-
# Output textbox to display refined persona
|
| 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=[
|
| 101 |
-
chat_btn.click(fn=chat_with_persona_generator, inputs=[
|
| 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 |
|