Files
mem0/notebooks/hugging_face_hub.ipynb
T

5.5 KiB

Cookbook for using Hugging Face Hub with Embedchain

Step-1: Install embedchain package

In [ ]:
!pip install embedchain
In [ ]:
!pip install embedchain[dataloaders]

You can find your HUGGINGFACE_ACCESS_TOKEN key on your Hugging Face Hub dashboard and install the dependencies

In [ ]:
!pip install embedchain[huggingface-hub]
In [ ]:
!pip install embedchain[opensource]
In [ ]:
import os
from embedchain import Pipeline as App

os.environ["HUGGINGFACE_ACCESS_TOKEN"] = "hf_xxx"

Step-3: Define your llm and embedding model config

In [ ]:
config = """
llm:
  provider: huggingface
  config:
    model: 'google/flan-t5-xxl'
    temperature: 0.5
    max_tokens: 1000
    top_p: 0.8
    stream: false

embedder:
  provider: huggingface
  config:
    model: 'sentence-transformers/all-mpnet-base-v2'
"""

# Write the multi-line string to a YAML file
with open('huggingface.yaml', 'w') as file:
    file.write(config)

Step-4 Create embedchain app based on the config

In [ ]:
app = App.from_config(yaml_path="huggingface.yaml")

Step-5: Add data sources to your app

In [ ]:
app.add("https://www.forbes.com/profile/elon-musk")
In [ ]:
while(True):
    question = input("Enter question: ")
    if question in ['q', 'exit', 'quit']:
        break
    answer = app.query(question)
    print(answer)
In [ ]: