|
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("Holiday Video Backdrop Image Generator") |
|
|
|
|
|
image_theme = st.text_input("Image Theme", placeholder="Enter a theme for your holiday video backdrop (e.g., festive living room, snowy landscape)") |
|
color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., red and green, white and blue)") |
|
additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the image (e.g., Christmas tree, snowflakes)") |
|
|
|
|
|
video_format = st.selectbox("Video Format", ["16:9 (Standard HD - 1920x1080)", "1:1 (Square - 1080x1080)", "4:5 (Portrait - 1080x1350)"]) |
|
|
|
|
|
format_size_mapping = { |
|
"16:9 (Standard HD - 1920x1080)": "1024x576", |
|
"1:1 (Square - 1080x1080)": "1024x1024", |
|
"4:5 (Portrait - 1080x1350)": "1024x768", |
|
} |
|
|
|
if st.button('Generate Image'): |
|
|
|
prompt = f"A holiday-themed backdrop image depicting: '{image_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'." |
|
|
|
|
|
try: |
|
response = openai.Image.create( |
|
model="dall-e-3", |
|
prompt=prompt, |
|
n=1, |
|
size=format_size_mapping[video_format], |
|
quality="standard" |
|
) |
|
|
|
|
|
image_url = response['data'][0]['url'] |
|
|
|
|
|
image_response = requests.get(image_url) |
|
image = Image.open(BytesIO(image_response.content)) |
|
|
|
|
|
st.image(image, caption='Generated Holiday Backdrop Image') |
|
|
|
except Exception as e: |
|
st.error(f"An error occurred: {e}") |
|
|