Identify LEGO parts from photos, detect their color, and sort them into storage boxes using AI.
- Part recognition via Brickognize API
- Color detection using OpenCV k-means clustering
- AI sorting — classifies parts into boxes/cavities via an LLM (Cerebras / OpenAI-compatible)
- Mobile web UI — capture parts with your phone camera, review and save results
- CLI mode for testing with local images
pip install -r requirements.txt
cp .env.example .env
# edit .env — at minimum set CEREBRAS_API_KEYpython web_app.pyOpen http://localhost:8080 — point your camera at a LEGO part and tap capture.
python main.pyUses assets/test.jpg by default (override with IMAGE_FILE env var).
All settings are environment variables (see .env.example):
| Variable | Default | Description |
|---|---|---|
API_URL |
https://api.brickognize.com/predict/ |
Brickognize endpoint |
CONFIDENCE_THRESHOLD |
0.5 |
Minimum detection confidence |
REQUEST_TIMEOUT |
5 |
API request timeout (seconds) |
KMEANS_CLUSTERS |
3 |
Color quantization clusters |
MIN_VALID_PIXELS |
50 |
Minimum pixels for color detection |
CEREBRAS_API_KEY |
— | LLM API key for sorting |
CEREBRAS_MODEL |
gpt-oss-120b |
LLM model name |
CEREBRAS_API_BASE |
https://api.cerebras.ai/v1 |
LLM API base URL |
- Create a new Web Service on Render
- Set Build Command to
pip install -r requirements.txt - Set Start Command to
python web_app.py - Add all env vars from
.env.examplein the Render dashboard - Deploy
├── web_app.py # FastAPI web server
├── main.py # CLI entry point
├── color_detect.py # Color detection via k-means
├── sort.py # LLM-based part sorting
├── templates/ # Web frontend
└── data/ # Saved parts & photos