Getting Started With Hugging Face-Installation and setUp
Dhanushkumar R
Microsoft Learn Student Ambassador - GOLD |Data Science @BigTapp Analytics|Ex-Intern @IIT Kharagpur|Machine Learning|Deep Learning|Data Science|Gen AI|LLM | Azure AI&Data |Databricks |Technical Blogger ??????
Hub Client Library :
The huggingface_hub library allows us to interact with Hugging FaceHub wich is a ML platform .There are hundreds of pre trained models and datasets hosted on te hub.The models and datasets that are created by u also can be hosted.
It mostly deals with PYTHON
INSTALLATION:
To install Hugging Face :
pip install git+https://github.com/huggingface/huggingface_hub
Repositories on the Hub are git version controlled, and we can download a single file or the whole repository.The files are downloaded with the "hf_hub_download()".This function will download and cache a file on our local disk.
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="google/pegasus-xsum", filename="config.json")
Login
In a lot of cases, we must be logged in with a Hugging Face account to interact with the Hub such as download private repos, upload files and so on.
huggingface-cli login
huggingface-cli login --token $HUGGINGFACE_TOKEN
OR
We can programmatically login using?login()?in a notebook or a script:
from huggingface_hub import login
login()
Create a repository
In order to create repo()
from huggingface_hub import HfApi
api = HfApi()
api.create_repo(repo_id="super-cool-model")
Download files
Repositories on the Hub are git version controlled, and users can download a single file or the whole repository.? the?hf_hub_download()?function can be used to download files. This function will download and cache a file on your local disk.
the repository id and the filename of the file are required to download.
Example consider Pegasus model config gile:
Pegasus:
Tips:
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="google/pegasus-xsum", filename="config.json")
领英推荐
Upload files
To upload files use upload_file()
The following things should be mentioned:
1.Path to the file to upload
2.The path of the file in repo
3.The repo id of where we wanna add the file .
from huggingface_hub import HfApi
api = HfApi()
api.upload_file(
path_or_fileobj ="/home/dir/...",
path_in_repo = "Readme.md",
repo_id = "username/test_dataset"
)
Installation
Install with pip
pip install --upgrade huggingface_hub
Install optional dependencies
pip install 'huggingface_hub[tensorflow]'
pip install 'huggingface_hub[cli,torch]'
Install from source
pip install git+https://github.com/huggingface/huggingface_hub
or
pip install git+https://github.com/huggingface/huggingface_hub@my-feature-branch
Editable install
git clone https://github.com/huggingface/huggingface_hub.git
cd huggingface_hub
pip install -e .
Installing with Conda
conda install -c conda-forge huggingface_hub
Conclusion:
This article includes what is hugging ce and the installationa and the setup.Th following articles will cover more concepts related to Hgging Face.