File size: 1,858 Bytes
bf70abc
0a480c8
a3215c8
 
 
c1fbddd
a3215c8
 
bf70abc
a3215c8
f23c1ac
a3215c8
 
 
175d43a
a0464cb
 
3cd9850
175d43a
 
 
3cd9850
175d43a
a3215c8
 
a0464cb
a3215c8
 
a0464cb
 
 
a3215c8
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
import openai
import requests
from PIL import Image
from io import BytesIO

# Set up the OpenAI API key from Hugging Face Spaces secrets
openai.api_key = st.secrets["OPENAI_API_KEY"]

st.title("Background Image Generator for Real Estate Videos")

# User inputs
image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your image (e.g., modern living room)")
color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., warm, cool)")
additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the image?")
image_style = st.selectbox("Image Style", ["vivid", "natural"], index=0)  # Select between vivid and natural styles
image_quality = st.selectbox("Image Quality", ["standard", "hd"], index=0)  # Select between standard and HD quality

if st.button('Generate Image'):
    # Construct the prompt
    prompt = f"Create an image with the theme: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'."

    # Call the DALL-E API
    try:
        response = openai.Image.create(
            model="dall-e-3",  # Specify DALL-E 3 model
            prompt=prompt,
            n=1,  # Number of images to generate
            size="1024x1024",  # Image dimensions
            quality=image_quality,  # Image quality parameter
            style=image_style  # Image style parameter
        )

        # Assuming the response contains a URL to the image
        image_url = response['data'][0]['url']
        
        # Fetch the image from the URL
        image_response = requests.get(image_url)
        image = Image.open(BytesIO(image_response.content))

        # Display the image
        st.image(image, caption='Generated Image')

    except Exception as e:
        st.error(f"An error occurred: {e}")