JF
josh Furley

Video Generator - Copy this React, Tailwind Component to your project

Import json import requests import time api_key = "<YOUR_API_KEY>" authorization = "Bearer %s" % api_key headers = { "accept": "application/json", "content type": "application/json", "authorization": authorization } # Get a presigned URL for uploading an image url = "https://cloud.leonardo.ai/api/rest/v1/init image" payload = {"extension": "jpg"} response = requests.post(url, json=payload, headers=headers) print("Get a presigned URL for uploading an image: %s" % response.status_code) # Upload image via presigned URL fields = json.loads(response.json()['uploadInitImage']['fields']) url = response.json()['uploadInitImage']['url'] image_id = response.json()['uploadInitImage']['id'] # For getting the image later image_file_path = "/workspace/test.jpg" files = {'file': open(image_file_path, 'rb')} response = requests.post(url, data=fields, files=files) # Header is not needed print("Upload image via presigned URL: %s" % response.status_code) # Generate video with an init image url = "https://cloud.leonardo.ai/api/rest/v1/generations motion svd" payload = { "imageId": image_id, "isInitImage": True, "motionStrength": 5 } response = requests.post(url, json=payload, headers=headers) print("Generate video with an init image: %s" % response.status_code) # Get the generated video generation_id = response.json()['motionSvdGenerationJob']['generationId'] url = "https://cloud.leonardo.ai/api/rest/v1/generations/%s" % generation_id time.sleep(60) response = requests.get(url, headers=headers) print(response.text)

Prompt
Component Preview

About

VideoGenerator - Create stunning videos from images with ease. Built with React and Tailwind, it supports image uploads and video gene. Get instant access!

Share

Last updated 1 month ago