forked from erictik/midjourney-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.human.ts
28 lines (26 loc) · 870 Bytes
/
verify.human.ts
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
import { HfInference } from "@huggingface/inference";
export class VerifyHuman {
private inference: HfInference;
constructor(HuggingFaceToken: string) {
if (HuggingFaceToken === "") {
throw new Error("HuggingFaceToken is required");
}
this.inference = new HfInference(HuggingFaceToken);
}
async verify(imageUri: string, categories: string[]) {
console.log("verify----start", imageUri, categories);
const imageCates = await this.inference.imageClassification({
data: await (await fetch(imageUri)).blob(),
model: "google/vit-base-patch16-224",
});
console.log("verify----response", { imageCates });
for (const imageCate of imageCates) {
const { label } = imageCate;
for (const category of categories) {
if (label.includes(category)) {
return category;
}
}
}
}
}