This Jupyter Notebook (huggingface.ipynb
) demonstrates how to use the Hugging Face transformers
library for text generation, summarization, or other NLP tasks.
Prerequisites Ensure you have the following installed:
- Python 3.7+
transformers
librarytorch
(if using PyTorch models)requests
(for API calls)
To install dependencies, run:
pip install transformers torch requests
Setup
- Get Your Hugging Face API Key
- Sign up at Hugging Face
- Navigate to
Settings
>Access Tokens
- Create an API token
- Set Up Your API Key Set your API key as an environment variable:
Windows
set HF_API_KEY=your_api_key
macOS/Linux
export HF_API_KEY=your_api_key
Usage Running the Notebook
- Open Jupyter Notebook:
jupyter notebook
- Load
huggingface.ipynb
and execute the cells step by step.
Features
- Text generation using Hugging Face models
- API-based and local model inference
- Error handling and logging
Customization
- Modify the prompt in the notebook to fit your use case.
- Change the model used by updating the
model_name
variable.