File size: 2,013 Bytes
cf3ffb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Invoke the pinned upstream full-body preprocessor on a GPU development host.
Not yet integrated into the ZeroGPU Space; no shell evaluation or paid services.
"""
import argparse
import json
from pathlib import Path
import subprocess
import sys
import core

UPSTREAM_SHA = '1ea34ff48f87168174e12956e200b1d908b1c5ff'

def command(repo, checkpoints, job):
    repo, checkpoints, job = map(lambda p: Path(p).resolve(), (repo,checkpoints,job))
    sha = core.run(['git','-C',repo,'rev-parse','HEAD']).strip()
    if sha != UPSTREAM_SHA:
        raise ValueError('Upstream checkout must match the reviewed revision: '+UPSTREAM_SHA)
    j = json.loads((job/'job.json').read_text())
    for name in ('pose2d/vitpose_h_wholebody.onnx','det/yolov10m.onnx','sam2/sam2_hiera_large.pt'):
        if not (checkpoints/name).is_file():
            raise ValueError('Missing preprocessing checkpoint: '+name)
    return [sys.executable, str(repo/'wan/modules/animate/preprocess/preprocess_data.py'),
        '--ckpt_path',str(checkpoints),'--video_path',str(job/'source.mp4'),
        '--refer_path',str(job/'reference.png'),'--save_path',str(job/'conditioning'),
        '--resolution_area',str(j['width']),str(j['height']), '--fps',str(core.FPS),
        '--iterations','3','--k','7','--w_len','1','--h_len','1','--replace_flag']

if __name__ == '__main__':
    p=argparse.ArgumentParser()
    p.add_argument('--repo',required=True)
    p.add_argument('--checkpoints',required=True)
    p.add_argument('--job',required=True)
    args=p.parse_args()
    job=Path(args.job).resolve()
    cmd=command(args.repo,args.checkpoints,job)
    core.write_manifest(job,{'state':'preprocessing'})
    try:
        subprocess.run(cmd,cwd=Path(args.repo).resolve(),check=True,timeout=600)
        core.attach_controls(job, [job/'conditioning'/name for name in core.CONTROL_NAMES])
        print(core.checkpoint(job))
    except Exception as e:
        core.write_manifest(job,{'state':'failed_preprocessing','error':str(e)})
        raise