With multi-center k=5 reference the gate is already more selective;
0.55 was too strict for non-standard angles (e.g. spread intestinal
specimens). p5 of training set is 0.507 so 0.35 still filters true
outliers while allowing valid pathology images through.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add cluster_centers.npy: k=5 from 2002 training images
Computed from all pig/data training images (CLOS/EC/PED/ROTA/SAL/mix/mix_EC).
Sanity: mean max-sim=0.719, p10=0.601 vs threshold 0.55.
~92% of training images pass vs old avg12 which blocked many valid images.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add k-means multi-center reference for similarity gate
- model.py: predict_image accepts 2-D ref_emb (cluster centers);
sim = max cosine similarity to any center; thres default 0.55
- main.py: load cluster_centers.npy if present, else avg12_embedding.npy
- scripts/compute_cluster_centers.py: extract embeddings from all
training images, k-means k=5, save cluster_centers.npy
Run script once to generate cluster_centers.npy, then redeploy.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove LOW_CONF block: in-range images should always be classified
Images passing the similarity gate (is_in_criteria=True) are already
confirmed as in-distribution. Low model confidence in those cases just
means borderline bacteria/virus — still a valid classification.
Only keep HIGH_CONF bypass (>= 0.85) to fix high-confidence images
being wrongly blocked by sim gate (e.g. organ specimens on black bg).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three-zone confidence decision: bypass sim gate for high-conf, reject low-conf
Image src used raw f.url without key, causing 422 on private
dashboard routes and onerror hiding all images silently.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update test script for HF Space with full validation
- Point to HF Space URL with X-API-Key header
- Test all 7 images with expected result validation
- Print PASS/FAIL per image with class, probability, elapsed time
- Summary line at end
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix disk metric to show container usage instead of host disk
psutil disk_usage shows host's 1.7TB disk which is meaningless.
Now calculates actual /api directory size and compares against
HF Spaces 50GB container limit.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix status metrics to read container cgroup limits instead of host
psutil reports host machine stats (126GB RAM) inside Docker.
Now reads from cgroup v2 (/sys/fs/cgroup/memory.current/.max),
falls back to cgroup v1, then psutil as last resort.
This correctly shows the container's 16GB RAM allocation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
New module: app/dashboard/
- router.py: APIRouter with 5 endpoints
GET /dashboard/ → HTML dashboard page
GET /dashboard/status/ → CPU / RAM / Disk metrics via psutil
GET /dashboard/logs/ → tail of app.log (last N lines)
GET /dashboard/database/→ inference_results.csv as JSON
GET /dashboard/uploads/ → list of uploaded images
GET /dashboard/uploads/{filename} → serve image file
- index.html: single-page dashboard with auto-refresh every 5s
Status cards (CPU%, RAM, Disk), Logs viewer, Records table,
Uploaded images grid
app/main.py: register dashboard router
requirements.txt: add psutil
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix missing uploads directory creation in container
os.makedirs(save_dir, exist_ok=True) before writing uploaded file,
so the uploads/ dir is auto-created even when not present on disk.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add HF Space metadata header to README.md (sdk: docker, app_port: 7860)
- Change exposed port from 8000 to 7860 (HF Spaces requirement)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix 5 bugs in upload validation, inference, and file cleanup
- Bug1: Replace second-precision timestamp with uuid suffix to prevent
filename collision under concurrent requests
- Bug2: Add file extension whitelist in save_uploaded_file; raise
ValueError for unsupported types before writing to disk
- Bug3: Remove misleading comment claiming SIM_THRES default is 0.75
- Bug4: Explicitly check model output keys and raise KeyError instead
of silently falling back to positional indices
- Bug5: Call os.remove(saved_path) in preprocessing failure path to
prevent orphaned files accumulating in uploads/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>