-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwan2_2.py
More file actions
107 lines (82 loc) · 3.04 KB
/
wan2_2.py
File metadata and controls
107 lines (82 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""wan2.2
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1ypqXKZBCq4bPHu5TKwgZb4_-oMsxKHlJ
"""
!git clone https://github.com/Wan-Video/Wan2.2.git
# Commented out IPython magic to ensure Python compatibility.
# %cd Wan2.2
!pip install -r requirements.txt
!pip install .
!pip install flash-attn --no-build-isolation
!pip install "huggingface_hub[cli]"
!huggingface-cli download Wan-AI/Wan2.2-I2V-A14B --local-dir ./Wan2.2-I2V-A14B
# @title 1. Upload Input Image
import os
from google.colab import files
# Clean up previous uploads to avoid confusion
if 'input_image_path' in locals():
print(f"Previous image was: {input_image_path}")
else:
input_image_path = ""
uploaded = files.upload()
# Get the filename of the uploaded file
if uploaded:
input_image_path = list(uploaded.keys())[0]
print(f"\nSUCCESS: Image set to '{input_image_path}'")
else:
print("\nNo file uploaded.")
# @title 2. Generation Settings
# @markdown ### 📝 Prompting
prompt = "In her bedroom, a Gen Z e-girl with dyed hair and an oversized graphic tee records a TikTok. She's holding her phone up, making a funny, exaggerated facial expression, and mouthing along to a trending sound. Her room is decorated with LED lights, band posters, and a few plushies. A ring light illuminates her face." # @param {type:"string"}
# @markdown ### ⚙️ Model Config
task = "i2v-A14B" # @param ["i2v-A14B", "i2v-1.3B"]
resolution = "1280*720" # @param ["1280*720", "832*480", "1024*1024"]
checkpoint_dir = "./Wan2.2-I2V-A14B" # @param {type:"string"}
# @markdown ### 🚀 Optimization Flags
offload_model = True # @param {type:"boolean"}
use_t5_cpu = True # @param {type:"boolean"}
convert_model_dtype = True # @param {type:"boolean"}
# Constructing the argument string based on checkboxes
args = ""
if offload_model:
args += "--offload_model True "
if use_t5_cpu:
args += "--t5_cpu "
if convert_model_dtype:
args += "--convert_model_dtype "
print("Configuration updated.")
# @title 3. Generate Video
import torch
import sys
import os
# Install missing dependency 'decord' which caused the error
!pip install decord
# 1. Clear VRAM before starting
torch.cuda.empty_cache()
# 2. Check if image exists
if not os.path.exists(input_image_path):
print(f"ERROR: Could not find image '{input_image_path}'. Please run Cell 1 again.")
else:
print(f"Processing image: {input_image_path}...")
print(f"Prompt: {prompt}")
# 3. Execute Command
# We use f-strings to insert the variables from Cell 2
!python generate.py \
--task {task} \
--size {resolution} \
--ckpt_dir {checkpoint_dir} \
--image "{input_image_path}" \
--prompt "{prompt}" \
{args}
import glob
from IPython.display import Video
# Find the most recently generated mp4 file
mp4_files = glob.glob("*.mp4")
if mp4_files:
latest_file = max(mp4_files, key=os.path.getctime)
print(f"Displaying: {latest_file}")
display(Video(latest_file, embed=True))
else:
print("No video found.")