Skip to main content

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 .gitignore to 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_hub and modelscope libraries are installed
  • Logged in to HuggingFace: huggingface-cli login
  • Logged in to ModelScope: modelscope login or 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 ID
  • MODELUPLOADER_MS_REPO: ModelScope repository ID
  • MODELUPLOADER_REPO_TYPE: Repository type (model, dataset, or space)
  • MODELUPLOADER_COMMIT_MESSAGE: Commit message for uploads

Command-line arguments override environment variables.

Priority Order

Configuration priority (highest to lowest):

  1. Command-line arguments (--hf-repo, --ms-repo, --repo-type, --commit-message)
  2. Environment variables (MODELUPLOADER_*)
  3. 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:

  1. Are you properly logged in to the platform?
  2. Is your network connection stable?
  3. Is the repository ID correct?
  4. 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!

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Acknowledgments

Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modeluploadhelper-0.1.1.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modeluploadhelper-0.1.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

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

Hashes for modeluploadhelper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 691ee275008c0c757ac9564cb1a8d9d7a2d25054e4e7334806195e16b9e14282
MD5 43244abc36180052768a878ddb5a0784
BLAKE2b-256 dfd98c2fe1814b9f0b86599a01d6370ad12a17490075a224b238995c55cc82fa

See more details on using hashes here.

File details

Details for the file modeluploadhelper-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for modeluploadhelper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49a92ef6de044e140813409661b27672852e14b1c61b657c682440a358e8727e
MD5 14845b263f157a06f0f9511c031aef66
BLAKE2b-256 845b6d4155b56a92f6b58c60f0bb9cfd3019a563ddbd079adb2567d0ef4efce7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page