AlekseyCalvin commited on
Commit
968cf3f
·
verified ·
1 Parent(s): e0c75e6

Update app_fast.py

Browse files
Files changed (1) hide show
  1. app_fast.py +9 -7
app_fast.py CHANGED
@@ -2,6 +2,7 @@ import spaces
2
  import torch
3
  from diffusers import AutoencoderKLWan, WanPipeline, WanImageToVideoPipeline, UniPCMultistepScheduler
4
  from diffusers.utils import export_to_video
 
5
  import gradio as gr
6
  import tempfile
7
  from huggingface_hub import hf_hub_download
@@ -11,6 +12,7 @@ import random
11
 
12
  MODEL_ID = "FastVideo/FastWan2.2-TI2V-5B-FullAttn-Diffusers"
13
  vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
 
14
 
15
  # Initialize pipelines
16
  text_to_video_pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)
@@ -20,7 +22,7 @@ for pipe in [text_to_video_pipe, image_to_video_pipe]:
20
  pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=5.0)
21
  pipe.to("cuda")
22
 
23
-
24
 
25
 
26
  ##Lora testing
@@ -42,7 +44,7 @@ for pipe in [text_to_video_pipe, image_to_video_pipe]:
42
  #LORA_FILENAME = "HSToric_color_Wan22_5b_LoRA.safetensors"
43
 
44
  LORA_REPO_ID = "AlekseyCalvin/Phenakistiscopes_Wan22_5B_T2V_LoRA"
45
- LORA_FILENAME = "Phenakistiscopes_MergedVers4_3_2_wan5b_wEMAsigmaRel020.safetensors"
46
  causvid_path = hf_hub_download(repo_id=LORA_REPO_ID, filename=LORA_FILENAME)
47
  pipe.load_lora_weights(causvid_path, adapter_name="wan_lora")
48
  pipe.set_adapters(["wan_lora"], adapter_weights=[1.05])
@@ -61,7 +63,7 @@ MIN_FRAMES_MODEL = 17
61
  MAX_FRAMES_MODEL = 193
62
 
63
  default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
64
- default_negative_prompt = "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, watermark, text, signature"
65
 
66
  def _calculate_new_dimensions_wan(pil_image, mod_val, calculation_max_area, min_slider_h, max_slider_h, min_slider_w, max_slider_w, default_h, default_w):
67
  orig_w, orig_h = pil_image.size
@@ -99,13 +101,13 @@ def get_duration(input_image, prompt, height, width,
99
  seed, randomize_seed,
100
  progress):
101
  if steps > 5 and duration_seconds > 5:
102
- return 30
103
  elif steps > 5 or duration_seconds > 5:
104
- return 25
105
  else:
106
- return 20
107
 
108
- @spaces.GPU(duration=get_duration)
109
  def generate_video(input_image, prompt, height, width, negative_prompt=default_negative_prompt, duration_seconds=2, guidance_scale=0, steps=4, seed=44, randomize_seed=False, progress=gr.Progress(track_tqdm=True)):
110
  target_h = max(MOD_VALUE, (int(height) // MOD_VALUE) * MOD_VALUE)
111
  target_w = max(MOD_VALUE, (int(width) // MOD_VALUE) * MOD_VALUE)
 
2
  import torch
3
  from diffusers import AutoencoderKLWan, WanPipeline, WanImageToVideoPipeline, UniPCMultistepScheduler
4
  from diffusers.utils import export_to_video
5
+ from diffusers.hooks import apply_first_block_cache, FirstBlockCacheConfig
6
  import gradio as gr
7
  import tempfile
8
  from huggingface_hub import hf_hub_download
 
12
 
13
  MODEL_ID = "FastVideo/FastWan2.2-TI2V-5B-FullAttn-Diffusers"
14
  vae = AutoencoderKLWan.from_pretrained(MODEL_ID, subfolder="vae", torch_dtype=torch.float32)
15
+ #vae = AutoencoderKLWan.from_pretrained("Kijai/WanVideo_comfy", filename="Wan2_2_VAE_bf16.safetensors", torch_dtype=torch.bfloat16)
16
 
17
  # Initialize pipelines
18
  text_to_video_pipe = WanPipeline.from_pretrained(MODEL_ID, vae=vae, torch_dtype=torch.bfloat16)
 
22
  pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=5.0)
23
  pipe.to("cuda")
24
 
25
+ apply_first_block_cache(pipe.transformer, FirstBlockCacheConfig(threshold=0.2))
26
 
27
 
28
  ##Lora testing
 
44
  #LORA_FILENAME = "HSToric_color_Wan22_5b_LoRA.safetensors"
45
 
46
  LORA_REPO_ID = "AlekseyCalvin/Phenakistiscopes_Wan22_5B_T2V_LoRA"
47
+ LORA_FILENAME = "Phenakistiscopes_V3_Wan5b_PowerEMA_SigmaRel013.safetensors"
48
  causvid_path = hf_hub_download(repo_id=LORA_REPO_ID, filename=LORA_FILENAME)
49
  pipe.load_lora_weights(causvid_path, adapter_name="wan_lora")
50
  pipe.set_adapters(["wan_lora"], adapter_weights=[1.05])
 
63
  MAX_FRAMES_MODEL = 193
64
 
65
  default_prompt_i2v = "make this image come alive, cinematic motion, smooth animation"
66
+ default_negative_prompt = "dull, overexposed, flashing, stuttering, static, blurred, vapid, banal, static, overall gray, worst, low, JPEG compression residue, incomplete, extra, error, missing, vanishing, lapse, broken, wrong, deformed, disfigured, misshapen, fused fingers, still, messy, watermark"
67
 
68
  def _calculate_new_dimensions_wan(pil_image, mod_val, calculation_max_area, min_slider_h, max_slider_h, min_slider_w, max_slider_w, default_h, default_w):
69
  orig_w, orig_h = pil_image.size
 
101
  seed, randomize_seed,
102
  progress):
103
  if steps > 5 and duration_seconds > 5:
104
+ return 50
105
  elif steps > 5 or duration_seconds > 5:
106
+ return 45
107
  else:
108
+ return 40
109
 
110
+ @spaces.GPU
111
  def generate_video(input_image, prompt, height, width, negative_prompt=default_negative_prompt, duration_seconds=2, guidance_scale=0, steps=4, seed=44, randomize_seed=False, progress=gr.Progress(track_tqdm=True)):
112
  target_h = max(MOD_VALUE, (int(height) // MOD_VALUE) * MOD_VALUE)
113
  target_w = max(MOD_VALUE, (int(width) // MOD_VALUE) * MOD_VALUE)