themblem/scripts/download_models.py
2025-11-24 06:53:55 +08:00

31 lines
901 B
Python
Executable File

#!/usr/bin/env python3
"""
Download HuggingFace models for offline use
"""
import os
from sentence_transformers import SentenceTransformer
from pathlib import Path
# Use HF mirror if HF_ENDPOINT is not already set
if 'HF_ENDPOINT' not in os.environ:
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
# Create models directory relative to this script: scripts/ -> ../models/
script_dir = Path(__file__).parent
models_dir = script_dir.parent / "models"
models_dir.mkdir(parents=True, exist_ok=True)
# Download the model
model_name = "shibing624/text2vec-base-chinese"
model_path = models_dir / "text2vec-base-chinese"
print(f"Downloading model: {model_name}")
print(f"Saving to: {model_path}")
print(f"Using HF endpoint: {os.environ.get('HF_ENDPOINT', 'default')}")
model = SentenceTransformer(model_name)
model.save(str(model_path))
print(f"Model successfully downloaded to {model_path}")