Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cubenlp/use-click
reconstruct using click
- Loading branch information
Showing
7 changed files
with
141 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,35 @@ | ||
# hf-mirror-download | ||
A command-line tool designed to streamline the process of downloading machine learning models and related files from the Hugging Face model hub mirror site. | ||
# hf-mirror-fetch | ||
|
||
https://hf-mirror.com/ | ||
[English](README-EN.md) | [简体中文](README.md) | ||
|
||
`hf-mirror-fetch` is a command-line tool designed to streamline the process of downloading machine learning models and related files from the Hugging Face model hub mirror site. This tool is particularly useful in environments where access to the primary Hugging Face repository is restricted or where connectivity to the main site is slow. | ||
|
||
## Installation | ||
|
||
Ensure you have Python 3.6 or higher installed. You can install `hf-mirror-fetch` using the following command: | ||
|
||
```bash | ||
pip install hf-mirror-fetch | ||
``` | ||
|
||
## Usage | ||
|
||
Using `hf-mirror-fetch` to download models is straightforward; you only need to provide the URL of the model page. Here is an example of how to use it: | ||
|
||
```bash | ||
hfmf -u https://huggingface.co/openchat/openchat_3.5/tree/main | ||
``` | ||
|
||
### Parameters | ||
|
||
- `-u`, `--url`: The URL of the model's page on hf-mirror.com or huggingface.co. | ||
- `-f`, `--tgt_folder`: (Optional) The target folder to save the downloaded files. If not specified, a folder named after the model will be created. | ||
- `--update`: (Optional) Update existing files except for weights. | ||
|
||
## Contributing | ||
|
||
Contributions of any kind are welcome, whether they are feature suggestions, code improvements, or documentation updates. Please submit your contributions through GitHub Issues or Pull Requests. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. For more details, please check the LICENSE file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
# hf-mirror-download | ||
download huggingface models from mirror site | ||
# hf-mirror-fetch | ||
|
||
https://hf-mirror.com/ | ||
[English](README-EN.md) | [简体中文](README.md) | ||
|
||
# usage | ||
```python | ||
python mirror_download.py https://huggingface.co/microsoft/phi-2/tree/main | ||
# or | ||
python mirror_download.py https://hf-mirror.com/microsoft/phi-2/tree/main | ||
`hf-mirror-fetch` 是一个命令行工具,旨在简化从 Hugging Face 模型镜像站点下载机器学习模型和相关文件的过程。这个工具特别适用于在访问 Hugging Face 主站受限或连接速度较慢的环境中。 | ||
|
||
## 安装 | ||
|
||
确保您已安装 Python 3.6 或更高版本。您可以通过以下命令安装 `hf-mirror-fetch`: | ||
|
||
```bash | ||
pip install hf-mirror-fetch | ||
``` | ||
|
||
## 使用方法 | ||
|
||
使用 `hf-mirror-fetch` 下载模型非常简单,只需要提供模型页面的 URL 即可。以下是使用示例: | ||
|
||
```bash | ||
hfmf -u https://huggingface.co/openchat/openchat_3.5/tree/main | ||
hfmf -u https://huggingface.co/openchat/openchat_3.5 | ||
hfmf -u openchat/openchat_3.5 | ||
``` | ||
在网站上找到模型之后,打开 `Files and versions` Tab, 拷贝链接下载 | ||
|
||
### 参数说明 | ||
|
||
- `-u`, `--url`: 模型页面在 hf-mirror.com 或 huggingface.co 上的 URL。 | ||
- `-f`, `--tgt_folder`: (可选)保存下载文件的目标文件夹。如果未指定,将使用模型名创建一个文件夹。 | ||
- `--update`: (可选)更新现有文件,但不包括权重文件。 | ||
|
||
## 贡献 | ||
|
||
欢迎任何形式的贡献,无论是功能建议、代码改进还是文档更新。请通过 GitHub 的 Issue 或 Pull Request 提交您的贡献。 | ||
|
||
## 版权 | ||
|
||
该项目采用 MIT 许可证。有关更多信息,请查看 LICENSE 文件。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
"""Console script for hf_mirror_fetch.""" | ||
import sys | ||
import click | ||
from hf_mirror_fetch.mirror_download import get_url2names, download_from_mirror_page | ||
|
||
def process_url(url): | ||
ROOT = "https://hf-mirror.com" | ||
HF = "https://huggingface.co" | ||
# If URL lacks a known prefix, assume it's intended for Hugging Face | ||
if not url.startswith((ROOT, HF)): | ||
url = f"{HF}/{url}" # Prepend with Hugging Face domain | ||
if url.startswith(HF): | ||
url = url.replace(HF, ROOT) | ||
# Ensure URL ends with /tree/main, append if necessary | ||
if not url.endswith("/tree/main"): | ||
# Append correctly depending on whether URL already ends with a slash | ||
url = f"{url.rstrip('/')}/tree/main" | ||
return url | ||
|
||
|
||
@click.command() | ||
def main(args=None): | ||
@click.option('-u', '--url', required=True, help='The URL of the model\'s page on hf-mirror.com or huggingface.co.') | ||
@click.option('-f', '--tgt_folder', default=None, type=str, help='The target folder to save the downloaded files.') | ||
@click.option('--update', is_flag=True, help='Update existing files except for weights.') | ||
def main(url, tgt_folder, update): | ||
"""Console script for hf_mirror_fetch.""" | ||
click.echo("Replace this message by putting your code into " | ||
"hf_mirror_fetch.cli.main") | ||
click.echo("See click documentation at https://click.palletsprojects.com/") | ||
url = process_url(url) | ||
download_from_mirror_page(url, tgt_folder, update) | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) # pragma: no cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters