|
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("Customer Avatar Generator") |
|
|
|
|
|
business_type = st.text_input("Business Type", placeholder="e.g., Real Estate, Fitness") |
|
target_demographics = st.text_input("Target Demographics", placeholder="e.g., Age range, gender, location") |
|
interests = st.text_input("Interests", placeholder="e.g., Home improvement, health and wellness") |
|
additional_details = st.text_input("Additional Details", placeholder="Any specific characteristics or preferences") |
|
|
|
if st.button('Generate Avatar'): |
|
|
|
prompt_text = f"Create a detailed customer avatar for a business in the {business_type} industry. Target demographics: {target_demographics}. Interests: {interests}. Additional details: {additional_details}." |
|
|
|
|
|
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}" |
|
|
|
|
|
prompt_image = f"A visual representation of a customer avatar for a {business_type} business. Demographics: {target_demographics}. Interests: {interests}." |
|
|
|
|
|
try: |
|
response_image = openai.Image.create( |
|
model="dall-e-3", |
|
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)) |
|
except Exception as e: |
|
image = None |
|
st.error(f"Error in generating image: {e}") |
|
|
|
|
|
st.write("**Avatar Description:**") |
|
st.write(avatar_description) |
|
if image: |
|
st.image(image, caption='Generated Customer Avatar Image') |
|
|