Spaces:
Running
Running
File size: 1,937 Bytes
9a1014e | 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | """Descarga el repositorio GGUF de Qwen para uso local."""
from __future__ import annotations
import argparse
import os
from pathlib import Path
from huggingface_hub import snapshot_download
DEST_REPO = os.getenv(
"LOCAL_MODEL_REPO",
"AlbertiTechnology/qwen3-4b-instruct-gguf",
)
MODELS_DIR = Path(os.getenv("MODELS_DIR", "MODELS"))
LOCAL_MODEL_DIR = MODELS_DIR / "qwen3-4b-instruct-gguf"
def get_token(required: bool = False) -> str | None:
token = os.getenv("HF_TOKEN") or os.getenv("HUGGINGFACEHUB_API_TOKEN")
if required and not token:
raise RuntimeError("HF_TOKEN is required to create and upload the model repository.")
return token
def download_local_model(
repo_id: str = DEST_REPO,
local_dir: Path = LOCAL_MODEL_DIR,
) -> Path:
"""Descarga el repositorio propio dentro de MODELS para inferencia local."""
local_dir.parent.mkdir(parents=True, exist_ok=True)
local_path = snapshot_download(
repo_id=repo_id,
token=get_token(),
local_dir=local_dir,
)
print(f"Modelo local descargado en: {local_path}", flush=True)
return Path(local_path)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument(
"--download-only",
action="store_true",
help="Sólo descarga DEST_REPO dentro de MODELS.",
)
parser.add_argument(
"--repo",
default=DEST_REPO,
help="Repositorio que se descargara dentro de MODELS.",
)
parser.add_argument(
"--local-dir",
type=Path,
default=LOCAL_MODEL_DIR,
help="Directorio local donde se guardara el repositorio.",
)
return parser.parse_args()
def main() -> None:
args = parse_args()
if args.download_only:
download_local_model(args.repo, args.local_dir)
return
raise SystemExit("Use --download-only.")
if __name__ == "__main__":
main()
|