feat: use i2vgenxl
Browse files
app.py
CHANGED
|
@@ -1,14 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import torchvision
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
def generate(prompt: str):
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return "video.mp4"
|
| 9 |
|
| 10 |
-
gr.Interface(
|
| 11 |
fn=generate,
|
| 12 |
-
inputs="text",
|
| 13 |
outputs=gr.Video()
|
| 14 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import torchvision
|
| 4 |
+
from diffusers import I2VGenXLPipeline
|
| 5 |
+
from diffusers.utils.loading_utils import load_image
|
| 6 |
+
from PIL import Image
|
| 7 |
|
| 8 |
+
def generate(image: Image.Image, prompt: str):
|
| 9 |
+
negative_prompt = "Distorted, discontinuous, Ugly, blurry, low resolution, motionless, static, disfigured, disconnected limbs, Ugly faces, incomplete arms"
|
| 10 |
+
generator = torch.manual_seed(8888)
|
| 11 |
+
image = image.convert("RGB")
|
| 12 |
+
pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
|
| 13 |
+
pipeline.enable_model_cpu_offload()
|
| 14 |
+
pipeline.unet.enable_forward_chunking()
|
| 15 |
+
frames = pipeline(
|
| 16 |
+
prompt=prompt,
|
| 17 |
+
image=image,
|
| 18 |
+
num_inference_steps=50,
|
| 19 |
+
negative_prompt=negative_prompt,
|
| 20 |
+
guidance_scale=9.0,
|
| 21 |
+
generator=generator,
|
| 22 |
+
decode_chunk_size=6,
|
| 23 |
+
).frames[0]
|
| 24 |
+
torchvision.io.write_video("video.mp4", frames, fps=16)
|
| 25 |
return "video.mp4"
|
| 26 |
|
| 27 |
+
app = gr.Interface(
|
| 28 |
fn=generate,
|
| 29 |
+
inputs=[gr.Image(type="pil"), "text"],
|
| 30 |
outputs=gr.Video()
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
app.launch()
|
| 35 |
+
|