bizvideoschool's picture
Update app.py
a7cf0d8 verified
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("Valentine's Day Video Backdrop Generator")
# User inputs for image generation
st.subheader("Define Your Business")
business_type = st.text_input("Your Business Type", placeholder="e.g., Cafe, Florist, Jewelry Store")
st.subheader("Valentine's Day Backdrop Details")
video_theme = st.text_input("Video Theme", placeholder="Valentine's Day theme for your video (e.g., romantic dinner, bouquet of flowers, gift showcase)")
color_scheme = st.text_input("Color Scheme", placeholder="Valentine's Day color scheme (e.g., red and white, pink and gold)")
additional_elements = st.text_input("Additional Elements", placeholder="Valentine's Day specific elements to include (e.g., hearts, chocolates, candles)")
if st.button('Generate Image'):
# Construct the prompt for Valentine's Day theme
prompt = f"Create a vertical image for a {business_type} with a Valentine's Day theme: '{video_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'. This image will be used as a backdrop for a TikTok or Instagram Reels video."
# Call the DALL-E API
try:
response = openai.Image.create(
model="dall-e-3", # Specify DALL-E 3 model
prompt=prompt,
n=1,
size="1024x1792", # Set image dimensions to vertical for TikTok or Reels
quality="standard" # Set image quality to standard for lower cost
)
# 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 Valentine\'s Day Video Backdrop Image')
except Exception as e:
st.error(f"An error occurred: {e}")