bizvideoschool
commited on
Commit
•
85e1e8f
1
Parent(s):
757b271
Update app.py
Browse files
app.py
CHANGED
@@ -7,22 +7,28 @@ from io import BytesIO
|
|
7 |
# Access the OpenAI API key from Hugging Face Spaces secrets
|
8 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
9 |
|
10 |
-
st.title("Customer Avatar Generator")
|
11 |
|
12 |
# User inputs for avatar generation
|
|
|
13 |
business_type = st.text_input("Business Type", placeholder="e.g., Real Estate, Fitness")
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
if st.button('Generate Avatar'):
|
19 |
# Construct the prompt for text generation
|
20 |
-
prompt_text = f"Create a
|
21 |
|
22 |
# Call the OpenAI API for text generation
|
23 |
try:
|
24 |
response_text = openai.ChatCompletion.create(
|
25 |
-
model="gpt-4",
|
26 |
messages=[
|
27 |
{"role": "system", "content": "You are a helpful assistant."},
|
28 |
{"role": "user", "content": prompt_text}
|
@@ -32,28 +38,6 @@ if st.button('Generate Avatar'):
|
|
32 |
except Exception as e:
|
33 |
avatar_description = f"Error in generating avatar description: {e}"
|
34 |
|
35 |
-
#
|
36 |
-
prompt_image = f"A visual representation of a customer avatar for a {business_type} business. Demographics: {target_demographics}. Interests: {interests}."
|
37 |
-
|
38 |
-
# Call the DALL-E API for image generation
|
39 |
-
try:
|
40 |
-
response_image = openai.Image.create(
|
41 |
-
model="dall-e-3", # Specify DALL-E 3 model
|
42 |
-
prompt=prompt_image,
|
43 |
-
n=1,
|
44 |
-
size="1024x1024" # Set image dimensions
|
45 |
-
)
|
46 |
-
|
47 |
-
# Fetch the image from the URL
|
48 |
-
image_url = response_image['data'][0]['url']
|
49 |
-
image_response = requests.get(image_url)
|
50 |
-
image = Image.open(BytesIO(image_response.content))
|
51 |
-
except Exception as e:
|
52 |
-
image = None
|
53 |
-
st.error(f"Error in generating image: {e}")
|
54 |
-
|
55 |
-
# Display the results
|
56 |
st.write("**Avatar Description:**")
|
57 |
st.write(avatar_description)
|
58 |
-
if image:
|
59 |
-
st.image(image, caption='Generated Customer Avatar Image')
|
|
|
7 |
# Access the OpenAI API key from Hugging Face Spaces secrets
|
8 |
openai.api_key = st.secrets["OPENAI_API_KEY"]
|
9 |
|
10 |
+
st.title("Intuitive Customer Avatar Generator")
|
11 |
|
12 |
# User inputs for avatar generation
|
13 |
+
st.subheader("Tell Us About Your Business")
|
14 |
business_type = st.text_input("Business Type", placeholder="e.g., Real Estate, Fitness")
|
15 |
+
primary_service_or_product = st.text_input("Primary Service/Product", placeholder="e.g., Home sales, Personal training sessions")
|
16 |
+
unique_selling_points = st.text_input("Unique Selling Points", placeholder="What sets your business apart?")
|
17 |
+
business_location = st.text_input("Business Location", placeholder="City or region you primarily serve")
|
18 |
+
|
19 |
+
st.subheader("Your Customer Interactions")
|
20 |
+
most_common_customer_feedback = st.text_area("Common Customer Feedback", placeholder="What feedback do you often receive from customers?")
|
21 |
+
customer_challenges = st.text_input("Customer Challenges", placeholder="What challenges do your customers typically face?")
|
22 |
+
repeat_customer_characteristics = st.text_input("Repeat Customer Characteristics", placeholder="Any common traits among your repeat customers?")
|
23 |
|
24 |
if st.button('Generate Avatar'):
|
25 |
# Construct the prompt for text generation
|
26 |
+
prompt_text = f"Create a customer avatar based on the following business details: Business type: {business_type}, primary service/product: {primary_service_or_product}, unique selling points: {unique_selling_points}, business location: {business_location}. Customer feedback: {most_common_customer_feedback}, customer challenges: {customer_challenges}, repeat customer characteristics: {repeat_customer_characteristics}."
|
27 |
|
28 |
# Call the OpenAI API for text generation
|
29 |
try:
|
30 |
response_text = openai.ChatCompletion.create(
|
31 |
+
model="gpt-4",
|
32 |
messages=[
|
33 |
{"role": "system", "content": "You are a helpful assistant."},
|
34 |
{"role": "user", "content": prompt_text}
|
|
|
38 |
except Exception as e:
|
39 |
avatar_description = f"Error in generating avatar description: {e}"
|
40 |
|
41 |
+
# Display the avatar description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
st.write("**Avatar Description:**")
|
43 |
st.write(avatar_description)
|
|
|
|