A library to save, load, and use Hugging Face models locally.
Project description
hflocal
hflocal is a Python library designed to simplify the process of saving, loading, and using Hugging Face models locally. This library provides a user-friendly interface for handling pre-trained models from the Hugging Face repository.
Author
Anish KM
- GitHub: @AnishKMBtech
Features
- Save pre-trained models and tokenizers to a local directory
- Load pre-trained models and tokenizers from a local directory
- Use models with a simple pipeline interface for various NLP tasks
Installation
You can install the hflocal library using pip:
pip install hflocal
Usage
Saving a Model
To save a pre-trained model and its tokenizer to a local directory, use the save_model function:
from hflocal import save_model
# Save the 'bert-base-uncased' model to the './saved_model' directory
save_model('bert-base-uncased', './saved_model')
Loading a Model
To load a pre-trained model and its tokenizer from a local directory, use the load_model function:
from hflocal import load_model
# Load the model and tokenizer from the './saved_model' directory
model, tokenizer = load_model('./saved_model')
Using the Model Pipeline
To use a model with a simple pipeline interface for various NLP tasks, use the ModelPipeline class:
from hflocal import ModelPipeline
# Initialize the pipeline with the saved model
pipeline = ModelPipeline('./saved_model')
# Use the pipeline for inference
result = pipeline("Your input text here")
print(result)
Development
Setting Up the Development Environment
- Clone the repository:
git clone https://github.com/AnishKMBtech/hflocal.git
cd hflocal
- Create a virtual environment and activate it:
python -m venv venv
# On Unix/macOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
- Install the required dependencies:
pip install -r requirements.txt
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
- Hugging Face for providing the pre-trained models and tokenizers
- Transformers library for the model and tokenizer implementations
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 hflocal-0.1.0.tar.gz.
File metadata
- Download URL: hflocal-0.1.0.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bb17fc1b4b62809032f33ef5958fabfac268f34070cec29c8b17c09d5dcc826
|
|
| MD5 |
209c379752fe21c4a62378b98c1aa78f
|
|
| BLAKE2b-256 |
f8017944578bf1e3d313281ac2d7b9dae57bb881b15ad894533db1ffac9abe35
|
File details
Details for the file hflocal-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hflocal-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84e0b1a4c4a0918c8ca593d5bca3b6bcaa171d6ed28d743929b844f850e4dfd1
|
|
| MD5 |
1e44fe3dd937f2c3865770d0e749c489
|
|
| BLAKE2b-256 |
79da9c5b41a8a9ae2d3f681735a6948231953d8a233d6a106d5b96c6ea796b91
|