Spaces:
Runtime error
Runtime error
File size: 6,079 Bytes
eb65e9e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
import gradio as gr
import numpy as np
import torch
from video_diffusion.stable_diffusion_video.stable_diffusion_pipeline import StableDiffusionWalkPipeline
from video_diffusion.utils.model_list import stable_model_list
class StableDiffusionText2VideoGenerator:
def __init__(self):
self.pipe = None
def load_model(
self,
model_path,
):
if self.pipe is None:
self.pipe = StableDiffusionWalkPipeline.from_pretrained(
model_path,
torch_dtype=torch.float16,
revision="fp16",
)
self.pipe.to("cuda")
self.pipe.enable_xformers_memory_efficient_attention()
self.pipe.enable_attention_slicing()
return self.pipe
def generate_video(
self,
model_path: str,
first_prompts: str,
second_prompts: str,
negative_prompt: str,
num_interpolation_steps: int,
guidance_scale: int,
num_inference_step: int,
height: int,
width: int,
upsample: bool,
fps=int,
):
first_seed = np.random.randint(0, 100000)
second_seed = np.random.randint(0, 100000)
seeds = [first_seed, second_seed]
prompts = [first_prompts, second_prompts]
pipe = self.load_model(model_path=model_path)
output_video = pipe.walk(
prompts=prompts,
num_interpolation_steps=int(num_interpolation_steps),
height=height,
width=width,
guidance_scale=guidance_scale,
num_inference_steps=num_inference_step,
negative_prompt=negative_prompt,
seeds=seeds,
upsample=upsample,
fps=fps,
)
return output_video
def app():
with gr.Blocks():
with gr.Row():
with gr.Column():
stable_text2video_first_prompt = gr.Textbox(
lines=1,
placeholder="First Prompt",
show_label=False,
)
stable_text2video_second_prompt = gr.Textbox(
lines=1,
placeholder="Second Prompt",
show_label=False,
)
stable_text2video_negative_prompt = gr.Textbox(
lines=1,
placeholder="Negative Prompt ",
show_label=False,
)
with gr.Row():
with gr.Column():
stable_text2video_model_path = gr.Dropdown(
choices=stable_model_list,
label="Stable Model List",
value=stable_model_list[0],
)
stable_text2video_guidance_scale = gr.Slider(
minimum=0,
maximum=15,
step=1,
value=8.5,
label="Guidance Scale",
)
stable_text2video_num_inference_steps = gr.Slider(
minimum=1,
maximum=100,
step=1,
value=30,
label="Number of Inference Steps",
)
stable_text2video_fps = gr.Slider(
minimum=1,
maximum=60,
step=1,
value=10,
label="Fps",
)
with gr.Row():
with gr.Column():
stable_text2video_num_interpolation_steps = gr.Number(
value=10,
label="Number of Interpolation Steps",
)
stable_text2video_height = gr.Slider(
minimum=1,
maximum=1000,
step=1,
value=512,
label="Height",
)
stable_text2video_width = gr.Slider(
minimum=1,
maximum=1000,
step=1,
value=512,
label="Width",
)
stable_text2video_upsample = gr.Checkbox(
label="Upsample",
default=False,
)
text2video_generate = gr.Button(value="Generator")
with gr.Column():
text2video_output = gr.Video(label="Output")
text2video_generate.click(
fn=StableDiffusionText2VideoGenerator().generate_video,
inputs=[
stable_text2video_model_path,
stable_text2video_first_prompt,
stable_text2video_second_prompt,
stable_text2video_negative_prompt,
stable_text2video_num_interpolation_steps,
stable_text2video_guidance_scale,
stable_text2video_num_inference_steps,
stable_text2video_height,
stable_text2video_width,
stable_text2video_upsample,
stable_text2video_fps,
],
outputs=text2video_output,
)
|