Hunyuan-Image / app.py
ovi054's picture
Create app.py
06fee64 verified
raw
history blame
2.11 kB
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)