File size: 1,803 Bytes
365d2be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1519aa
 
 
365d2be
 
 
 
 
 
 
e1519aa
 
365d2be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1519aa
365d2be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
74
"""Download modles."""
# pylint: disable=invalid-name, broad-exception-caught, line-too-long
from typing import Optional

import typer
from dl_hf_model import dl_hf_model
from loguru import logger

url = "https://huggingface.co/TheBloke/Upstage-Llama-2-70B-instruct-v2-GGML/blob/main/upstage-llama-2-70b-instruct-v2.ggmlv3.q3_K_S.bin"


__version__ = "0.0.1"

app = typer.Typer(
    name="dl-mode",
    add_completion=False,
    help="donwload models from hf and save to a dir (default models)",
)


def _version_callback(value: bool) -> None:
    if value:
        typer.echo(
            f"{app.info.name} v.{__version__} -- download models for given url(s)"
        )
        raise typer.Exit()


@app.command()
def main(
    urls: str = typer.Argument(  # pylint: disable=unused-argument
        "",
        help=f"one or more urls (default {url})",
        show_default=False,
    ),
    version: Optional[bool] = typer.Option(  # pylint: disable=unused-argument
        None,
        "--version",
        "-v",
        "-V",
        help="Show version info and exit.",
        callback=_version_callback,
        is_eager=True,
    ),
    model_dir: Optional[str] = typer.Option(
        None,
        "--mode-dir",
        help="dir to save downloaded models (default models)",
    ),
):
    """Download a model or model given url(s)."""
    logger.trace(f"{urls}")
    if model_dir is None:
        model_dir = "models"
    if isinstance(urls, str):
        urls.split()

    url_list = urls[:]
    if not urls:
        url_list = [url]
    try:
        for elm in url_list:
            dl_hf_model(elm)
    except Exception as exc:
        logger.error(exc)
        raise typer.Exit()


if __name__ == "__main__":
    try:
        app()
    except Exception as exc_:
        logger.error(exc_)