upstatestack/TikTok-Video-Image-Generator
0
1import streamlit as st2import openai3import requests4from PIL import Image5from io import BytesIO6 7# Set up the OpenAI API key from Hugging Face Spaces secrets8openai.api_key = st.secrets["OPENAI_API_KEY"]9 10st.title("Short-Form Video Backdrop and Image Generator")11 12# User inputs for image generation13st.subheader("Define Your Business")14business_type = st.text_input("Your Business Type", placeholder="e.g., Cafe, Florist, Yoga Studio")15 16st.subheader("Video Backdrop Details")17video_theme = st.text_input("Video Theme", placeholder="Enter a theme for your TikTok video (e.g., cozy cafe, floral arrangement, yoga session)")18color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., pastel, vibrant, earth tones)")19additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the backdrop (e.g., coffee cups, flowers, yoga mats)")20 21if st.button('Generate Image'):22 # Construct the prompt23 prompt = f"Create a vertical image that could be used in the background of a video on TikTok or Reels for a {business_type}. Theme: '{video_theme}', color scheme: '{color_scheme}', including elements: '{additional_elements}'."24 25 # Call the DALL-E API26 try:27 response = openai.Image.create(28 model="dall-e-3", # Specify DALL-E 3 model29 prompt=prompt,30 n=1,31 size="1024x1792", # Set image dimensions to vertical32 quality="standard" # Set image quality to standard for lower cost33 )34 35 # Assuming the response contains a URL to the image36 image_url = response['data'][0]['url']37 38 # Fetch the image from the URL39 image_response = requests.get(image_url)40 image = Image.open(BytesIO(image_response.content))41 42 # Display the image43 st.image(image, caption='Generated Business Video Backdrop Image')44 45 except Exception as e:46 st.error(f"An error occurred: {e}")47 