bizvideoschool commited on
Commit
a3215c8
1 Parent(s): 175d43a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -15
app.py CHANGED
@@ -1,14 +1,18 @@
1
  import streamlit as st
2
  import openai
 
 
 
3
 
4
- # Access the OpenAI API key
5
- openai.api_key = st.secrets["YOUR_OPENAI_API_KEY"]
 
6
 
7
- st.title("Real Estate Video Background Image Generator")
8
 
9
- # User inputs for image generation
10
- image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your image (e.g., cozy living room, modern office)")
11
- color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., warm, cool, monochromatic)")
12
  additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the image?")
13
 
14
  if st.button('Generate Image'):
@@ -16,12 +20,22 @@ if st.button('Generate Image'):
16
  prompt = f"Create an image with the theme: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'."
17
 
18
  # Call the DALL-E API
19
- response = openai.Image.create(
20
- prompt=prompt,
21
- n=1, # Number of images to generate
22
- size="1024x1024" # Image dimensions
23
- )
24
-
25
- # Display the image
26
- image_data = response.data[0] # Assuming response contains image data
27
- st.image(image_data, caption='Generated Image')
 
 
 
 
 
 
 
 
 
 
 
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
+ # Ensure that you have added your OpenAI API key in the Hugging Face Spaces secrets under the name "OPENAI_API_KEY"
9
+ openai.api_key = st.secrets["OPENAI_API_KEY"]
10
 
11
+ st.title("Background Image Generator for Real Estate Videos")
12
 
13
+ # User inputs
14
+ image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your image (e.g., modern living room)")
15
+ color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., warm, cool)")
16
  additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the image?")
17
 
18
  if st.button('Generate Image'):
 
20
  prompt = f"Create an image with the theme: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'."
21
 
22
  # Call the DALL-E API
23
+ try:
24
+ response = openai.Image.create(
25
+ prompt=prompt,
26
+ n=1, # Number of images to generate
27
+ size="1024x1024" # Image dimensions
28
+ )
29
+
30
+ # Assuming the response contains a URL to the image
31
+ image_url = response['data'][0]['url']
32
+
33
+ # Fetch the image from the URL
34
+ image_response = requests.get(image_url)
35
+ image = Image.open(BytesIO(image_response.content))
36
+
37
+ # Display the image
38
+ st.image(image, caption='Generated Image')
39
+
40
+ except Exception as e:
41
+ st.error(f"An error occurred: {e}")