from diffusers import DiffusionPipeline import gradio as gr import torch import cv2 import os MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD') device = "cuda" if torch.cuda.is_available() else "cpu" pipe = DiffusionPipeline.from_pretrained( "CompVis/stable-diffusion-v1-4", use_auth_token=MY_SECRET_TOKEN, #revision='fp16', #torch_dtype=torch.float16, safety_checker=None, # Very important for videos...lots of false positives while interpolating custom_pipeline="interpolate_stable_diffusion", ).to(device) pipe.enable_attention_slicing() def run(prompt1, seed1, prompt2, seed2, prompt3, seed3): frame_filepaths = pipe.walk( prompts=[prompt1, prompt2, prompt3], seeds=[seed1, seed2, seed3], num_interpolation_steps=16, output_dir='./dreams', batch_size=4, height=512, width=512, guidance_scale=8.5, num_inference_steps=50, ) print(frame_filepaths) frame = cv2.imread(frame_filepaths[0]) height, width, layers = frame.shape fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') video = cv2.VideoWriter("out.mp4", fourcc, 24, (width,height)) for image in frame_filepaths: #print(image) video.write(cv2.imread(image)) video.release() cv2.destroyAllWindows() #print(video) return "out.mp4", frame_filepaths with gr.Blocks() as demo: with gr.Column(): gr.HTML('''
This community pipeline returns a list of images saved under the folder as defined in output_dir.
You can use these images to create videos of stable diffusion.
This demo can be run on a GPU of at least 8GB VRAM and should take approximately 5 minutes.
—