FastAPI / README.md
ravi19's picture
Add Hugging Face Space metadata
8d5cf35
metadata
title: FastAPI App
emoji: 
colorFrom: gray
colorTo: purple
sdk: docker
app_file: app.py
pinned: false

Image Similarity Search API

A FastAPI application for image similarity search using CLIP embeddings and Qdrant vector database.

Features

  • Upload images and store their vector embeddings
  • Search for similar images using an uploaded image or base64 encoded image
  • Secure API with API key authentication
  • Well-organized, modular codebase following OOP principles

Installation

  1. Clone this repository
  2. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables (optional, defaults are provided):
export QDRANT_URL="your-qdrant-url"
export QDRANT_API_KEY="your-qdrant-api-key"
export COLLECTION_NAME="your-collection-name"
export API_KEY="your-api-key"
export PORT=8000
export ENVIRONMENT="production"  # Or "development" for debug mode with auto-reload

Usage

Run the application:

python app.py

The API will be available at http://localhost:8000 (or the port specified in environment variables).

API Documentation

Once running, API documentation is available at:

API Endpoints

  • POST /add-image/: Add an image to the database
  • POST /add-images-from-folder/: Add all images from a folder to the database
  • POST /search-by-image/: Search for similar images using an uploaded image
  • POST /search-by-image-scan/: Search for similar images using a base64 encoded image
  • GET /collections: List all collections in the database
  • GET /health: Health check endpoint

Project Structure

image_similarity_api/
│
├── app.py                 # Main application entry point
├── config.py              # Configuration settings
├── models/
│   ├── __init__.py
│   └── schemas.py         # Pydantic models
├── services/
│   ├── __init__.py
│   ├── embedding.py       # Image embedding service
│   ├── security.py        # Security service
│   └── vector_db.py       # Vector database service
├── api/
│   ├── __init__.py
│   └── routes.py          # API routes
├── requirements.txt       # Project dependencies
└── README.md              # Project documentation

Development

For development, set the ENVIRONMENT variable to "development" for auto-reload:

export ENVIRONMENT="development"
python app.py

Deployment

This application can be deployed to any platform that supports Python applications:

  1. Docker
  2. Kubernetes
  3. Cloud platforms (AWS, GCP, Azure, etc.)
  4. Serverless platforms (with appropriate adapters)

Remember to set all required environment variables in your production environment.