bizvideoschool commited on
Commit
c91c212
1 Parent(s): 59895d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -34
app.py CHANGED
@@ -1,42 +1,38 @@
1
  import streamlit as st
2
  import openai
 
 
 
3
 
4
- # Set up the OpenAI API key from Hugging Face Spaces secrets
5
- openai.api_key = st.secrets["OPENAI_API_KEY"]
6
 
7
  st.title("Customer Avatar Generator")
8
 
9
- # User inputs for generating the customer avatar
10
- business_type = st.text_input("Business Type", "Enter the type of your business (e.g., Real Estate, E-commerce)")
11
- target_market = st.text_input("Target Market", "Describe your target market (e.g., first-time home buyers, fitness enthusiasts)")
12
- unique_selling_points = st.text_area("Unique Selling Points", "What sets your business apart from competitors? (e.g., personalized service, affordable pricing)")
13
- customer_challenges = st.text_area("Customer Challenges", "What challenges do your customers face that your business solves? (e.g., finding affordable housing, achieving fitness goals)")
14
-
15
- submit_button = st.button("Generate Customer Avatar")
16
-
17
- if submit_button:
18
- # Construct the prompt for the AI
19
- prompt = f"""
20
- Generate a detailed customer avatar for a business.
21
- Business Type: {business_type}
22
- Target Market: {target_market}
23
- Unique Selling Points: {unique_selling_points}
24
- Customer Challenges: {customer_challenges}
25
- """
26
-
27
- # Call the OpenAI API
 
28
  try:
29
- response = openai.Completion.create(
30
- model="gpt-4", # Specify GPT-4 model
31
- prompt=prompt,
32
- max_tokens=500, # Adjust based on the required length of the avatar
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"An error occurred: {e}")
 
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}")