This directory contains standalone tools and utility services used by PotterDoc.
To maintain stability on hardware with <1GB RAM, Glaze supports offloading the heavy rembg background removal task to a serverless microservice.
- Optimized Dispatch: The system offloads the image's R2 CDN URL directly to the remote service. This ensures the production host does not have to download or process the image bytes, saving bandwidth and memory.
- Security: The service is secured with an API Key (
X-API-Key) validated against amodal.Secret. - Local Fallback: If
REMOTE_REMBG_URLis not configured, the system falls back to a localu2netpmodel with 640px downscaling.
- Set up Auth Token: Create a Modal secret named
piece-image-segment-secretwith anAUTH_TOKENkey. - Install Modal:
bazel run @uv//:uv -- tool install modal - Authenticate:
modal setup - Deploy:
modal deploy services/piece_image_segment_service.py - Capture the URL: The output will provide a permanent URL, e.g.,
https://your-workspace-name--crop.modal.run.
Update your production .env file with the following variables:
| Variable | Description |
|---|---|
REMOTE_REMBG_URL |
The URL of your deployed Modal service (e.g. https://phil--crop.modal.run). |
MODAL_AUTH_TOKEN |
The secure token you generated for the piece-image-segment-secret. |
# Example .env additions
REMOTE_REMBG_URL="https://your-workspace-name--crop.modal.run"
MODAL_AUTH_TOKEN="your-secure-random-token"- Restart Service:
cd ~/glaze docker compose up -d
The Glaze Import Tool at /tools/glaze-import is a browser-based admin workflow for seeding the public GlazeType and GlazeCombination libraries from physical test-tile photographs (JPEG, PNG, or HEIC where the browser supports it). It replaces manual admin entry for bulk imports.
Only staff users (
is_staff = True) can access this tool.
- Upload — drag-and-drop or select source images from disk, or use Upload Via Cloud, which uploads the file to R2 via a presigned URL and loads it back from the CDN.
- Crop — draw a rotatable square crop box over each image. The box may extend beyond the image boundary; overflow becomes transparent. A live preview updates after 200 ms of inactivity.
- OCR — optionally draw a rotatable OCR region box on the crop preview to focus text extraction. Click Run OCR For All Records — Tesseract reads each region and auto-fills the name, glaze kind, first/second glaze, runs, and food-safe fields. OCR understands structured labels (
1st Glaze: …/2nd Glaze: …) and annotation lines (CAUTION: RUNS,NOT FOOD SAFE). - Review — verify and correct each record's parsed fields, then check the Reviewed box. Combination names are auto-computed as
<first>!<second>and are read-only. - Import — sends all reviewed records and compressed crop images to the backend. A per-record progress list tracks each file; results show admin links to every created object.
If any records are skipped as duplicates, a 6. Reconcile tab appears with the scraped fields and a direct link to the existing admin record.
| Record kind | Created objects |
|---|---|
glaze_type |
Public GlazeType + a matching single-layer public GlazeCombination |
glaze_combination |
Public GlazeCombination with two ordered layers (both referenced GlazeType rows must already exist as public records) |
runs and is_food_safe parsed from OCR are written to both GlazeType and GlazeCombination on creation.