import spaces # must come before torch / CUDA-touching imports import os import tempfile import time from fractions import Fraction import av import gradio as gr import numpy as np import torch from huggingface_hub import hf_hub_download from PIL import Image from safetensors.torch import load_file from solarwm.backends.wan22.ref2va.cores import Ref2VAWanBDCore from solarwm.backends.wan22.ref2va.data import Ref2VAWanSample from solarwm.backends.wan22.ref2va.model import Ref2VAWanModel from solarwm.backends.wan22.runtime.components import Wan5BVAE from solarwm.backends.wan22.runtime.modeling.t5 import umt5_xxl from solarwm.backends.wan22.runtime.modeling.tokenizers import HuggingfaceTokenizer # ----------------------------------------------------------------------------------- geometry # GameWM-Wan2.2-5B (GameWM-engine GEOMETRY["wan2.2-5b"]): 121 frames, 24 fps, 1280x704 target, # 640x352 proxy video. Latents: 31 frames, 44x80 target grid, 22x40 proxy grid. FPS = 24 FRAMES = 121 WIDTH, HEIGHT = 1280, 704 PROXY_WIDTH, PROXY_HEIGHT = 640, 352 SHEET_SHORT_EDGE = 1024 # protocol: is scaled to short edge 1024 SPAN = "[0.00s-5.17s]" # the training captions' span, kept verbatim for every backbone SHEET_PROMPT = ( " is the protagonist identity sheet (front / left profile / back). The character the " "camera follows is the character in every frame, also while turning or entering and " "leaving the frame. Identity only: camera, pose, motion and framing come from