bizvideoschool commited on
Commit
a2b71e3
1 Parent(s): 85e1e8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -7,7 +7,7 @@ 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("Intuitive Customer Avatar Generator")
11
 
12
  # User inputs for avatar generation
13
  st.subheader("Tell Us About Your Business")
@@ -21,9 +21,15 @@ most_common_customer_feedback = st.text_area("Common Customer Feedback", placeho
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:
@@ -38,6 +44,34 @@ if st.button('Generate Avatar'):
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 & Content Pillar Generator")
11
 
12
  # User inputs for avatar generation
13
  st.subheader("Tell Us About Your Business")
 
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 and Content Pillars'):
25
  # Construct the prompt for text generation
26
+ prompt_text = (
27
+ f"Create a detailed customer avatar and suggest content pillars based on the following business details: "
28
+ f"Business type: {business_type}, primary service/product: {primary_service_or_product}, "
29
+ f"unique selling points: {unique_selling_points}, business location: {business_location}. "
30
+ f"Customer feedback: {most_common_customer_feedback}, customer challenges: {customer_challenges}, "
31
+ f"repeat customer characteristics: {repeat_customer_characteristics}."
32
+ )
33
 
34
  # Call the OpenAI API for text generation
35
  try:
 
44
  except Exception as e:
45
  avatar_description = f"Error in generating avatar description: {e}"
46
 
47
+ # Display the avatar description with formatted headers
48
+ st.markdown("### Customer Avatar Description")
49
+ st.write(avatar_description.split('\n\n')[0]) # Assuming the avatar description is the first paragraph
50
+ st.markdown("### Content Pillars Recommendations")
51
+ st.write('\n'.join(avatar_description.split('\n\n')[1:])) # Assuming the rest is content pillars
52
+
53
+ # Additional prompt for image generation
54
+ prompt_image = f"An image representing the customer avatar based on the business type: {business_type}, and customer characteristics: {repeat_customer_characteristics}."
55
+
56
+ # Call the OpenAI API for image generation
57
+ try:
58
+ response_image = openai.Image.create(
59
+ model="dall-e-2", # Specify DALL-E model
60
+ prompt=prompt_image,
61
+ n=1,
62
+ size="1024x1024" # Set image dimensions
63
+ )
64
+
65
+ # Assuming the response contains a URL to the image
66
+ image_url = response_image['data'][0]['url']
67
+
68
+ # Fetch the image from the URL
69
+ image_response = requests.get(image_url)
70
+ image = Image.open(BytesIO(image_response.content))
71
+
72
+ # Display the image with a header
73
+ st.markdown("### Generated Customer Avatar Image")
74
+ st.image(image, caption='Generated Customer Avatar Image')
75
+
76
+ except Exception as e:
77
+ st.error(f"Error in generating image: {e}")