Lazy Image to Video

 import os, base64
from flask import request, jsonify
import logging

from flask import Flask, render_template
from import BaseApplication

logging.basicConfig(level=logging.DEBUG)  # Changed logging level to DEBUG for more detailed logs
logger = logging.getLogger(__name__)

app = Flask(__name__)

@app.route("/generate", methods=['POST'])
def generate_video():
    import requests
    logger.debug("Received request to generate video")
    if 'image' not in request.files:
        logger.error("No image file provided")
        return jsonify(error="No image file provided. Please ensure the form-data key is 'image' and a file is attached."), 400
    image = request.files['image']
    # Convert form data to string to ensure compatibility
    seed = str(request.form.get('seed', "0"))
    cfg_scale = str(request.form.get('cfg_scale', "1.8"))
    motion_bucket_id = str(request.form.get('motion_bucket_id', "127"))

About this template

Lazy Image to Video using stability ai to generate video clips based on their image to video model.

Introduction to the Lazy Image to Video Template

Welcome to the Lazy Image to Video template! This template allows you to create a web application that uses Stability AI to generate video clips from images. It's a perfect solution for builders looking to integrate advanced AI-powered video generation into their projects without worrying about the complexities of deployment and environment setup.

Getting Started

To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy or paste any code manually.

Initial Setup

Before testing the application, you'll need to set up an environment secret for the Stability API key. Here's how to do it:

  • Go to the Stability AI website and create an account if you haven't already.
  • Once logged in, navigate to the API section and generate a new API key.
  • Copy the API key provided by Stability AI.
  • In the Lazy Builder interface, go to the Environment Secrets tab.
  • Create a new secret with the key STABILITY_API_KEY and paste the API key you copied as the value.

Test: Deploying the App

With the environment secret set, you're ready to deploy the app. Press the "Test" button in the Lazy Builder interface. This will start the deployment process and launch the Lazy CLI. You will not be prompted for any user input at this stage, as the template does not require CLI input.

Using the App

Once the app is deployed, Lazy will provide you with a dedicated server link. Use this link to access the web interface of your Image to Video application. Here's how to use the interface:

  • Upload an image using the provided form.
  • Click on "Generate Video" to start the video generation process.
  • After submission, you will receive a video ID. Use this ID to poll for the status of your video generation.
  • Once the video is ready, you will be able to view and download it directly from the web interface.

Integrating the App

If you wish to integrate this video generation feature into another service or frontend, you can use the server link provided by Lazy to make API calls to the /generate and /poll/{id} endpoints. Here's a sample request to start video generation:

POST /generate
Content-Type: multipart/form-data
Authorization: Bearer YOUR_STABILITY_API_KEY

  "image": "data:image/jpeg;base64,...", // Base64 encoded image
  "seed": "0",
  "cfg_scale": "1.8",
  "motion_bucket_id": "127"

And here's a sample request to poll the status of the video generation:

GET /poll/{video_id}
Accept: video/*
Authorization: Bearer YOUR_STABILITY_API_KEY

Replace YOUR_STABILITY_API_KEY with the actual API key and {video_id} with the ID you received after generating the video.

For further details on the Stability AI API, refer to the official documentation provided by Stability AI.

By following these steps, you can easily set up and integrate the Lazy Image to Video template into your project, leveraging the power of AI to enhance your application's capabilities.

Last published
May 18, 2024

More templates like this

GPT-4o Reminders WhatsApp bot

This bot uses GPT-4o to give Whatsapp-based reminders to people just by chatting.


Context Aware Chat API

A simple chat API for user interaction with a large language model.


DALL-E 3 QuickStart API

Do you want to integrate with DALL-E 3 quickly? Well, all you need for this API to work is your OpenAI API key and you have a usable DALL-E 3 server in minutes! It takes in a prompt and responds with a URL to your new image.

Lazy Image to Video