|
import streamlit as st |
|
import openai |
|
import requests |
|
from PIL import Image |
|
from io import BytesIO |
|
|
|
|
|
openai.api_key = st.secrets["OPENAI_API_KEY"] |
|
|
|
st.title("Background Image Generator for Real Estate Videos") |
|
|
|
|
|
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) |
|
image_quality = st.selectbox("Image Quality", ["standard", "hd"], index=0) |
|
|
|
if st.button('Generate Image'): |
|
|
|
prompt = f"Create an image with the theme: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'." |
|
|
|
|
|
try: |
|
response = openai.Image.create( |
|
model="dall-e-3", |
|
prompt=prompt, |
|
n=1, |
|
size="1024x1024", |
|
quality=image_quality, |
|
style=image_style |
|
) |
|
|
|
|
|
image_url = response['data'][0]['url'] |
|
|
|
|
|
image_response = requests.get(image_url) |
|
image = Image.open(BytesIO(image_response.content)) |
|
|
|
|
|
st.image(image, caption='Generated Image') |
|
|
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
|