Back to Mem0

Hugging Face Hub

embedchain/notebooks/hugging_face_hub.ipynb

2.0.11.3 KB
Original Source

Cookbook for using Hugging Face Hub with Embedchain

Step-1: Install embedchain package

python
!pip install embedchain[huggingface_hub,opensource]

You can find your HUGGINGFACE_ACCESS_TOKEN key on your Hugging Face Hub dashboard

python
import os
from embedchain import App

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

Step-3 Create embedchain app and define your config

python
app = App.from_config(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"
        }
    }
})

Step-4: Add data sources to your app

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