Introduction to huggingface_hub
The huggingface_hub
library is a powerful tool designed for interaction with the Hugging Face Hub, a platform that strives to democratize open-source Machine Learning for creators and collaborators. It serves as an exceptional resource for discovering pre-trained models and datasets that can enhance various projects. Moreover, users are able to explore thousands of machine learning applications hosted on the Hub and even create and share their own models, datasets, and demos within the community. This library facilitates all these engaging activities using simple Python commands.
Key Features
The huggingface_hub
offers multiple remarkable features, including:
- Download files: Access models and datasets easily with straightforward commands.
- Upload files: Share your creations or updates by uploading files to the Hub.
- Manage repositories: Organize and maintain your repositories seamlessly to support your work.
- Run Inference: Execute inference on deployed models effortlessly, aiding in research and application development.
- Search functionalities: Discover models, datasets, and Spaces with advanced search options.
- Share Model Cards: Document and share details of your models using Model Cards.
- Community Engagement: Collaborate and communicate through pull requests and comments, actively participating in the growing community.
Installation
To get started with the huggingface_hub
library, it's easily installable via pip:
pip install huggingface_hub
For those using conda, installation through this package manager is also available. Additionally, the library comes with optional dependencies for various specific needs, such as enhancing the Inference experience:
pip install huggingface_hub[inference]
For comprehensive installation instructions and details on optional dependencies, refer to the installation guide.
Quick Start Guide
Download Files
To download files, use simple Python commands. Here’s how to download a single file:
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="tiiuae/falcon-7b-instruct", filename="config.json")
For downloading an entire repository:
from huggingface_hub import snapshot_download
snapshot_download("stabilityai/stable-diffusion-2-1")
User Authentication
Authenticate your applications using tokens. Simply log in via this command:
huggingface-cli login
# or using an environment variable
huggingface-cli login --token $HUGGINGFACE_TOKEN
Creating a Repository
Creating a repository is straightforward:
from huggingface_hub import create_repo
create_repo(repo_id="super-cool-model")
Upload Files
Upload a single file with:
from huggingface_hub import upload_file
upload_file(
path_or_fileobj="/home/lysandre/dummy-test/README.md",
path_in_repo="README.md",
repo_id="lysandre/test-model",
)
For uploading an entire folder:
from huggingface_hub import upload_folder
upload_folder(
folder_path="/path/to/local/space",
repo_id="username/my-cool-space",
repo_type="space",
)
To get more detailed input, refer to the upload guide.
Integration with the Hub
The huggingface_hub
partners with open-source ML libraries for free model hosting and versioning. The benefits of integration include hosting, built-in versioning, serverless inference, and more. Interested libraries can open an issue for discussions, and a step-by-step guide is available for assistance.
Contributing to the Community
Contributions in any form, whether feature requests, bug reports, or documentation improvements, are greatly valued. Participation in discussions, helping others, and enhancing documentation are all vital ways to contribute. The contribution guide outlines how to get started, ensuring everyone can play a part in the vibrant community.
Whether you’re downloading pre-trained models or engaging with fellow enthusiasts, the huggingface_hub
library makes it simple and rewarding to be part of an ever-growing machine learning ecosystem.