Spaces:
Runtime error
Runtime error
bizvideoschool
commited on
Commit
•
a3215c8
1
Parent(s):
175d43a
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,18 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
|
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
6 |
|
7 |
-
st.title("
|
8 |
|
9 |
-
# User inputs
|
10 |
-
image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your image (e.g.,
|
11 |
-
color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., warm, cool
|
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 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}")
|