Spaces:
Running
on
Zero
Running
on
Zero
Commit
Β·
16d02f1
1
Parent(s):
9e04e04
Single File FusionX
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import spaces
|
| 2 |
import torch
|
| 3 |
-
from diffusers import AutoencoderKLWan, WanImageToVideoPipeline, UniPCMultistepScheduler
|
| 4 |
from diffusers.utils import export_to_video
|
| 5 |
# Conditionally import T2V pipeline to handle different diffusers versions and prevent crashes.
|
| 6 |
try:
|
|
@@ -10,8 +10,8 @@ except ImportError:
|
|
| 10 |
WanTextToVideoPipeline = None # Define as None so later code doesn't raise NameError
|
| 11 |
IS_T2V_AVAILABLE = False
|
| 12 |
print("β οΈ Warning: 'WanTextToVideoPipeline' could not be imported. Your 'diffusers' version might be outdated (requires >= 0.25.0).")
|
| 13 |
-
from transformers import CLIPVisionModel
|
| 14 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 15 |
import tempfile
|
| 16 |
import re
|
| 17 |
import os
|
|
@@ -24,56 +24,68 @@ import gradio as gr
|
|
| 24 |
import random
|
| 25 |
|
| 26 |
# --- I2V (Image-to-Video) Configuration ---
|
| 27 |
-
I2V_MODEL_ID = "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers"
|
| 28 |
-
|
| 29 |
|
| 30 |
# --- T2V (Text-to-Video) Configuration ---
|
| 31 |
T2V_MODEL_ID = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
|
| 32 |
-
|
| 33 |
|
| 34 |
-
# ---
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
return None
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
try:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
except Exception as e:
|
| 61 |
-
print(f"β Error
|
| 62 |
traceback.print_exc()
|
| 63 |
-
|
| 64 |
-
return pipe
|
| 65 |
-
|
| 66 |
-
# --- Load Pipelines ---
|
| 67 |
-
i2v_image_encoder = CLIPVisionModel.from_pretrained(I2V_MODEL_ID, subfolder="image_encoder", torch_dtype=torch.float32)
|
| 68 |
-
i2v_vae = AutoencoderKLWan.from_pretrained(I2V_MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 69 |
-
i2v_pipe = load_and_fuse_pipeline(
|
| 70 |
-
I2V_MODEL_ID, I2V_LORA_FILENAME, WanImageToVideoPipeline, LORA_REPO_ID,
|
| 71 |
-
vae=i2v_vae, image_encoder=i2v_image_encoder
|
| 72 |
-
)
|
| 73 |
-
|
| 74 |
-
t2v_pipe = load_and_fuse_pipeline(
|
| 75 |
-
T2V_MODEL_ID, T2V_LORA_FILENAME, WanTextToVideoPipeline, LORA_REPO_ID
|
| 76 |
-
)
|
| 77 |
|
| 78 |
# --- LLM Prompt Enhancer Setup ---
|
| 79 |
print("\nπ€ Loading LLM for Prompt Enhancement (Qwen/Qwen3-8B)...")
|
|
|
|
| 1 |
import spaces
|
| 2 |
import torch
|
| 3 |
+
from diffusers import AutoencoderKLWan, WanImageToVideoPipeline, UniPCMultistepScheduler, WanTransformer3DModel
|
| 4 |
from diffusers.utils import export_to_video
|
| 5 |
# Conditionally import T2V pipeline to handle different diffusers versions and prevent crashes.
|
| 6 |
try:
|
|
|
|
| 10 |
WanTextToVideoPipeline = None # Define as None so later code doesn't raise NameError
|
| 11 |
IS_T2V_AVAILABLE = False
|
| 12 |
print("β οΈ Warning: 'WanTextToVideoPipeline' could not be imported. Your 'diffusers' version might be outdated (requires >= 0.25.0).")
|
| 13 |
+
from transformers import CLIPVisionModel, CLIPTextModel, CLIPTokenizer
|
| 14 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline # noqa
|
| 15 |
import tempfile
|
| 16 |
import re
|
| 17 |
import os
|
|
|
|
| 24 |
import random
|
| 25 |
|
| 26 |
# --- I2V (Image-to-Video) Configuration ---
|
| 27 |
+
I2V_MODEL_ID = "Wan-AI/Wan2.1-I2V-14B-480P-Diffusers" # Used for VAE/encoder components
|
| 28 |
+
I2V_SINGLE_FILE_URL = "https://huggingface.co/vrgamedevgirl84/Wan14BT2VFusioniX/resolve/main/Wan14Bi2vFusioniX.safetensors"
|
| 29 |
|
| 30 |
# --- T2V (Text-to-Video) Configuration ---
|
| 31 |
T2V_MODEL_ID = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
|
| 32 |
+
T2V_SINGLE_FILE_URL = "https://huggingface.co/vrgamedevgirl84/Wan14BT2VFusioniX/resolve/main/WanT2V_MasterModel.safetensors"
|
| 33 |
|
| 34 |
+
# --- Load Pipelines ---
|
| 35 |
+
print("π Loading I2V pipeline from single file...")
|
| 36 |
+
i2v_pipe = None
|
| 37 |
+
try:
|
| 38 |
+
# Load components needed for the pipeline from the base model repo
|
| 39 |
+
i2v_image_encoder = CLIPVisionModel.from_pretrained(I2V_MODEL_ID, subfolder="image_encoder", torch_dtype=torch.float32)
|
| 40 |
+
i2v_vae = AutoencoderKLWan.from_pretrained(I2V_MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
|
|
|
| 41 |
|
| 42 |
+
# Load the main transformer from the single file URL
|
| 43 |
+
i2v_transformer = WanTransformer3DModel.from_single_file(
|
| 44 |
+
I2V_SINGLE_FILE_URL,
|
| 45 |
+
torch_dtype=torch.bfloat16
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Manually assemble the pipeline with the custom transformer
|
| 49 |
+
i2v_pipe = WanImageToVideoPipeline(
|
| 50 |
+
vae=i2v_vae,
|
| 51 |
+
image_encoder=i2v_image_encoder,
|
| 52 |
+
transformer=i2v_transformer
|
| 53 |
+
)
|
| 54 |
+
i2v_pipe.scheduler = UniPCMultistepScheduler.from_config(i2v_pipe.scheduler.config, flow_shift=8.0)
|
| 55 |
+
i2v_pipe.to("cuda")
|
| 56 |
+
print("β
I2V pipeline loaded successfully from single file.")
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"β Critical Error: Failed to load I2V pipeline from single file.")
|
| 59 |
+
traceback.print_exc()
|
| 60 |
|
| 61 |
+
print("\nπ Loading T2V pipeline from single file...")
|
| 62 |
+
t2v_pipe = None
|
| 63 |
+
if IS_T2V_AVAILABLE:
|
| 64 |
try:
|
| 65 |
+
# Load components needed for the pipeline from the base model repo
|
| 66 |
+
t2v_vae = AutoencoderKLWan.from_pretrained(T2V_MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
|
| 67 |
+
t2v_text_encoder = CLIPTextModel.from_pretrained(T2V_MODEL_ID, subfolder="text_encoder", torch_dtype=torch.bfloat16)
|
| 68 |
+
t2v_tokenizer = CLIPTokenizer.from_pretrained(T2V_MODEL_ID, subfolder="tokenizer")
|
| 69 |
+
|
| 70 |
+
# Load the main transformer from the single file URL
|
| 71 |
+
t2v_transformer = WanTransformer3DModel.from_single_file(
|
| 72 |
+
T2V_SINGLE_FILE_URL,
|
| 73 |
+
torch_dtype=torch.bfloat16
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# Manually assemble the pipeline with the custom transformer
|
| 77 |
+
t2v_pipe = WanTextToVideoPipeline(
|
| 78 |
+
vae=t2v_vae,
|
| 79 |
+
text_encoder=t2v_text_encoder,
|
| 80 |
+
tokenizer=t2v_tokenizer,
|
| 81 |
+
transformer=t2v_transformer
|
| 82 |
+
)
|
| 83 |
+
t2v_pipe.scheduler = UniPCMultistepScheduler.from_config(t2v_pipe.scheduler.config, flow_shift=8.0)
|
| 84 |
+
t2v_pipe.to("cuda")
|
| 85 |
+
print("β
T2V pipeline loaded successfully from single file.")
|
| 86 |
except Exception as e:
|
| 87 |
+
print(f"β Critical Error: Failed to load T2V pipeline from single file.")
|
| 88 |
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# --- LLM Prompt Enhancer Setup ---
|
| 91 |
print("\nπ€ Loading LLM for Prompt Enhancement (Qwen/Qwen3-8B)...")
|