Spaces:
Runtime error
Runtime error
File size: 1,345 Bytes
e008c35 | 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 | import { spawnSync } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
const envPath = join(process.cwd(), ".env.local");
if (existsSync(envPath)) {
for (const line of readFileSync(envPath, "utf8").split("\n")) {
const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
if (match && !process.env[match[1]]) {
process.env[match[1]] = match[2];
}
}
}
const localPython = join(process.cwd(), ".venv", "bin", "python");
const python = process.env.SAM_PYTHON || (existsSync(localPython) ? localPython : "python3");
const checkpoint = process.env.SAM_CHECKPOINT;
const result = spawnSync(
python,
[
"-c",
"import torch, segment_anything; print('torch=' + torch.__version__); print('segment_anything=ok')"
],
{ encoding: "utf8" }
);
if (result.status !== 0) {
console.error("SAM Python dependencies are not installed for:", python);
console.error(result.stderr || result.stdout);
process.exit(1);
}
if (!checkpoint) {
console.error("SAM_CHECKPOINT is not set.");
process.exit(1);
}
if (!existsSync(checkpoint)) {
console.error(`SAM_CHECKPOINT does not exist: ${checkpoint}`);
process.exit(1);
}
console.log(result.stdout.trim());
console.log(`checkpoint=${checkpoint}`);
console.log(`modelType=${process.env.SAM_MODEL_TYPE || "vit_h"}`);
|