File size: 2,111 Bytes
06fee64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
from diffusers import HunyuanVideoPipeline, HunyuanVideoTransformer3DModel
from PIL import Image
import numpy as np
import gradio as gr
import os
import gc


model_id = "hunyuanvideo-community/HunyuanVideo"
transformer = HunyuanVideoTransformer3DModel.from_pretrained(
    model_id, subfolder="transformer", torch_dtype=torch.bfloat16
    )


pipe = HunyuanVideoPipeline.from_pretrained(model_id, transformer=transformer, torch_dtype=torch.float16)
pipe.vae.enable_tiling()
pipe.load_lora_weights("ovi054/ovimxVid")
pipe.to("cuda")


def generate(prompt, negative_prompt, width=1280, height=720, num_inference_steps=30, progress=gr.Progress(track_tqdm=True)):
    try:
        output = pipe(
            prompt=prompt,
            # negative_prompt=negative_prompt,
            height=height,
            width=width,
            num_frames=1,
            num_inference_steps=num_inference_steps,
            # guidance_scale=5.0,
        ).frames[0][0]
        # image = (output * 255).astype(np.uint8)
        # return Image.fromarray(image)
        return output
    finally:
        # Always clear memory, even if an error occurs
        torch.cuda.empty_cache()
        gc.collect()


iface = gr.Interface(
    fn=generate,
    inputs=[
        gr.Textbox(label="Input prompt"),
    ],
    additional_inputs = [
        gr.Textbox(label="Negative prompt", value = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"),
        gr.Slider(label="Width", minimum=480, maximum=1280, step=16, value=832),
        gr.Slider(label="Height", minimum=480, maximum=1280, step=16, value=832),
        gr.Slider(minimum=1, maximum=80, step=1, label="Inference Steps", value=30)
    ],
    outputs=gr.Image(label="output"),
)


iface.launch(share=True, debug=True)