Hugging Face Integration
Import Hugging Face datasets into Pixeltable and run CLIP, Sentence Transformers, ViT, and DETR as computed columns without an API key.
Challenge
Hugging Face gives you datasets and model weights. Production still needs a table that holds the rows, a way to run those models on insert, and an index that stays current. A notebook that loads a Dataset, loops tensors, and writes vectors to disk does not update when a new split arrives. CLIP for image search and a Sentence Transformer for captions usually live in two scripts. Pixeltable already stores Image and String columns. The integration is the UDFs in pixeltable.functions.huggingface and the import helper that maps Dataset feature types onto those columns.
Solution
Declare the table with TableModel. Use clip.using and sentence_transformer.using on EmbeddingIndex, or vit_for_image_classification and detr_for_object_detection as computed fields. Weights download from the Hub and run locally; there is no Hugging Face Inference API key on this path. pip install torch transformers sentence-transformers datasets as the model family requires. To load a Hub dataset, pxt.io.import_huggingface_dataset maps feature types (Image, Audio, string, ClassLabel, and the rest documented on the import page) into a new table. An app that already has a schema inserts rows the same way it inserts any other media.
Integration Steps
Step 1 of 4Declare an Image column and a CLIP embedding index so text and stills share one space.
import pixeltable as pxtfrom pixeltable.functions.huggingface import clipTableModel = pxt.model_base()clip_embed = clip.using(model_id='openai/clip-vit-base-patch32')class Images(TableModel, name='images'):image: pxt.Imagename: pxt.String | None__indexes__ = [pxt.EmbeddingIndex(image, embedding=clip_embed),]@pxt.querydef search_images(query: str, limit: int = 5):sim = Images.image.similarity(string=query) # string= for a sentence; image= for a stillreturn (Images.order_by(sim, asc=False).limit(limit).select(Images.image, Images.name, sim))# pxt schema update app.py hf_vision -f
💡 embedding= on an Image column registers CLIP for both stills and query strings. similarity(string=) ranks by a sentence. similarity(image=) ranks by another still. torch and transformers are required.
Key Benefits
Use Cases
Technical Requirements
Learn More
Related articles
Ready to Integrate Hugging Face?
Get started with Pixeltable and Hugging Face in minutes.
pip install pixeltable