Tanya-Khanna
Restore removed numpy aliases (np.float et al) in compat shim for SadTalker
49cbd6d
Raw
History Blame Contribute Delete
959 Bytes
"""Runtime compatibility shims for vendored 2023-era code (SadTalker stack).
Import this BEFORE anything that imports basicsr/gfpgan: torchvision 0.17+
removed transforms.functional_tensor, which basicsr still imports. On Spaces
we can't sed site-packages, so we plant a module alias instead.
"""
import sys
def install() -> None:
try:
import torchvision.transforms.functional as F
sys.modules.setdefault("torchvision.transforms.functional_tensor", F)
except ImportError:
pass # torchvision not installed (local dev) — nothing to shim
# numpy >=1.24 removed the deprecated builtin aliases SadTalker still uses
try:
import numpy as np
for name, typ in {"float": float, "int": int, "bool": bool,
"object": object, "complex": complex, "str": str}.items():
if not hasattr(np, name):
setattr(np, name, typ)
except ImportError:
pass