imagebind / README.md
fcastrovilli's picture
refactor: computeSimilarities
63b0848
metadata
title: Imagebind
emoji: 📚
colorFrom: red
colorTo: green
sdk: docker
pinned: false
license: mit
short_description: Small imagebind api implementation

ImageBind API Implementation

A FastAPI implementation of Facebook's ImageBind model for cross-modal embeddings.

Local Setup

  1. Install system dependencies:
sudo apt-get update && sudo apt-get install -y ffmpeg libsndfile1
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install Python dependencies:
pip install --no-cache-dir --upgrade -r requirements.txt
  1. Download and setup ImageBind:
python setup_imagebind.py
pip install --no-cache-dir .

Docker Setup

Build and run the container:

docker build -t imagebind-api .
docker run -p 7860:7860 imagebind-api

API Endpoints

The API will be available at http://localhost:7860 with the following endpoints:

POST /compute_embeddings

Generate embeddings for images, audio files, and text.

POST /compute_similarities

Compute similarities between embeddings with advanced filtering options:

  • Threshold filtering for minimum similarity scores
  • Top-K results limitation
  • Optional self-similarity inclusion
  • Score normalization
  • Detailed match information including original file/text references
  • Statistical analysis of similarity scores

GET /health

Basic health check endpoint

For detailed API documentation, visit http://localhost:7860/docs

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

API Authentication

The API uses Bearer token authentication. You need to include an authorization header with your API token in all requests:

# Set your API token as an environment variable
export API_TOKEN="your-api-token-here"

# Example curl request with authentication
curl -X POST "http://localhost:7860/compute_embeddings" \
     -H "Authorization: Bearer ${API_TOKEN}" \
     -H "Content-Type: multipart/form-data" \
     -F "texts=example text"

When running the Docker container, you can set the API token as an environment variable:

docker run -p 7860:7860 -e API_TOKEN="your-api-token-here" imagebind-api