|
import streamlit as st |
|
import openai |
|
import requests |
|
from PIL import Image |
|
from io import BytesIO |
|
|
|
|
|
openai.api_key = st.secrets["OPENAI_API_KEY"] |
|
|
|
st.title("Intuitive Customer Avatar & Content Pillar Generator") |
|
|
|
|
|
st.subheader("Tell Us About Your Business") |
|
business_type = st.text_input("Business Type", placeholder="e.g., Real Estate, Fitness") |
|
primary_service_or_product = st.text_input("Primary Service/Product", placeholder="e.g., Home sales, Personal training sessions") |
|
unique_selling_points = st.text_input("Unique Selling Points", placeholder="What sets your business apart?") |
|
business_location = st.text_input("Business Location", placeholder="City or region you primarily serve") |
|
|
|
st.subheader("Your Customer Interactions") |
|
most_common_customer_feedback = st.text_area("Common Customer Feedback", placeholder="What feedback do you often receive from customers?") |
|
customer_challenges = st.text_input("Customer Challenges", placeholder="What challenges do your customers typically face?") |
|
repeat_customer_characteristics = st.text_input("Repeat Customer Characteristics", placeholder="Any common traits among your repeat customers?") |
|
|
|
if st.button('Generate Avatar and Content Pillars'): |
|
|
|
prompt_text = ( |
|
f"Create a detailed customer avatar and suggest content pillars based on the following business details: " |
|
f"Business type: {business_type}, primary service/product: {primary_service_or_product}, " |
|
f"unique selling points: {unique_selling_points}, business location: {business_location}. " |
|
f"Customer feedback: {most_common_customer_feedback}, customer challenges: {customer_challenges}, " |
|
f"repeat customer characteristics: {repeat_customer_characteristics}." |
|
) |
|
|
|
|
|
try: |
|
response_text = openai.ChatCompletion.create( |
|
model="gpt-4", |
|
messages=[ |
|
{"role": "system", "content": "You are a helpful assistant."}, |
|
{"role": "user", "content": prompt_text} |
|
] |
|
) |
|
avatar_description = response_text.choices[0].message['content'] |
|
except Exception as e: |
|
avatar_description = f"Error in generating avatar description: {e}" |
|
|
|
|
|
st.markdown("### Customer Avatar Description") |
|
st.write(avatar_description.split('\n\n')[0]) |
|
st.markdown("### Content Pillars Recommendations") |
|
st.write('\n'.join(avatar_description.split('\n\n')[1:])) |
|
|
|
|
|
prompt_image = f"An image representing the customer avatar based on the business type: {business_type}, and customer characteristics: {repeat_customer_characteristics}." |
|
|
|
|
|
try: |
|
response_image = openai.Image.create( |
|
model="dall-e-2", |
|
prompt=prompt_image, |
|
n=1, |
|
size="1024x1024" |
|
) |
|
|
|
|
|
image_url = response_image['data'][0]['url'] |
|
|
|
|
|
image_response = requests.get(image_url) |
|
image = Image.open(BytesIO(image_response.content)) |
|
|
|
|
|
st.markdown("### Generated Customer Avatar Image") |
|
st.image(image, caption='Generated Customer Avatar Image') |
|
|
|
except Exception as e: |
|
st.error(f"Error in generating image: {e}") |
|
|