Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 1,255 Bytes
a214f17 5249c42 a214f17 | 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 45 46 47 48 49 | import subprocess
from huggingface_hub import snapshot_download, login, HfApi
from app.config import config
def authenticate():
if not config.HF_TOKEN:
raise RuntimeError("HF_TOKEN is not set.")
api = HfApi()
user = api.whoami(token=config.HF_TOKEN)
print(f"Authenticated as: {user['name']}")
login(token=config.HF_TOKEN, add_to_git_credential=False)
def download_models():
models = [
config.FASTTEXT_MODEL,
config.TRANSLATION_MODEL,
config.LLM_MODEL,
*config.ASR_MODELS.values(),
]
ignore = [
"*.msgpack", "*.h5", "flax_model*", "tf_model*",
"rust_model*", "optimizer.pt", "rng_state*",
"training_args.bin", "trainer_state.json", "scheduler.pt",
]
print("\nDownloading models...")
for model_id in models:
print(f" {model_id}...")
snapshot_download(
repo_id=model_id,
token=config.HF_TOKEN,
ignore_patterns=ignore,
)
print(f" ✓ {model_id}")
print("\nAll models cached.")
if __name__ == "__main__":
authenticate()
download_models()
subprocess.run(
["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"],
check=True,
) |