Skip to main content
Open on GitHub

huggingface


title: Hugging Face Integration description: Learn how to use Hugging Face models, embeddings, and tools with LangChain.โ€‹

๐Ÿš€ Hugging Face Integration in LangChain

All functionality related to the Hugging Face Platform is available through the langchain-huggingface and langchain-community packages.


๐Ÿ“ฆ Installationโ€‹

Install the Hugging Face integration packages:

pip install langchain-huggingface

To use tools, embeddings, and TTS (Text-to-Speech), install:

pip install transformers datasets huggingface_hub pillow

๐Ÿค– Chat Modelsโ€‹

ChatHuggingFaceโ€‹

Use chat models via Hugging Faceโ€™s hosted models or APIs.

from langchain_huggingface import ChatHuggingFace
API Reference:ChatHuggingFace

๐Ÿ“„ Usage Example


๐Ÿ’ฌ LLMs (Text Generation)โ€‹

HuggingFaceEndpointโ€‹

Use models directly from Hugging Face Hub (via endpoint):

from langchain_huggingface import HuggingFaceEndpoint

llm = HuggingFaceEndpoint(
repo_id="tiiuae/falcon-7b-instruct",
task="text-generation"
)
API Reference:HuggingFaceEndpoint

๐Ÿ“„ Usage Example


HuggingFacePipelineโ€‹

Run models locally via Hugging Faceโ€™s transformers.Pipeline:

from langchain_huggingface import HuggingFacePipeline
API Reference:HuggingFacePipeline

๐Ÿ“„ Usage Example


๐Ÿง  Embedding Modelsโ€‹

HuggingFaceEmbeddingsโ€‹

from langchain_huggingface import HuggingFaceEmbeddings
API Reference:HuggingFaceEmbeddings

๐Ÿ“‚ Document Loadersโ€‹

HuggingFaceDatasetLoaderโ€‹

Load public datasets from Hugging Face Hub.

from langchain_community.document_loaders.hugging_face_dataset import HuggingFaceDatasetLoader

๐Ÿ“„ Usage Example


HuggingFaceModelLoaderโ€‹

Load model metadata and README from Hugging Face Hub.

from langchain_community.document_loaders import HuggingFaceModelLoader

ImageCaptionLoaderโ€‹

Use Hugging Face vision models to generate image captions.

from langchain_community.document_loaders import ImageCaptionLoader
API Reference:ImageCaptionLoader

๐Ÿ“ฆ Requires:

pip install transformers pillow

๐Ÿ› ๏ธ Toolsโ€‹

Hugging Face Hub Toolsโ€‹

Interact with Hugging Face tools directly using:

from langchain_community.agent_toolkits.load_tools import load_huggingface_tool
API Reference:load_huggingface_tool

๐Ÿ“ฆ Requires:

pip install transformers huggingface_hub

๐Ÿ“„ Usage Example


HuggingFaceTextToSpeechModelInferenceโ€‹

Wrapper around text-to-speech model using Hugging Face API:

from langchain_community.tools.audio import HuggingFaceTextToSpeechModelInference

๐Ÿ’ก For more examples and updates, refer to the official LangChain Hugging Face docs.


Was this page helpful?