FARMLINGUA_FARMAI / start.py
drrobot9's picture
Update start.py
5249c42 verified
Raw
History Blame Contribute Delete
1.26 kB
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,
)