INNER CODE UNIT · Python
load_model_once
OpenVGLab/OmniLottie · app.py:38
def load_model_once():
global model, processor, device
if model is not None:
return model, processor, device
checkpoint_path = "/PATH/TO/OmniLottie"
device = torch.device("cuda:0" if torch.cuda.is_available() else "xpu:0" if torch.xpu.is_available() else "cpu")
print(f"Loading model from {checkpoint_path}...")
model = LottieDecoder(pix_len=4560, text_len=1500)
model_file = os.path.join(checkpoint_path, 'pytorch_model.bin')
if os.path.exists(model_file):
model.load_state_dict(torch.load(model_file, map_location='cpu'))
else: