Download app.py from upstatestack/TikTok-Video-Image-Generator: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/spaces/upstatestack/TikTok-Video-Image-Generator/resolve/main/app.py
- Command line
-
hf download hf://spaces/upstatestack/TikTok-Video-Image-Generator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/upstatestack/TikTok-Video-Image-Generator/resolve/main/app.py
1.97 kB
| 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("Short-Form Video Backdrop and Image Generator") | |
| # User inputs for image generation | |
| st.subheader("Define Your Business") | |
| business_type = st.text_input("Your Business Type", placeholder="e.g., Cafe, Florist, Yoga Studio") | |
| st.subheader("Video Backdrop Details") | |
| video_theme = st.text_input("Video Theme", placeholder="Enter a theme for your TikTok video (e.g., cozy cafe, floral arrangement, yoga session)") | |
| color_scheme = st.text_input("Color Scheme", placeholder="Preferred color scheme (e.g., pastel, vibrant, earth tones)") | |
| additional_elements = st.text_input("Additional Elements", placeholder="Any specific elements to include in the backdrop (e.g., coffee cups, flowers, yoga mats)") | |
| if st.button('Generate Image'): | |
| # Construct the prompt | |
| 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}'." | |
| # 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 | |
| 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 Business Video Backdrop Image') | |
| except Exception as e: | |
| st.error(f"An error occurred: {e}") | |