File size: 708 Bytes
ad2704e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# paths.py

import os


def model_source(local_path: str, hub_id: str) -> str:
    """Resolve where to load a pretrained model from.

    The Dockerfile bakes these models into the image at build time, so in the
    container we load from disk and never touch the network. Outside the
    container those paths do not exist, so fall back to the Hub.

    This used to be a hand-set `runAsContainer` flag, which was easy to get
    wrong: it was left False in main.py, so the Space re-downloaded from the
    Hub on every boot despite having baked copies sitting on disk.
    """
    resolved = local_path if os.path.isdir(local_path) else hub_id
    print(f"📦 {hub_id} -> {resolved}")
    return resolved