All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 1m2s
Barcode scanning - Scan barcode in the food sheet reads UPC-A/E and EAN-13/8 live from the camera with ZXing WebAssembly (bundled, precached, CSP allows wasm), with photo and typed-digit fallbacks - Lookups check saved foods first (offline), then local copies of USDA FoodData Central Branded Foods and Open Food Facts, then the live Open Food Facts API; API answers and misses are cached - Server imports refresh in a low-priority child process: USDA when a new archive is published, Open Food Facts weekly by streaming its CSV export; each import builds a new table and swaps it in atomically - Every available nutrient is kept: foods and entries gain optional barcode (GTIN-14) and extra nutrients, shown under More nutrients and included in JSON exports - Settings shows the size, date and any error for each product copy Label scanning - Scan label sends a downscaled photo to the server, read with PaddleOCR PP-OCRv5 (server detection, English recognition) on ONNX Runtime CPU, about 1.3 s median - Parser handles US/Canadian, linear, Spanish and EU per-100 g panels, tilted photos, OCR misspellings and %DV cross-checks - Models are pinned and checksum-verified at image build time Container - Runtime moves to Debian slim for ONNX Runtime's glibc build; other platforms' binaries are pruned - Smoke tests now read a fixture label inside the container - README and Unraid docs cover disk use, network access and refresh Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
48 lines
1.8 KiB
JavaScript
48 lines
1.8 KiB
JavaScript
// Downloads the pinned PaddleOCR (PP-OCRv5) ONNX models used for label scans.
|
|
// node scripts/fetch-models.js [directory] (default: models)
|
|
import { createHash } from "node:crypto";
|
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { join, resolve } from "node:path";
|
|
|
|
export const models = [
|
|
{
|
|
dir: "det",
|
|
repo: "PaddlePaddle/PP-OCRv5_server_det_onnx",
|
|
revision: "dcf248c4dcc064c6d030db241255f9e8fbc6733a",
|
|
sha256: "10803475a591f7dc623e24670fb5752ec94d39a1f8cf069aac1b6f0ce19cfc85",
|
|
},
|
|
{
|
|
dir: "rec",
|
|
repo: "PaddlePaddle/en_PP-OCRv5_mobile_rec_onnx",
|
|
revision: "3fafbc3b5dcf93dd72add9f48368be8a3a2cd33b",
|
|
sha256: "b5f833dfc5d0eb71da397b4efa06ebeee9b431b690a47d6af40d77d8eabc557f",
|
|
},
|
|
];
|
|
|
|
async function get(repo, revision, file) {
|
|
const url = `https://huggingface.co/${repo}/resolve/${revision}/${file}`;
|
|
const response = await fetch(url);
|
|
if (!response.ok) throw new Error(`${url}: ${response.status}`);
|
|
return Buffer.from(await response.arrayBuffer());
|
|
}
|
|
|
|
const root = resolve(process.argv[2] || "models");
|
|
for (const model of models) {
|
|
const dir = join(root, model.dir);
|
|
mkdirSync(dir, { recursive: true });
|
|
const onnx = join(dir, "inference.onnx");
|
|
const current =
|
|
existsSync(onnx) &&
|
|
createHash("sha256").update(readFileSync(onnx)).digest("hex");
|
|
if (current === model.sha256) continue;
|
|
const data = await get(model.repo, model.revision, "inference.onnx");
|
|
const digest = createHash("sha256").update(data).digest("hex");
|
|
if (digest !== model.sha256)
|
|
throw new Error(`${model.repo} checksum mismatch: ${digest}`);
|
|
writeFileSync(onnx, data);
|
|
writeFileSync(
|
|
join(dir, "inference.yml"),
|
|
await get(model.repo, model.revision, "inference.yml"),
|
|
);
|
|
console.log(`Fetched ${model.repo}`);
|
|
}
|