image-search-tool

Image Search Tool

An intelligent, self-hosted web application that allows you to easily index and search through your local image collections using semantic text queries (powered by CLIP), optical character recognition (OCR), and reverse image search.

Features

Architecture

Prerequisites

  1. Python 3.8+
  2. Tesseract OCR: You must have Tesseract installed on your system.
    • Windows: Download the installer from UB-Mannheim Tesseract. You may need to add the installation directory to your system’s PATH, or configure the path in ocr_service.py if it is not detected automatically:
      pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
      
    • macOS: brew install tesseract
    • Linux (Ubuntu/Debian): sudo apt-install tesseract-ocr

Installation

  1. Navigate to the project directory:
    cd path/to/image_search_tool
    
  2. Install the required Python dependencies:
    pip install -r requirements.txt
    

Usage

  1. Start the FastAPI server:
    uvicorn main:app --reload --host 0.0.0.0 --port 8000
    
  2. Open your web browser and navigate to http://localhost:8000.
  3. Indexing:
    • Before you can search, you need to index a directory of images.
    • Enter the absolute path to a folder containing images on your local machine and click the “Index” button.
    • Depending on the number of images, this may take a few moments. The server runs the vision transformer and OCR on each image in the background.
  4. Search by Text: Enter a descriptive phrase (e.g., “a sunny beach”, “invoice document”) into the search bar.
  5. Search by Image: Use the file upload option in the UI to perform a reverse image search.

API Endpoints

State Management

When you index a directory, the tool automatically saves the embeddings and indexing metadata to image_index.pt and image_index.pt.json in the project root. Upon restarting the application, it will gracefully attempt to load this cached index so you don’t have to re-index your images.