dindizz's picture
Create app.py
4476c45 verified
import gradio as gr
from transformers import pipeline
# Load the Hugging Face generative model (GPT-like)
generator = pipeline('text-generation', model='gpt2')
# Function to generate potential target audience groups based on product info using GPT-2
def generate_personas(company, industry, product, features_benefits):
prompt = f"Generate three potential target audience groups for {company} in the {industry} industry, focusing on their product {product} with features like {features_benefits}."
personas = generator(prompt, max_length=150, num_return_sequences=1)
return personas[0]['generated_text']
# Define the conversation logic with generative model for persona refinement
def chat_with_persona_generator(persona_selection, prompt_selection):
prompt_map = {
"Expand on the demographic attributes": "Provide detailed demographic attributes for our audience, including age, gender, location, and occupation.",
"Elaborate on the key challenges": "What are the common challenges and pain points faced by the target audience in their daily life?",
"Describe the primary goals": "What are the primary goals and aspirations of the target audience, both in the short-term and long-term?",
"Provide a comprehensive list of hobbies": "What are the hobbies, interests, and leisure activities of the target audience?",
"Explore the emotional triggers": "What emotional triggers influence the decision-making process of our target audience?",
"Detail the brands, influencers": "Which brands, influencers, or thought leaders does our target audience admire or follow, and why?",
"Outline the types of media": "What types of media does our target audience consume regularly (books, podcasts, blogs, social media)?",
"Suggest innovative communication channels": "Suggest innovative communication channels and platforms where the target audience is likely to engage.",
"Analyze the factors contributing to purchasing decisions": "Analyze the factors influencing the purchasing decisions of the target audience, including budget and decision-making influencers.",
"Describe how our customers behave digitally": "How does the target audience behave digitally, including online shopping habits, browsing patterns, and social interactions?"
}
prompt = f"{prompt_map.get(prompt_selection, 'Provide details about the target audience.')}"
response = generator(f"{persona_selection}: {prompt}", max_length=100, num_return_sequences=1)
return response[0]['generated_text']
# Gradio Interface
def persona_generator_interface():
with gr.Blocks() as interface:
gr.Markdown("## Welcome to the Customer Persona Generator!\nLet's get started with creating detailed personas for your marketing campaigns.")
# Input section
company = gr.Textbox(label="Company Name")
industry = gr.Textbox(label="Industry")
product = gr.Textbox(label="Product")
features_benefits = gr.Textbox(label="Features and Benefits")
# Button to generate personas
generate_btn = gr.Button("Generate Target Audience Groups")
# Output for audience groups
personas_output = gr.Textbox(label="Suggested Target Audience Groups", interactive=False)
# Chat options for persona refinement
persona_selection = gr.Dropdown(["Audience Group 1", "Audience Group 2", "Audience Group 3"], label="Select Audience Group")
prompt_selection = gr.Dropdown([
"Expand on the demographic attributes",
"Elaborate on the key challenges",
"Describe the primary goals",
"Provide a comprehensive list of hobbies",
"Explore the emotional triggers",
"Detail the brands, influencers",
"Outline the types of media",
"Suggest innovative communication channels",
"Analyze the factors contributing to purchasing decisions",
"Describe how our customers behave digitally"],
label="Select Prompt")
# Button to chat further
chat_btn = gr.Button("Ask")
# Output for chat response
chat_output = gr.Textbox(label="Persona Insights", interactive=False)
# Define actions
generate_btn.click(fn=generate_personas, inputs=[company, industry, product, features_benefits], outputs=personas_output)
chat_btn.click(fn=chat_with_persona_generator, inputs=[persona_selection, prompt_selection], outputs=chat_output)
return interface
# Launch the app
persona_generator_interface().launch()