Spaces:
Build error
Build error
v1
Browse files- README.md +2 -2
- app.py +7 -0
- demo_app.py +110 -0
- packages.txt +4 -0
- requirements.txt +48 -0
- utils.py +40 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
title: Huanyan Studio
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
1 |
---
|
2 |
title: Huanyan Studio
|
3 |
+
emoji: ✨
|
4 |
colorFrom: blue
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.16.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
app.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from utils import install_packages
|
2 |
+
|
3 |
+
if __name__ == "__main__":
|
4 |
+
install_packages()
|
5 |
+
|
6 |
+
from demo_app import demo
|
7 |
+
demo.queue(max_size=20).launch()
|
demo_app.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import torch
|
4 |
+
from diffusers import HunyuanVideoPipeline
|
5 |
+
# ... other imports ...
|
6 |
+
|
7 |
+
# Add LORA configuration
|
8 |
+
LORA_LIST = [
|
9 |
+
"Top_Off.safetensors",
|
10 |
+
"huanyan_helper.safetensors",
|
11 |
+
"huanyan_helper_alpha.safetensors",
|
12 |
+
"hunyuan-t-solo-v1.0.safetensors",
|
13 |
+
"stripe_v2.safetensors"
|
14 |
+
]
|
15 |
+
|
16 |
+
def create_advanced_settings():
|
17 |
+
with gr.Accordion("Advanced Settings", open=False):
|
18 |
+
# LORA Selection
|
19 |
+
lora_choices = gr.CheckboxGroup(
|
20 |
+
choices=LORA_LIST,
|
21 |
+
label="Select LORAs",
|
22 |
+
value=[LORA_LIST[0]]
|
23 |
+
)
|
24 |
+
|
25 |
+
lora_weights = {}
|
26 |
+
for lora in LORA_LIST:
|
27 |
+
lora_weights[lora] = gr.Slider(0.0, 1.0, value=0.8,
|
28 |
+
label=f"{lora} Weight")
|
29 |
+
|
30 |
+
# Resolution Settings
|
31 |
+
resolution = gr.Dropdown(
|
32 |
+
choices=["512x512", "768x768", "1024x1024"],
|
33 |
+
value="512x512",
|
34 |
+
label="Output Resolution"
|
35 |
+
)
|
36 |
+
|
37 |
+
return lora_choices, lora_weights, resolution
|
38 |
+
|
39 |
+
def validate_image_resolution(image, resolution):
|
40 |
+
if image is None:
|
41 |
+
return
|
42 |
+
img = Image.open(image)
|
43 |
+
w, h = img.size
|
44 |
+
if f"{w}x{h}" != resolution:
|
45 |
+
raise gr.Error(f"Image resolution ({w}x{h}) must match output resolution ({resolution})")
|
46 |
+
|
47 |
+
def generate_video(prompt, negative_prompt, lora_choices, lora_weights,
|
48 |
+
resolution, image_input=None, steps=30):
|
49 |
+
# Validate image resolution if provided
|
50 |
+
if image_input:
|
51 |
+
validate_image_resolution(image_input, resolution)
|
52 |
+
|
53 |
+
# Load base model
|
54 |
+
pipe = HunyuanVideoPipeline.from_pretrained(
|
55 |
+
"Tencent-Hunyuan/Hunyuan-Video-Lite",
|
56 |
+
torch_dtype=torch.float16
|
57 |
+
).to("cuda")
|
58 |
+
|
59 |
+
# Apply selected LORAs
|
60 |
+
for lora in lora_choices:
|
61 |
+
pipe.load_lora_weights(
|
62 |
+
f"TTV4ME/{lora}",
|
63 |
+
adapter_name="hunyuanvideo-lora",
|
64 |
+
weight_name=lora_weights[lora]
|
65 |
+
)
|
66 |
+
|
67 |
+
# Generate from image or text
|
68 |
+
if image_input:
|
69 |
+
image = Image.open(image_input).convert("RGB")
|
70 |
+
output = pipe.image_to_video(
|
71 |
+
image,
|
72 |
+
prompt=prompt,
|
73 |
+
negative_prompt=negative_prompt,
|
74 |
+
num_frames=24,
|
75 |
+
height=int(resolution.split("x")[1]),
|
76 |
+
width=int(resolution.split("x")[0]),
|
77 |
+
num_inference_steps=steps
|
78 |
+
)
|
79 |
+
else:
|
80 |
+
output = pipe.text_to_video(
|
81 |
+
prompt=prompt,
|
82 |
+
negative_prompt=negative_prompt,
|
83 |
+
height=int(resolution.split("x")[1]),
|
84 |
+
width=int(resolution.split("x")[0]),
|
85 |
+
num_inference_steps=steps
|
86 |
+
)
|
87 |
+
|
88 |
+
return output.video
|
89 |
+
|
90 |
+
# Update interface
|
91 |
+
with gr.Blocks() as demo:
|
92 |
+
with gr.Row():
|
93 |
+
with gr.Column():
|
94 |
+
prompt = gr.Textbox(label="Prompt")
|
95 |
+
negative_prompt = gr.Textbox(label="Negative Prompt")
|
96 |
+
image_input = gr.Image(label="Input Image", type="filepath")
|
97 |
+
|
98 |
+
lora_choices, lora_weights, resolution = create_advanced_settings()
|
99 |
+
|
100 |
+
generate_btn = gr.Button("Generate Video")
|
101 |
+
|
102 |
+
with gr.Column():
|
103 |
+
output_video = gr.Video(label="Generated Video")
|
104 |
+
|
105 |
+
generate_btn.click(
|
106 |
+
fn=generate_video,
|
107 |
+
inputs=[prompt, negative_prompt, lora_choices,
|
108 |
+
lora_weights, resolution, image_input],
|
109 |
+
outputs=output_video
|
110 |
+
)
|
packages.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ffmpeg
|
2 |
+
python3-imageio
|
3 |
+
cmake
|
4 |
+
libstdc++6
|
requirements.txt
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--extra-index-url https://download.pytorch.org/whl/cu124
|
2 |
+
bitsandbytes
|
3 |
+
decord
|
4 |
+
einops
|
5 |
+
facexlib
|
6 |
+
ftfy
|
7 |
+
gguf
|
8 |
+
git+https://github.com/huggingface/accelerate.git@main#egg=accelerate
|
9 |
+
git+https://github.com/huggingface/diffusers.git@main#egg=diffusers
|
10 |
+
git+https://github.com/huggingface/transformers.git@main#egg=transformers
|
11 |
+
gradio
|
12 |
+
hf_transfer
|
13 |
+
huggingface_hub
|
14 |
+
imageio
|
15 |
+
imageio-ffmpeg
|
16 |
+
insightface
|
17 |
+
invisible_watermark
|
18 |
+
matplotlib
|
19 |
+
moviepy==1.0.3
|
20 |
+
numpy<2.0
|
21 |
+
onnxruntime
|
22 |
+
onnxruntime-gpu
|
23 |
+
omegaconf
|
24 |
+
opencv-python
|
25 |
+
opencv-python-headless
|
26 |
+
git+https://github.com/huggingface/optimum-quanto
|
27 |
+
packaging
|
28 |
+
patch_conv
|
29 |
+
Pillow==10.2.0
|
30 |
+
psutil
|
31 |
+
safetensors
|
32 |
+
scipy
|
33 |
+
scikit-learn
|
34 |
+
scikit-image
|
35 |
+
scikit-video
|
36 |
+
sentencepiece
|
37 |
+
setuptools
|
38 |
+
spaces
|
39 |
+
timm
|
40 |
+
tokenizers>=0.13.3
|
41 |
+
torch<2.6.0,>=2.4.0
|
42 |
+
torchao
|
43 |
+
torchaudio
|
44 |
+
torchsde
|
45 |
+
torchvision
|
46 |
+
tqdm
|
47 |
+
wheel
|
48 |
+
git+https://github.com/huggingface/peft.git
|
utils.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def install_packages():
|
2 |
+
import subprocess
|
3 |
+
import sys
|
4 |
+
import importlib
|
5 |
+
|
6 |
+
def _is_package_available(name) -> bool:
|
7 |
+
try:
|
8 |
+
importlib.import_module(name)
|
9 |
+
return True
|
10 |
+
except (ImportError, ModuleNotFoundError):
|
11 |
+
return False
|
12 |
+
|
13 |
+
# upgrade pip
|
14 |
+
subprocess.run(
|
15 |
+
f"{sys.executable} -m pip install --upgrade pip", shell=True, check=True
|
16 |
+
)
|
17 |
+
subprocess.run(
|
18 |
+
f"{sys.executable} -m pip install --upgrade ninja wheel setuptools packaging", shell=True, check=True
|
19 |
+
)
|
20 |
+
|
21 |
+
# install ninja
|
22 |
+
if not _is_package_available("ninja"):
|
23 |
+
subprocess.run(f"{sys.executable} -m pip install ninja nvidia-cudnn-cu12==9.1.0.70 nvidia-cublas-cu12==12.4.5.8 torch==2.5.1 --extra-index-url https://download.pytorch.org/whl/cu124", shell=True, check=True)
|
24 |
+
|
25 |
+
# install flash attention
|
26 |
+
if not _is_package_available("flash_attn"):
|
27 |
+
subprocess.run(
|
28 |
+
f"{sys.executable} -m pip install -v -U flash-attention --no-build-isolation",
|
29 |
+
env={"MAX_JOBS": "1"},
|
30 |
+
shell=True,
|
31 |
+
check=True
|
32 |
+
)
|
33 |
+
|
34 |
+
# install xformers
|
35 |
+
if not _is_package_available("xformers"):
|
36 |
+
subprocess.run(
|
37 |
+
f"{sys.executable} -m pip install -v -U xformers nvidia-cudnn-cu12==9.1.0.70 nvidia-cublas-cu12==12.4.5.8 torch==2.5.1 --extra-index-url https://download.pytorch.org/whl/cu124",
|
38 |
+
shell=True,
|
39 |
+
check=True
|
40 |
+
)
|