Spaces:
Sleeping
Sleeping
File size: 2,993 Bytes
a05a818 | 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 108 | ---
title: Image Selector Backend
emoji: ๐ผ๏ธ
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
license: mit
---
# Image Selector Backend API
A FastAPI backend for intelligent image deduplication and selection. Upload images, group similar ones using ResNet50 embeddings, and keep only the best image from each group based on aesthetics scoring.
## ๐ Features
- **Smart Deduplication**: Groups similar images using deep learning embeddings
- **Aesthetics Scoring**: Ranks images within each group using a CLIP-based aesthetics model
- **REST API**: Simple endpoints for upload, process, progress tracking, and download
- **Per-User Sessions**: Each user gets isolated processing and temporary storage
- **Auto Cleanup**: Temporary files are removed after download
## ๐ก API Endpoints
### Health Check
```
GET /
```
Returns: `{"status": "ok"}`
### Upload Images
```
POST /upload
```
Form fields:
- `user_id` (text): Your unique session ID
- `file` (file): Image file to upload
### Start Processing
```
POST /process
```
Form fields:
- `user_id` (text): Your session ID
- `similarity` (float, optional): Similarity threshold (default: 0.87)
- `use_aesthetics` (bool, optional): Enable aesthetics scoring (default: true)
### Check Progress
```
GET /progress/{user_id}
```
Returns processing status, percentage, and ETA.
### Download Results
```
GET /download/{user_id}
```
Returns a ZIP file containing the best images from each group.
## ๐ง How It Works
1. **Upload**: Send images with a unique `user_id`
2. **Process**: Trigger processing - the backend will:
- Generate embeddings for all images
- Group similar images (similarity threshold configurable)
- Score each image using an aesthetics model
- Keep the best image from each group
3. **Download**: Retrieve a ZIP of selected images
4. **Auto-cleanup**: All temporary files are deleted after download
## ๐ป Local Development
```bash
git clone <this-repo>
cd <repo-folder>
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 7860
```
## ๐จ Frontend
Use with the web UI:
- [Image Selector Frontend](https://github.com/basilbenny1002/image-selector-front-end)
## ๐ฆ Tech Stack
- **FastAPI**: Modern async web framework
- **PyTorch**: Deep learning for embeddings
- **ResNet50**: Feature extraction model
- **CLIP**: Aesthetics prediction model
- **SQLite**: Temporary embeddings storage
## โ ๏ธ Notes for HuggingFace Spaces
- Uses `/tmp` for ephemeral storage (free tier)
- For persistent storage, upgrade to a paid tier and data will use `/data`
- Model weights download on first run (~500MB for ResNet50 + aesthetics model)
- GPU recommended for faster processing (upgrade to T4 or better)
## ๐ License
MIT License - see LICENSE file
## ๐ Project Origin
Based on [Image-Selecter](https://github.com/basilbenny1002/Image-Selecter)
|