bizvideoschool's picture
Update app.py
c91c212
raw
history blame
No virus
1.9 kB
import streamlit as st
import openai
import requests
from PIL import Image
from io import BytesIO
# Setup OpenAI API key (ensure it's set in environment variables)
openai.api_key = os.environ["OPENAI_API_KEY"]
st.title("Customer Avatar Generator")
# User inputs for avatar generation
name = st.text_input("Customer's Name", placeholder="Enter a name for your customer avatar")
age = st.text_input("Age Range", placeholder="e.g., 30-40 years")
gender = st.selectbox("Gender", ["Female", "Male", "Non-binary", "Prefer not to say"])
location = st.text_input("Location", placeholder="e.g., Urban, Suburban, Rural")
interests = st.text_area("Interests", placeholder="List their interests, hobbies, and preferences")
profession = st.text_input("Profession", placeholder="e.g., Software Engineer, Teacher")
income_level = st.text_input("Income Level", placeholder="e.g., $50,000 - $70,000 annually")
# Button for generating avatar
if st.button('Generate Customer Avatar'):
# Generating text profile
profile_prompt = f"Create a detailed customer avatar profile for: Name: {name}, Age: {age}, Gender: {gender}, Location: {location}, Interests: {interests}, Profession: {profession}, Income Level: {income_level}."
profile_response = openai.Completion.create(model="gpt-4", prompt=profile_prompt, max_tokens=150)
profile = profile_response.choices[0].text.strip()
st.subheader("Customer Avatar Profile:")
st.write(profile)
# Generating image
image_prompt = f"An image of a person who fits this profile: {profile_prompt}"
try:
image_response = openai.Image.create(model="dall-e", prompt=image_prompt, n=1)
image_url = image_response['data'][0]['url']
image = Image.open(BytesIO(requests.get(image_url).content))
st.image(image, caption='Generated Avatar Image')
except Exception as e:
st.error(f"Error in generating image: {e}")