ovi054 commited on
Commit
06fee64
·
verified ·
1 Parent(s): 2a45d5a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import HunyuanVideoPipeline, HunyuanVideoTransformer3DModel
3
+ from PIL import Image
4
+ import numpy as np
5
+ import gradio as gr
6
+ import os
7
+ import gc
8
+
9
+
10
+ model_id = "hunyuanvideo-community/HunyuanVideo"
11
+ transformer = HunyuanVideoTransformer3DModel.from_pretrained(
12
+ model_id, subfolder="transformer", torch_dtype=torch.bfloat16
13
+ )
14
+
15
+
16
+ pipe = HunyuanVideoPipeline.from_pretrained(model_id, transformer=transformer, torch_dtype=torch.float16)
17
+ pipe.vae.enable_tiling()
18
+ pipe.load_lora_weights("ovi054/ovimxVid")
19
+ pipe.to("cuda")
20
+
21
+
22
+ def generate(prompt, negative_prompt, width=1280, height=720, num_inference_steps=30, progress=gr.Progress(track_tqdm=True)):
23
+ try:
24
+ output = pipe(
25
+ prompt=prompt,
26
+ # negative_prompt=negative_prompt,
27
+ height=height,
28
+ width=width,
29
+ num_frames=1,
30
+ num_inference_steps=num_inference_steps,
31
+ # guidance_scale=5.0,
32
+ ).frames[0][0]
33
+ # image = (output * 255).astype(np.uint8)
34
+ # return Image.fromarray(image)
35
+ return output
36
+ finally:
37
+ # Always clear memory, even if an error occurs
38
+ torch.cuda.empty_cache()
39
+ gc.collect()
40
+
41
+
42
+ iface = gr.Interface(
43
+ fn=generate,
44
+ inputs=[
45
+ gr.Textbox(label="Input prompt"),
46
+ ],
47
+ additional_inputs = [
48
+ 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"),
49
+ gr.Slider(label="Width", minimum=480, maximum=1280, step=16, value=832),
50
+ gr.Slider(label="Height", minimum=480, maximum=1280, step=16, value=832),
51
+ gr.Slider(minimum=1, maximum=80, step=1, label="Inference Steps", value=30)
52
+ ],
53
+ outputs=gr.Image(label="output"),
54
+ )
55
+
56
+
57
+ iface.launch(share=True, debug=True)