A tool for uploading models to HuggingFace and ModelScope
Project description
Model Uploader
A Python tool for uploading models to both HuggingFace Hub and ModelScope.
Features
- ๐ Upload to HuggingFace Hub and ModelScope simultaneously
- ๐ฆ Automatically reads
.gitignoreto intelligently skip unwanted files - ๐ง Flexible CLI configuration with selective platform upload
- ๐ Detailed logging with real-time progress and status updates
- ๐ Automatic language detection (English/Chinese)
- ๐ฏ Modular design, easy to integrate into other projects
Installation
From PyPI (Recommended)
pip install modeluploader
From Source
git clone https://github.com/Maicarons/modeluploader.git
cd modeluploader
pip install .
Development Mode
git clone https://github.com/Maicarons/modeluploader.git
cd modeluploader
pip install -e ".[dev]"
Quick Start
1. Prerequisites
Before using, ensure:
huggingface_hubandmodelscopelibraries are installed- Logged in to HuggingFace:
huggingface-cli login - Logged in to ModelScope:
modelscope loginor have access token ready
2. Configure Repository IDs (Three Ways)
Method 1: Command-line Arguments (Recommended)
modeluploader --hf-repo your_username/hf_repo --ms-repo your_username/ms_repo
Method 2: Environment Variables
# Windows
set MODELUPLOADER_HF_REPO=your_username/hf_repo
set MODELUPLOADER_MS_REPO=your_username/ms_repo
set MODELUPLOADER_REPO_TYPE=model
set MODELUPLOADER_COMMIT_MESSAGE="Upload model files"
# Linux/macOS
export MODELUPLOADER_HF_REPO=your_username/hf_repo
export MODELUPLOADER_MS_REPO=your_username/ms_repo
export MODELUPLOADER_REPO_TYPE=model
export MODELUPLOADER_COMMIT_MESSAGE="Upload model files"
modeluploader
Method 3: Python API
from modeluploader import upload_to_huggingface, upload_to_modelscope
# Pass repo_id directly
upload_to_huggingface("./model", repo_id="your_username/hf_repo")
upload_to_modelscope("./model", repo_id="your_username/ms_repo")
3. Basic Usage
# Upload to both platforms (default)
modeluploader --hf-repo user/repo1 --ms-repo user/repo2
# Upload dataset with custom commit message
modeluploader \
--hf-repo user/dataset_repo \
--ms-repo user/dataset_repo \
--repo-type dataset \
--commit-message "Upload training dataset v1.0"
# Upload to HuggingFace only
modeluploader --platform hf --hf-repo user/repo1
# Upload to ModelScope only
modeluploader --platform ms --ms-repo user/repo2
# Specify upload directory
modeluploader --hf-repo user/repo1 --path /path/to/your/model
# Use ModelScope token
modeluploader --ms-repo user/repo2 --ms-token YOUR_TOKEN
4. Command-Line Arguments
| Argument | Description | Default |
|---|---|---|
--platform |
Select platform: hf, ms, both |
both |
--path |
Path to folder to upload | . (current directory) |
--hf-repo |
HuggingFace repository ID (format: username/repo_name) | Required |
--ms-repo |
ModelScope repository ID (format: username/repo_name) | Required |
--repo-type |
Repository type: model, dataset, or space |
model |
--commit-message |
Commit message for the upload | Upload model files |
--gitignore |
Path to .gitignore file |
.gitignore |
--ms-token |
ModelScope access token (optional) | None |
5. Using as Python Module
from modeluploader import (
upload_to_huggingface,
upload_to_modelscope,
load_gitignore_patterns
)
# Load ignore patterns
ignore_patterns = load_gitignore_patterns(".gitignore")
# Upload to HuggingFace
success_hf = upload_to_huggingface(
folder_path="./my_model",
ignore_patterns=ignore_patterns
)
# Upload to ModelScope
success_ms = upload_to_modelscope(
folder_path="./my_model",
token="your_token", # Optional
ignore_patterns=ignore_patterns
)
if success_hf and success_ms:
print("All uploads successful!")
Configuration
Environment Variables
You can set default configuration via environment variables:
MODELUPLOADER_HF_REPO: HuggingFace repository IDMODELUPLOADER_MS_REPO: ModelScope repository IDMODELUPLOADER_REPO_TYPE: Repository type (model,dataset, orspace)MODELUPLOADER_COMMIT_MESSAGE: Commit message for uploads
Command-line arguments override environment variables.
Priority Order
Configuration priority (highest to lowest):
- Command-line arguments (
--hf-repo,--ms-repo,--repo-type,--commit-message) - Environment variables (
MODELUPLOADER_*) - Direct parameters in code API calls
.gitignore Support
The tool automatically reads rules from .gitignore file and ignores:
- Python cache files (
__pycache__/,*.pyc) - Virtual environments (
venv/,.env) - IDE configuration files (
.idea/,.vscode/) - Build artifacts (
build/,dist/) - Other patterns defined in your
.gitignore
Language Detection
The tool automatically detects your system language and displays messages in:
- English (default)
- Chinese (if system locale is Chinese)
You can also manually set the language:
from modeluploader import set_language
# Force English
set_language('en')
# Force Chinese
set_language('zh')
Project Structure
modeluploader/
โโโ modeluploader/
โ โโโ __init__.py # Package initialization
โ โโโ __main__.py # Support for python -m
โ โโโ cli.py # Command-line interface
โ โโโ config.py # Configuration module
โ โโโ i18n.py # Internationalization module
โ โโโ gitignore_parser.py # .gitignore parser
โ โโโ huggingface_uploader.py # HuggingFace upload module
โ โโโ modelscope_uploader.py # ModelScope upload module
โโโ tests/
โ โโโ test_modeluploader.py # Unit tests
โโโ main.py # Backward compatibility entry
โโโ pyproject.toml # Project configuration
โโโ README.md # English documentation
โโโ README_zh.md # Chinese documentation
โโโ LICENSE # Apache 2.0 License
Development Guide
Run Tests
pytest tests/
Code Formatting
black modeluploader/
flake8 modeluploader/
Build Distribution Package
pip install build
python -m build
This generates .tar.gz and .whl files in the dist/ directory.
Publish to PyPI
# Install twine
pip install twine
# Upload to TestPyPI (testing)
twine upload --repository testpypi dist/*
# Upload to PyPI (production)
twine upload dist/*
FAQ
Q: How to upload to only one platform?
A: Use the --platform argument:
modeluploader --platform hf # HuggingFace only
modeluploader --platform ms # ModelScope only
Q: What if upload fails?
A: Check the following:
- Are you properly logged in to the platform?
- Is your network connection stable?
- Is the repository ID correct?
- Review the detailed error logs for troubleshooting
Q: How to customize ignored files?
A: Create or edit the .gitignore file in your project root and add patterns for files or directories to ignore.
Q: Can I configure repositories dynamically in code?
A: Yes, through these methods:
# Method 1: Pass parameters directly
from modeluploader import upload_to_huggingface
upload_to_huggingface(
"./model",
repo_id="user/repo",
repo_type="dataset",
commit_message="Custom message"
)
# Method 2: Set environment variables
import os
os.environ['MODELUPLOADER_HF_REPO'] = 'user/repo'
os.environ['MODELUPLOADER_REPO_TYPE'] = 'dataset'
os.environ['MODELUPLOADER_COMMIT_MESSAGE'] = 'Custom message'
from modeluploader import upload_to_huggingface
upload_to_huggingface("./model")
Contributing
Issues and Pull Requests are welcome!
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Acknowledgments
- HuggingFace Hub
- ModelScope
- All contributors
Contact
- Project Homepage: https://github.com/Maicarons/modeluploader
- Issue Tracker: https://github.com/Maicarons/modeluploader/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file modeluploadhelper-0.1.1.tar.gz.
File metadata
- Download URL: modeluploadhelper-0.1.1.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
691ee275008c0c757ac9564cb1a8d9d7a2d25054e4e7334806195e16b9e14282
|
|
| MD5 |
43244abc36180052768a878ddb5a0784
|
|
| BLAKE2b-256 |
dfd98c2fe1814b9f0b86599a01d6370ad12a17490075a224b238995c55cc82fa
|
File details
Details for the file modeluploadhelper-0.1.1-py3-none-any.whl.
File metadata
- Download URL: modeluploadhelper-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49a92ef6de044e140813409661b27672852e14b1c61b657c682440a358e8727e
|
|
| MD5 |
14845b263f157a06f0f9511c031aef66
|
|
| BLAKE2b-256 |
845b6d4155b56a92f6b58c60f0bb9cfd3019a563ddbd079adb2567d0ef4efce7
|