bizvideoschool
commited on
Commit
•
c91c212
1
Parent(s):
59895d9
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,38 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
|
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
openai.api_key =
|
6 |
|
7 |
st.title("Customer Avatar Generator")
|
8 |
|
9 |
-
# User inputs for
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
Customer
|
25 |
-
|
26 |
-
|
27 |
-
#
|
|
|
28 |
try:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
)
|
34 |
-
|
35 |
-
avatar = response.choices[0].text.strip()
|
36 |
-
|
37 |
-
# Display the customer avatar
|
38 |
-
st.subheader("Generated Customer Avatar")
|
39 |
-
st.write(avatar)
|
40 |
-
|
41 |
except Exception as e:
|
42 |
-
st.error(f"
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
+
import requests
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
+
# Setup OpenAI API key (ensure it's set in environment variables)
|
8 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
9 |
|
10 |
st.title("Customer Avatar Generator")
|
11 |
|
12 |
+
# User inputs for avatar generation
|
13 |
+
name = st.text_input("Customer's Name", placeholder="Enter a name for your customer avatar")
|
14 |
+
age = st.text_input("Age Range", placeholder="e.g., 30-40 years")
|
15 |
+
gender = st.selectbox("Gender", ["Female", "Male", "Non-binary", "Prefer not to say"])
|
16 |
+
location = st.text_input("Location", placeholder="e.g., Urban, Suburban, Rural")
|
17 |
+
interests = st.text_area("Interests", placeholder="List their interests, hobbies, and preferences")
|
18 |
+
profession = st.text_input("Profession", placeholder="e.g., Software Engineer, Teacher")
|
19 |
+
income_level = st.text_input("Income Level", placeholder="e.g., $50,000 - $70,000 annually")
|
20 |
+
|
21 |
+
# Button for generating avatar
|
22 |
+
if st.button('Generate Customer Avatar'):
|
23 |
+
# Generating text profile
|
24 |
+
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}."
|
25 |
+
profile_response = openai.Completion.create(model="gpt-4", prompt=profile_prompt, max_tokens=150)
|
26 |
+
profile = profile_response.choices[0].text.strip()
|
27 |
+
st.subheader("Customer Avatar Profile:")
|
28 |
+
st.write(profile)
|
29 |
+
|
30 |
+
# Generating image
|
31 |
+
image_prompt = f"An image of a person who fits this profile: {profile_prompt}"
|
32 |
try:
|
33 |
+
image_response = openai.Image.create(model="dall-e", prompt=image_prompt, n=1)
|
34 |
+
image_url = image_response['data'][0]['url']
|
35 |
+
image = Image.open(BytesIO(requests.get(image_url).content))
|
36 |
+
st.image(image, caption='Generated Avatar Image')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
except Exception as e:
|
38 |
+
st.error(f"Error in generating image: {e}")
|