File size: 1,903 Bytes
bf70abc
0a480c8
c91c212
 
 
c1fbddd
c91c212
 
bf70abc
59895d9
f23c1ac
c91c212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3215c8
c91c212
 
 
 
a3215c8
c91c212
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
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}")