File size: 1,360 Bytes
55549d3
 
2c40a1b
55549d3
 
 
 
694d214
 
55549d3
694d214
 
 
2c40a1b
694d214
2c40a1b
694d214
 
 
 
 
 
 
55549d3
694d214
55549d3
694d214
55549d3
2c40a1b
 
 
 
 
 
 
 
 
 
 
 
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
import os

# Patch wan/__init__.py
p = '/app/Wan2.2/wan/__init__.py'
with open(p) as f:
    content = f.read()
lines = content.split('\n')
result = []
problematic = {'speech2video', 'animate', 'video2audio'}
for line in lines:
    stripped = line.strip()
    if stripped.startswith('from .') and 'import' in stripped:
        parts = stripped.split()
        module_ref = parts[1]
        module_name = module_ref.lstrip('.')
        if any(mod in module_name for mod in problematic):
            indent = line[:len(line) - len(line.lstrip())]
            result.append(f'{indent}try:')
            result.append(f'{indent}    {stripped}')
            result.append(f'{indent}except ImportError:')
            result.append(f'{indent}    pass')
        else:
            result.append(line)
    else:
        result.append(line)
with open(p, 'w') as f:
    f.write('\n'.join(result))
print('Patched wan/__init__.py')

# Patch generate.py
p = '/app/Wan2.2/generate.py'
with open(p) as f:
    c = f.read()
c = c.replace(
    'from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander',
    'try:\n    from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander\nexcept ImportError:\n    DashScopePromptExpander = None\n    QwenPromptExpander = None'
)
with open(p, 'w') as f:
    f.write(c)
print('Patched generate.py')