File size: 3,749 Bytes
bf70abc 0a480c8 c91c212 c1fbddd 757b271 bf70abc a2b71e3 f23c1ac c91c212 85e1e8f 757b271 85e1e8f 757b271 a2b71e3 757b271 a2b71e3 757b271 85e1e8f 757b271 a2b71e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import streamlit as st
import openai
import requests
from PIL import Image
from io import BytesIO
# Access the OpenAI API key from Hugging Face Spaces secrets
openai.api_key = st.secrets["OPENAI_API_KEY"]
st.title("Intuitive Customer Avatar & Content Pillar Generator")
# User inputs for avatar generation
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'):
# Construct the prompt for text generation
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}."
)
# Call the OpenAI API for text generation
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}"
# Display the avatar description with formatted headers
st.markdown("### Customer Avatar Description")
st.write(avatar_description.split('\n\n')[0]) # Assuming the avatar description is the first paragraph
st.markdown("### Content Pillars Recommendations")
st.write('\n'.join(avatar_description.split('\n\n')[1:])) # Assuming the rest is content pillars
# Additional prompt for image generation
prompt_image = f"An image representing the customer avatar based on the business type: {business_type}, and customer characteristics: {repeat_customer_characteristics}."
# Call the OpenAI API for image generation
try:
response_image = openai.Image.create(
model="dall-e-2", # Specify DALL-E model
prompt=prompt_image,
n=1,
size="1024x1024" # Set image dimensions
)
# Assuming the response contains a URL to the image
image_url = response_image['data'][0]['url']
# Fetch the image from the URL
image_response = requests.get(image_url)
image = Image.open(BytesIO(image_response.content))
# Display the image with a header
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}")
|