File size: 2,829 Bytes
8d5cf35
 
 
 
 
 
 
 
 
b36cb8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
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:

```bash
pip install -r requirements.txt
```

3. Set up environment variables (optional, defaults are provided):

```bash
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:

```bash
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:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc

## 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:

```bash
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.