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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -36
app.py CHANGED
@@ -1,54 +1,42 @@
1
  import streamlit as st
2
  import openai
3
- import requests
4
- from PIL import Image
5
- from io import BytesIO
6
 
7
  # Set up the OpenAI API key from Hugging Face Spaces secrets
8
  openai.api_key = st.secrets["OPENAI_API_KEY"]
9
 
10
- st.title("Holiday Video Backdrop Image Generator")
11
 
12
- # User inputs for image generation
13
- image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your holiday video backdrop (e.g., festive living room, snowy landscape)")
14
- color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., red and green, white and blue)")
15
- additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the image (e.g., Christmas tree, snowflakes)")
 
16
 
17
- # Dropdown for selecting image dimensions
18
- video_format = st.selectbox("Video Format", ["16:9 (Standard HD - 1920x1080)", "16:9 (4K - 3840x2160)", "1:1 (Square - 1080x1080)", "4:5 (Portrait - 1080x1350)", "9:16 (Tall - 1080x1920)"])
19
 
20
- # Mapping formats to DALL-E API size parameters
21
- format_size_mapping = {
22
- "16:9 (Standard HD - 1920x1080)": "1024x576", # Closest available size in DALL-E for 1080p
23
- "16:9 (4K - 3840x2160)": "1792x1024", # Closest available size in DALL-E for 4K
24
- "1:1 (Square - 1080x1080)": "1024x1024",
25
- "4:5 (Portrait - 1080x1350)": "1024x1792", # Closest available vertical size
26
- "9:16 (Tall - 1080x1920)": "1024x1792" # Closest available vertical size
27
- }
 
28
 
29
- if st.button('Generate Image'):
30
- # Construct the prompt
31
- prompt = f"A holiday-themed backdrop image depicting: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'."
32
-
33
- # Call the DALL-E API
34
  try:
35
- response = openai.Image.create(
36
- model="dall-e-3", # Specify DALL-E 3 model
37
  prompt=prompt,
38
- n=1,
39
- size=format_size_mapping[video_format], # Set image dimensions based on selected video format
40
- quality="hd" # Set image quality to high definition
41
  )
42
 
43
- # Assuming the response contains a URL to the image
44
- image_url = response['data'][0]['url']
45
-
46
- # Fetch the image from the URL
47
- image_response = requests.get(image_url)
48
- image = Image.open(BytesIO(image_response.content))
49
 
50
- # Display the image
51
- st.image(image, caption='Generated Holiday Backdrop Image')
 
52
 
53
  except Exception as e:
54
  st.error(f"An error occurred: {e}")
 
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}")