2025-01-03 01:44:25 +03:00
|
|
|
import AddFaceIcon from "@/components/icons/AddFaceIcon";
|
2025-01-05 00:21:47 +03:00
|
|
|
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
2025-03-17 22:50:13 +03:00
|
|
|
import CreateFaceWizardDialog from "@/components/overlay/detail/FaceCreateWizardDialog";
|
2025-04-24 02:27:46 +03:00
|
|
|
import TextEntryDialog from "@/components/overlay/dialog/TextEntryDialog";
|
2024-11-26 23:41:49 +03:00
|
|
|
import UploadImageDialog from "@/components/overlay/dialog/UploadImageDialog";
|
2025-04-11 00:33:51 +03:00
|
|
|
import FaceSelectionDialog from "@/components/overlay/FaceSelectionDialog";
|
2025-05-09 16:36:44 +03:00
|
|
|
import { Button, buttonVariants } from "@/components/ui/button";
|
|
|
|
|
import {
|
|
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
|
|
|
|
AlertDialogDescription,
|
|
|
|
|
AlertDialogFooter,
|
|
|
|
|
AlertDialogHeader,
|
|
|
|
|
AlertDialogTitle,
|
|
|
|
|
} from "@/components/ui/alert-dialog";
|
2025-03-18 17:32:15 +03:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
} from "@/components/ui/dialog";
|
2025-01-03 01:44:25 +03:00
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
2025-04-03 17:17:29 +03:00
|
|
|
DropdownMenuSeparator,
|
2025-01-03 01:44:25 +03:00
|
|
|
} from "@/components/ui/dropdown-menu";
|
2024-11-26 23:41:49 +03:00
|
|
|
import { Toaster } from "@/components/ui/sonner";
|
2025-01-03 01:44:25 +03:00
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "@/components/ui/tooltip";
|
2025-03-10 18:01:52 +03:00
|
|
|
import useKeyboardListener from "@/hooks/use-keyboard-listener";
|
2024-11-26 23:41:49 +03:00
|
|
|
import useOptimisticState from "@/hooks/use-optimistic-state";
|
2025-01-05 00:21:47 +03:00
|
|
|
import { cn } from "@/lib/utils";
|
2025-03-28 21:52:12 +03:00
|
|
|
import { Event } from "@/types/event";
|
2025-10-07 22:43:06 +03:00
|
|
|
import { FaceLibraryData } from "@/types/face";
|
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2025-03-28 21:52:12 +03:00
|
|
|
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
2024-11-26 23:41:49 +03:00
|
|
|
import axios from "axios";
|
2025-10-02 16:21:37 +03:00
|
|
|
import {
|
|
|
|
|
MutableRefObject,
|
|
|
|
|
useCallback,
|
|
|
|
|
useEffect,
|
|
|
|
|
useMemo,
|
|
|
|
|
useRef,
|
|
|
|
|
useState,
|
|
|
|
|
} from "react";
|
2025-10-07 22:43:06 +03:00
|
|
|
import { isDesktop } from "react-device-detect";
|
2025-05-09 16:36:44 +03:00
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
2025-03-28 21:52:12 +03:00
|
|
|
import {
|
2025-05-08 01:31:24 +03:00
|
|
|
LuFolderCheck,
|
2025-03-28 21:52:12 +03:00
|
|
|
LuImagePlus,
|
2025-04-24 02:27:46 +03:00
|
|
|
LuPencil,
|
2025-03-28 21:52:12 +03:00
|
|
|
LuRefreshCw,
|
|
|
|
|
LuScanFace,
|
|
|
|
|
LuTrash2,
|
|
|
|
|
} from "react-icons/lu";
|
2024-11-26 23:41:49 +03:00
|
|
|
import { toast } from "sonner";
|
|
|
|
|
import useSWR from "swr";
|
2025-10-07 22:43:06 +03:00
|
|
|
import {
|
|
|
|
|
ClassificationCard,
|
|
|
|
|
GroupedClassificationCard,
|
|
|
|
|
} from "@/components/card/ClassificationCard";
|
|
|
|
|
import { ClassificationItemData } from "@/types/classification";
|
2024-11-26 23:41:49 +03:00
|
|
|
|
|
|
|
|
export default function FaceLibrary() {
|
2025-03-16 18:36:20 +03:00
|
|
|
const { t } = useTranslation(["views/faceLibrary"]);
|
|
|
|
|
|
2025-01-05 00:21:47 +03:00
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
2025-01-03 01:44:25 +03:00
|
|
|
// title
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-03-16 18:36:20 +03:00
|
|
|
document.title = t("documentTitle");
|
|
|
|
|
}, [t]);
|
2025-01-03 01:44:25 +03:00
|
|
|
|
2025-05-08 01:31:24 +03:00
|
|
|
const [page, setPage] = useState<string>("train");
|
2024-11-26 23:41:49 +03:00
|
|
|
const [pageToggle, setPageToggle] = useOptimisticState(page, setPage, 100);
|
|
|
|
|
|
|
|
|
|
// face data
|
|
|
|
|
|
2025-03-21 20:47:32 +03:00
|
|
|
const { data: faceData, mutate: refreshFaces } =
|
|
|
|
|
useSWR<FaceLibraryData>("faces");
|
2024-11-26 23:41:49 +03:00
|
|
|
|
|
|
|
|
const faces = useMemo<string[]>(
|
2025-01-01 00:56:01 +03:00
|
|
|
() =>
|
2025-07-07 15:35:55 +03:00
|
|
|
faceData
|
|
|
|
|
? Object.keys(faceData)
|
|
|
|
|
.filter((face) => face != "train")
|
|
|
|
|
.sort()
|
|
|
|
|
: [],
|
2024-11-26 23:41:49 +03:00
|
|
|
[faceData],
|
|
|
|
|
);
|
|
|
|
|
const faceImages = useMemo<string[]>(
|
|
|
|
|
() => (pageToggle && faceData ? faceData[pageToggle] : []),
|
|
|
|
|
[pageToggle, faceData],
|
|
|
|
|
);
|
|
|
|
|
|
2025-01-03 01:44:25 +03:00
|
|
|
const trainImages = useMemo<string[]>(
|
|
|
|
|
() => faceData?.["train"] || [],
|
2025-01-01 00:56:01 +03:00
|
|
|
[faceData],
|
|
|
|
|
);
|
|
|
|
|
|
2024-11-26 23:41:49 +03:00
|
|
|
// upload
|
|
|
|
|
|
|
|
|
|
const [upload, setUpload] = useState(false);
|
2025-02-09 22:22:25 +03:00
|
|
|
const [addFace, setAddFace] = useState(false);
|
2024-11-26 23:41:49 +03:00
|
|
|
|
2025-10-02 15:31:09 +03:00
|
|
|
// input focus for keyboard shortcuts
|
2024-11-26 23:41:49 +03:00
|
|
|
const onUploadImage = useCallback(
|
|
|
|
|
(file: File) => {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("file", file);
|
2024-11-27 22:48:39 +03:00
|
|
|
axios
|
2025-02-09 22:22:25 +03:00
|
|
|
.post(`faces/${pageToggle}/register`, formData, {
|
2024-11-27 22:48:39 +03:00
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then((resp) => {
|
|
|
|
|
if (resp.status == 200) {
|
|
|
|
|
setUpload(false);
|
|
|
|
|
refreshFaces();
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.success(t("toast.success.uploadedImage"), {
|
2025-02-10 00:50:12 +03:00
|
|
|
position: "top-center",
|
|
|
|
|
});
|
2024-11-27 22:48:39 +03:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
2025-03-08 19:01:08 +03:00
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.error(t("toast.error.uploadingImageFailed", { errorMessage }), {
|
2025-03-08 19:01:08 +03:00
|
|
|
position: "top-center",
|
|
|
|
|
});
|
2024-11-27 22:48:39 +03:00
|
|
|
});
|
2024-11-26 23:41:49 +03:00
|
|
|
},
|
2025-03-16 18:36:20 +03:00
|
|
|
[pageToggle, refreshFaces, t],
|
2024-11-26 23:41:49 +03:00
|
|
|
);
|
|
|
|
|
|
2025-03-10 18:01:52 +03:00
|
|
|
// face multiselect
|
|
|
|
|
|
|
|
|
|
const [selectedFaces, setSelectedFaces] = useState<string[]>([]);
|
|
|
|
|
|
2025-04-01 00:49:56 +03:00
|
|
|
const onClickFaces = useCallback(
|
|
|
|
|
(images: string[], ctrl: boolean) => {
|
2025-03-17 22:50:13 +03:00
|
|
|
if (selectedFaces.length == 0 && !ctrl) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-01 00:49:56 +03:00
|
|
|
let newSelectedFaces = [...selectedFaces];
|
2025-03-10 18:01:52 +03:00
|
|
|
|
2025-04-01 00:49:56 +03:00
|
|
|
images.forEach((imageId) => {
|
|
|
|
|
const index = newSelectedFaces.indexOf(imageId);
|
|
|
|
|
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
if (selectedFaces.length == 1) {
|
|
|
|
|
newSelectedFaces = [];
|
|
|
|
|
} else {
|
|
|
|
|
const copy = [
|
|
|
|
|
...newSelectedFaces.slice(0, index),
|
|
|
|
|
...newSelectedFaces.slice(index + 1),
|
|
|
|
|
];
|
|
|
|
|
newSelectedFaces = copy;
|
|
|
|
|
}
|
2025-03-10 18:01:52 +03:00
|
|
|
} else {
|
2025-04-01 00:49:56 +03:00
|
|
|
newSelectedFaces.push(imageId);
|
2025-03-10 18:01:52 +03:00
|
|
|
}
|
2025-04-01 00:49:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setSelectedFaces(newSelectedFaces);
|
2025-03-10 18:01:52 +03:00
|
|
|
},
|
|
|
|
|
[selectedFaces, setSelectedFaces],
|
|
|
|
|
);
|
|
|
|
|
|
2025-05-09 16:36:44 +03:00
|
|
|
const [deleteDialogOpen, setDeleteDialogOpen] = useState<{
|
|
|
|
|
name: string;
|
|
|
|
|
ids: string[];
|
|
|
|
|
} | null>(null);
|
|
|
|
|
|
2025-03-17 22:50:13 +03:00
|
|
|
const onDelete = useCallback(
|
2025-04-03 17:17:29 +03:00
|
|
|
(name: string, ids: string[], isName: boolean = false) => {
|
2025-03-17 22:50:13 +03:00
|
|
|
axios
|
|
|
|
|
.post(`/faces/${name}/delete`, { ids })
|
|
|
|
|
.then((resp) => {
|
|
|
|
|
setSelectedFaces([]);
|
2025-03-10 18:01:52 +03:00
|
|
|
|
2025-03-17 22:50:13 +03:00
|
|
|
if (resp.status == 200) {
|
2025-04-03 17:17:29 +03:00
|
|
|
if (isName) {
|
|
|
|
|
toast.success(
|
|
|
|
|
t("toast.success.deletedName", { count: ids.length }),
|
|
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
toast.success(
|
|
|
|
|
t("toast.success.deletedFace", { count: ids.length }),
|
|
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-03-17 22:50:13 +03:00
|
|
|
|
|
|
|
|
if (faceImages.length == 1) {
|
|
|
|
|
// face has been deleted
|
2025-05-09 16:36:44 +03:00
|
|
|
setPageToggle("train");
|
2025-03-17 22:50:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refreshFaces();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
2025-04-03 17:17:29 +03:00
|
|
|
if (isName) {
|
|
|
|
|
toast.error(t("toast.error.deleteNameFailed", { errorMessage }), {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
toast.error(t("toast.error.deleteFaceFailed", { errorMessage }), {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-03-10 18:01:52 +03:00
|
|
|
});
|
2025-03-17 22:50:13 +03:00
|
|
|
},
|
|
|
|
|
[faceImages, refreshFaces, setPageToggle, t],
|
|
|
|
|
);
|
2025-03-10 18:01:52 +03:00
|
|
|
|
2025-04-24 02:27:46 +03:00
|
|
|
const onRename = useCallback(
|
|
|
|
|
(oldName: string, newName: string) => {
|
|
|
|
|
axios
|
|
|
|
|
.put(`/faces/${oldName}/rename`, { new_name: newName })
|
|
|
|
|
.then((resp) => {
|
|
|
|
|
if (resp.status === 200) {
|
|
|
|
|
toast.success(t("toast.success.renamedFace", { name: newName }), {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
setPageToggle("train");
|
|
|
|
|
refreshFaces();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
|
|
|
|
toast.error(t("toast.error.renameFaceFailed", { errorMessage }), {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[setPageToggle, refreshFaces, t],
|
|
|
|
|
);
|
|
|
|
|
|
2025-03-10 18:01:52 +03:00
|
|
|
// keyboard
|
|
|
|
|
|
2025-10-02 16:21:37 +03:00
|
|
|
const contentRef = useRef<HTMLDivElement | null>(null);
|
2025-10-02 15:31:09 +03:00
|
|
|
useKeyboardListener(
|
|
|
|
|
["a", "Escape"],
|
|
|
|
|
(key, modifiers) => {
|
2025-10-02 16:21:37 +03:00
|
|
|
if (!modifiers.down) {
|
|
|
|
|
return true;
|
2025-10-02 15:31:09 +03:00
|
|
|
}
|
2025-03-10 18:01:52 +03:00
|
|
|
|
2025-10-02 15:31:09 +03:00
|
|
|
switch (key) {
|
|
|
|
|
case "a":
|
2025-10-02 16:21:37 +03:00
|
|
|
if (modifiers.ctrl && !modifiers.repeat) {
|
2025-10-02 15:31:09 +03:00
|
|
|
if (selectedFaces.length) {
|
|
|
|
|
setSelectedFaces([]);
|
|
|
|
|
} else {
|
|
|
|
|
setSelectedFaces([
|
|
|
|
|
...(pageToggle === "train" ? trainImages : faceImages),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2025-10-02 16:21:37 +03:00
|
|
|
|
|
|
|
|
return true;
|
2025-04-01 00:49:56 +03:00
|
|
|
}
|
2025-10-02 15:31:09 +03:00
|
|
|
break;
|
|
|
|
|
case "Escape":
|
|
|
|
|
setSelectedFaces([]);
|
2025-10-02 16:21:37 +03:00
|
|
|
return true;
|
2025-10-02 15:31:09 +03:00
|
|
|
}
|
2025-10-02 16:21:37 +03:00
|
|
|
|
|
|
|
|
return false;
|
2025-10-02 15:31:09 +03:00
|
|
|
},
|
2025-10-02 16:21:37 +03:00
|
|
|
contentRef,
|
2025-10-02 15:31:09 +03:00
|
|
|
);
|
2025-05-09 16:36:44 +03:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setSelectedFaces([]);
|
|
|
|
|
}, [pageToggle]);
|
2025-03-10 18:01:52 +03:00
|
|
|
|
2025-01-05 00:21:47 +03:00
|
|
|
if (!config) {
|
|
|
|
|
return <ActivityIndicator />;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 23:41:49 +03:00
|
|
|
return (
|
|
|
|
|
<div className="flex size-full flex-col p-2">
|
|
|
|
|
<Toaster />
|
|
|
|
|
|
2025-05-09 16:36:44 +03:00
|
|
|
<AlertDialog
|
|
|
|
|
open={!!deleteDialogOpen}
|
|
|
|
|
onOpenChange={() => setDeleteDialogOpen(null)}
|
|
|
|
|
>
|
|
|
|
|
<AlertDialogContent>
|
|
|
|
|
<AlertDialogHeader>
|
|
|
|
|
<AlertDialogTitle>{t("deleteFaceAttempts.title")}</AlertDialogTitle>
|
|
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogDescription>
|
|
|
|
|
<Trans
|
|
|
|
|
ns="views/faceLibrary"
|
|
|
|
|
values={{ count: deleteDialogOpen?.ids.length }}
|
|
|
|
|
>
|
|
|
|
|
deleteFaceAttempts.desc
|
|
|
|
|
</Trans>
|
|
|
|
|
</AlertDialogDescription>
|
|
|
|
|
<AlertDialogFooter>
|
|
|
|
|
<AlertDialogCancel>
|
|
|
|
|
{t("button.cancel", { ns: "common" })}
|
|
|
|
|
</AlertDialogCancel>
|
|
|
|
|
<AlertDialogAction
|
|
|
|
|
className={buttonVariants({ variant: "destructive" })}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (deleteDialogOpen) {
|
|
|
|
|
onDelete(deleteDialogOpen.name, deleteDialogOpen.ids);
|
|
|
|
|
setDeleteDialogOpen(null);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t("button.delete", { ns: "common" })}
|
|
|
|
|
</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
|
2024-11-26 23:41:49 +03:00
|
|
|
<UploadImageDialog
|
|
|
|
|
open={upload}
|
2025-03-16 18:36:20 +03:00
|
|
|
title={t("uploadFaceImage.title")}
|
|
|
|
|
description={t("uploadFaceImage.desc", { pageToggle })}
|
2024-11-26 23:41:49 +03:00
|
|
|
setOpen={setUpload}
|
|
|
|
|
onSave={onUploadImage}
|
|
|
|
|
/>
|
|
|
|
|
|
2025-03-17 22:50:13 +03:00
|
|
|
<CreateFaceWizardDialog
|
2025-02-09 22:22:25 +03:00
|
|
|
open={addFace}
|
|
|
|
|
setOpen={setAddFace}
|
2025-03-17 22:50:13 +03:00
|
|
|
onFinish={refreshFaces}
|
2025-02-09 22:22:25 +03:00
|
|
|
/>
|
|
|
|
|
|
2025-01-05 00:21:47 +03:00
|
|
|
<div className="relative mb-2 flex h-11 w-full items-center justify-between">
|
2025-03-21 20:47:32 +03:00
|
|
|
<LibrarySelector
|
|
|
|
|
pageToggle={pageToggle}
|
|
|
|
|
faceData={faceData}
|
|
|
|
|
faces={faces}
|
|
|
|
|
trainImages={trainImages}
|
|
|
|
|
setPageToggle={setPageToggle}
|
2025-04-03 17:17:29 +03:00
|
|
|
onDelete={onDelete}
|
2025-04-24 02:27:46 +03:00
|
|
|
onRename={onRename}
|
2025-03-21 20:47:32 +03:00
|
|
|
/>
|
2025-03-10 18:01:52 +03:00
|
|
|
{selectedFaces?.length > 0 ? (
|
|
|
|
|
<div className="flex items-center justify-center gap-2">
|
2025-04-01 00:49:56 +03:00
|
|
|
<div className="mx-1 flex w-48 items-center justify-center text-sm text-muted-foreground">
|
|
|
|
|
<div className="p-1">{`${selectedFaces.length} selected`}</div>
|
|
|
|
|
<div className="p-1">{"|"}</div>
|
|
|
|
|
<div
|
|
|
|
|
className="cursor-pointer p-2 text-primary hover:rounded-lg hover:bg-secondary"
|
|
|
|
|
onClick={() => setSelectedFaces([])}
|
|
|
|
|
>
|
|
|
|
|
{t("button.unselect", { ns: "common" })}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-03-17 22:50:13 +03:00
|
|
|
<Button
|
|
|
|
|
className="flex gap-2"
|
2025-05-09 16:36:44 +03:00
|
|
|
onClick={() =>
|
|
|
|
|
setDeleteDialogOpen({ name: pageToggle, ids: selectedFaces })
|
|
|
|
|
}
|
2025-03-17 22:50:13 +03:00
|
|
|
>
|
2025-03-10 18:01:52 +03:00
|
|
|
<LuTrash2 className="size-7 rounded-md p-1 text-secondary-foreground" />
|
2025-03-17 22:50:13 +03:00
|
|
|
{isDesktop && t("button.deleteFaceAttempts")}
|
2025-03-10 18:01:52 +03:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex items-center justify-center gap-2">
|
|
|
|
|
<Button className="flex gap-2" onClick={() => setAddFace(true)}>
|
|
|
|
|
<LuScanFace className="size-7 rounded-md p-1 text-secondary-foreground" />
|
2025-03-17 22:50:13 +03:00
|
|
|
{isDesktop && t("button.addFace")}
|
2025-03-10 18:01:52 +03:00
|
|
|
</Button>
|
|
|
|
|
{pageToggle != "train" && (
|
|
|
|
|
<Button className="flex gap-2" onClick={() => setUpload(true)}>
|
|
|
|
|
<LuImagePlus className="size-7 rounded-md p-1 text-secondary-foreground" />
|
2025-03-17 22:50:13 +03:00
|
|
|
{isDesktop && t("button.uploadImage")}
|
2025-03-10 18:01:52 +03:00
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-11-26 23:41:49 +03:00
|
|
|
</div>
|
2025-05-11 21:03:53 +03:00
|
|
|
{pageToggle && faceImages?.length === 0 && pageToggle !== "train" ? (
|
2025-05-09 16:36:44 +03:00
|
|
|
<div className="absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center text-center">
|
|
|
|
|
<LuFolderCheck className="size-16" />
|
2025-05-11 21:03:53 +03:00
|
|
|
{t("nofaces")}
|
2025-05-09 16:36:44 +03:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
pageToggle &&
|
2025-01-03 01:44:25 +03:00
|
|
|
(pageToggle == "train" ? (
|
|
|
|
|
<TrainingGrid
|
2025-01-05 00:21:47 +03:00
|
|
|
config={config}
|
2025-10-02 16:21:37 +03:00
|
|
|
contentRef={contentRef}
|
2025-01-03 01:44:25 +03:00
|
|
|
attemptImages={trainImages}
|
|
|
|
|
faceNames={faces}
|
2025-03-10 18:01:52 +03:00
|
|
|
selectedFaces={selectedFaces}
|
2025-04-01 00:49:56 +03:00
|
|
|
onClickFaces={onClickFaces}
|
2025-01-03 01:44:25 +03:00
|
|
|
onRefresh={refreshFaces}
|
|
|
|
|
/>
|
2025-01-01 00:56:01 +03:00
|
|
|
) : (
|
|
|
|
|
<FaceGrid
|
2025-10-02 16:21:37 +03:00
|
|
|
contentRef={contentRef}
|
2025-01-01 00:56:01 +03:00
|
|
|
faceImages={faceImages}
|
|
|
|
|
pageToggle={pageToggle}
|
2025-05-09 16:36:44 +03:00
|
|
|
selectedFaces={selectedFaces}
|
|
|
|
|
onClickFaces={onClickFaces}
|
2025-03-17 22:50:13 +03:00
|
|
|
onDelete={onDelete}
|
2025-01-01 00:56:01 +03:00
|
|
|
/>
|
2025-05-09 16:36:44 +03:00
|
|
|
))
|
|
|
|
|
)}
|
2025-01-01 00:56:01 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-21 20:47:32 +03:00
|
|
|
type LibrarySelectorProps = {
|
|
|
|
|
pageToggle: string | undefined;
|
|
|
|
|
faceData?: FaceLibraryData;
|
|
|
|
|
faces: string[];
|
|
|
|
|
trainImages: string[];
|
2025-05-08 01:31:24 +03:00
|
|
|
setPageToggle: (toggle: string) => void;
|
2025-04-03 17:17:29 +03:00
|
|
|
onDelete: (name: string, ids: string[], isName: boolean) => void;
|
2025-04-24 02:27:46 +03:00
|
|
|
onRename: (old_name: string, new_name: string) => void;
|
2025-03-21 20:47:32 +03:00
|
|
|
};
|
|
|
|
|
function LibrarySelector({
|
|
|
|
|
pageToggle,
|
|
|
|
|
faceData,
|
|
|
|
|
faces,
|
|
|
|
|
trainImages,
|
|
|
|
|
setPageToggle,
|
2025-04-03 17:17:29 +03:00
|
|
|
onDelete,
|
2025-04-24 02:27:46 +03:00
|
|
|
onRename,
|
2025-03-21 20:47:32 +03:00
|
|
|
}: LibrarySelectorProps) {
|
|
|
|
|
const { t } = useTranslation(["views/faceLibrary"]);
|
2025-04-03 17:17:29 +03:00
|
|
|
const [confirmDelete, setConfirmDelete] = useState<string | null>(null);
|
2025-04-24 02:27:46 +03:00
|
|
|
const [renameFace, setRenameFace] = useState<string | null>(null);
|
2025-03-21 20:47:32 +03:00
|
|
|
|
2025-04-03 17:17:29 +03:00
|
|
|
const handleDeleteFace = useCallback(
|
|
|
|
|
(faceName: string) => {
|
|
|
|
|
// Get all image IDs for this face
|
|
|
|
|
const imageIds = faceData?.[faceName] || [];
|
|
|
|
|
|
|
|
|
|
onDelete(faceName, imageIds, true);
|
|
|
|
|
setPageToggle("train");
|
|
|
|
|
},
|
|
|
|
|
[faceData, onDelete, setPageToggle],
|
|
|
|
|
);
|
|
|
|
|
|
2025-04-24 02:27:46 +03:00
|
|
|
const handleSetOpen = useCallback(
|
|
|
|
|
(open: boolean) => {
|
|
|
|
|
setRenameFace(open ? renameFace : null);
|
|
|
|
|
},
|
|
|
|
|
[renameFace],
|
|
|
|
|
);
|
|
|
|
|
|
2025-04-03 17:17:29 +03:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Dialog
|
|
|
|
|
open={!!confirmDelete}
|
|
|
|
|
onOpenChange={(open) => !open && setConfirmDelete(null)}
|
|
|
|
|
>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
<DialogHeader>
|
|
|
|
|
<DialogTitle>{t("deleteFaceLibrary.title")}</DialogTitle>
|
|
|
|
|
<DialogDescription>
|
|
|
|
|
{t("deleteFaceLibrary.desc", { name: confirmDelete })}
|
|
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
<div className="flex justify-end gap-2">
|
|
|
|
|
<Button variant="outline" onClick={() => setConfirmDelete(null)}>
|
|
|
|
|
{t("button.cancel", { ns: "common" })}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="destructive"
|
2025-07-07 17:03:57 +03:00
|
|
|
className="text-white"
|
2025-04-03 17:17:29 +03:00
|
|
|
onClick={() => {
|
|
|
|
|
if (confirmDelete) {
|
|
|
|
|
handleDeleteFace(confirmDelete);
|
|
|
|
|
setConfirmDelete(null);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{t("button.delete", { ns: "common" })}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
|
2025-04-24 02:27:46 +03:00
|
|
|
<TextEntryDialog
|
|
|
|
|
open={!!renameFace}
|
|
|
|
|
setOpen={handleSetOpen}
|
|
|
|
|
title={t("renameFace.title")}
|
|
|
|
|
description={t("renameFace.desc", { name: renameFace })}
|
|
|
|
|
onSave={(newName) => {
|
|
|
|
|
onRename(renameFace!, newName);
|
|
|
|
|
setRenameFace(null);
|
|
|
|
|
}}
|
|
|
|
|
defaultValue={renameFace || ""}
|
2025-05-18 01:11:19 +03:00
|
|
|
regexPattern={/^[\p{L}\p{N}\s'_-]{1,50}$/u}
|
|
|
|
|
regexErrorMessage={t("description.invalidName")}
|
2025-04-24 02:27:46 +03:00
|
|
|
/>
|
|
|
|
|
|
2025-04-03 17:17:29 +03:00
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
2025-04-23 01:21:09 +03:00
|
|
|
<Button className="flex justify-between smart-capitalize">
|
2025-05-09 16:36:44 +03:00
|
|
|
{pageToggle == "train" ? t("train.title") : pageToggle}
|
2025-04-03 17:17:29 +03:00
|
|
|
<span className="ml-2 text-primary-variant">
|
|
|
|
|
({(pageToggle && faceData?.[pageToggle]?.length) || 0})
|
|
|
|
|
</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent
|
|
|
|
|
className="scrollbar-container max-h-[40dvh] min-w-[220px] overflow-y-auto"
|
|
|
|
|
align="start"
|
2025-03-21 20:47:32 +03:00
|
|
|
>
|
2025-05-08 01:31:24 +03:00
|
|
|
<DropdownMenuItem
|
|
|
|
|
className="flex cursor-pointer items-center justify-start gap-2"
|
|
|
|
|
aria-label={t("train.aria")}
|
|
|
|
|
onClick={() => setPageToggle("train")}
|
|
|
|
|
>
|
|
|
|
|
<div>{t("train.title")}</div>
|
|
|
|
|
<div className="text-secondary-foreground">
|
|
|
|
|
({trainImages.length})
|
|
|
|
|
</div>
|
|
|
|
|
</DropdownMenuItem>
|
2025-04-03 17:17:29 +03:00
|
|
|
{trainImages.length > 0 && faces.length > 0 && (
|
2025-03-21 20:47:32 +03:00
|
|
|
<>
|
2025-04-03 17:17:29 +03:00
|
|
|
<DropdownMenuSeparator />
|
|
|
|
|
<div className="mb-1 ml-1.5 text-xs text-secondary-foreground">
|
2025-05-09 16:36:44 +03:00
|
|
|
{t("collections")}
|
2025-04-03 17:17:29 +03:00
|
|
|
</div>
|
2025-03-21 20:47:32 +03:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{Object.values(faces).map((face) => (
|
2025-04-03 17:17:29 +03:00
|
|
|
<DropdownMenuItem
|
2025-03-21 20:47:32 +03:00
|
|
|
key={face}
|
2025-04-03 17:17:29 +03:00
|
|
|
className="group flex items-center justify-between"
|
2025-03-21 20:47:32 +03:00
|
|
|
>
|
2025-04-03 17:17:29 +03:00
|
|
|
<div
|
2025-05-18 01:11:19 +03:00
|
|
|
className="flex-grow cursor-pointer"
|
2025-04-03 17:17:29 +03:00
|
|
|
onClick={() => setPageToggle(face)}
|
|
|
|
|
>
|
|
|
|
|
{face}
|
|
|
|
|
<span className="ml-2 text-muted-foreground">
|
|
|
|
|
({faceData?.[face].length})
|
|
|
|
|
</span>
|
2025-03-21 20:47:32 +03:00
|
|
|
</div>
|
2025-04-24 02:27:46 +03:00
|
|
|
<div className="flex gap-0.5">
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
2025-05-02 15:44:45 +03:00
|
|
|
className="size-7 lg:opacity-0 lg:transition-opacity lg:group-hover:opacity-100"
|
2025-04-24 02:27:46 +03:00
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
setRenameFace(face);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<LuPencil className="size-4 text-primary" />
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipPortal>
|
|
|
|
|
<TooltipContent>{t("button.renameFace")}</TooltipContent>
|
|
|
|
|
</TooltipPortal>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
2025-05-02 15:44:45 +03:00
|
|
|
className="size-7 lg:opacity-0 lg:transition-opacity lg:group-hover:opacity-100"
|
2025-04-24 02:27:46 +03:00
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
setConfirmDelete(face);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<LuTrash2 className="size-4 text-destructive" />
|
|
|
|
|
</Button>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipPortal>
|
|
|
|
|
<TooltipContent>{t("button.deleteFace")}</TooltipContent>
|
|
|
|
|
</TooltipPortal>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
2025-04-03 17:17:29 +03:00
|
|
|
</DropdownMenuItem>
|
2025-03-21 20:47:32 +03:00
|
|
|
))}
|
2025-04-03 17:17:29 +03:00
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
</>
|
2025-03-21 20:47:32 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-03 01:44:25 +03:00
|
|
|
type TrainingGridProps = {
|
2025-01-05 00:21:47 +03:00
|
|
|
config: FrigateConfig;
|
2025-10-02 16:21:37 +03:00
|
|
|
contentRef: MutableRefObject<HTMLDivElement | null>;
|
2025-01-01 00:56:01 +03:00
|
|
|
attemptImages: string[];
|
2025-01-03 01:44:25 +03:00
|
|
|
faceNames: string[];
|
2025-03-10 18:01:52 +03:00
|
|
|
selectedFaces: string[];
|
2025-04-01 00:49:56 +03:00
|
|
|
onClickFaces: (images: string[], ctrl: boolean) => void;
|
2025-01-01 00:56:01 +03:00
|
|
|
onRefresh: () => void;
|
|
|
|
|
};
|
2025-01-03 01:44:25 +03:00
|
|
|
function TrainingGrid({
|
2025-01-05 00:21:47 +03:00
|
|
|
config,
|
2025-10-02 16:21:37 +03:00
|
|
|
contentRef,
|
2025-01-03 01:44:25 +03:00
|
|
|
attemptImages,
|
|
|
|
|
faceNames,
|
2025-03-10 18:01:52 +03:00
|
|
|
selectedFaces,
|
2025-04-01 00:49:56 +03:00
|
|
|
onClickFaces,
|
2025-01-03 01:44:25 +03:00
|
|
|
onRefresh,
|
|
|
|
|
}: TrainingGridProps) {
|
2025-04-01 00:49:56 +03:00
|
|
|
const { t } = useTranslation(["views/faceLibrary"]);
|
2025-03-18 17:32:15 +03:00
|
|
|
|
|
|
|
|
// face data
|
|
|
|
|
|
2025-03-28 21:52:12 +03:00
|
|
|
const faceGroups = useMemo(() => {
|
2025-10-07 22:43:06 +03:00
|
|
|
const groups: { [eventId: string]: ClassificationItemData[] } = {};
|
2025-03-28 21:52:12 +03:00
|
|
|
|
2025-04-01 00:49:56 +03:00
|
|
|
const faces = attemptImages
|
|
|
|
|
.map((image) => {
|
2025-03-28 21:52:12 +03:00
|
|
|
const parts = image.split("-");
|
2025-04-01 00:49:56 +03:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return {
|
|
|
|
|
filename: image,
|
2025-10-07 22:43:06 +03:00
|
|
|
filepath: `clips/faces/train/${image}`,
|
2025-04-01 00:49:56 +03:00
|
|
|
timestamp: Number.parseFloat(parts[2]),
|
|
|
|
|
eventId: `${parts[0]}-${parts[1]}`,
|
|
|
|
|
name: parts[3],
|
|
|
|
|
score: Number.parseFloat(parts[4]),
|
|
|
|
|
};
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.filter((v) => v != null);
|
|
|
|
|
|
|
|
|
|
faces
|
|
|
|
|
.sort((a, b) => a.eventId.localeCompare(b.eventId))
|
|
|
|
|
.reverse()
|
|
|
|
|
.forEach((face) => {
|
|
|
|
|
if (groups[face.eventId]) {
|
|
|
|
|
groups[face.eventId].push(face);
|
2025-03-28 21:52:12 +03:00
|
|
|
} else {
|
2025-04-01 00:49:56 +03:00
|
|
|
groups[face.eventId] = [face];
|
2025-03-28 21:52:12 +03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return groups;
|
|
|
|
|
}, [attemptImages]);
|
|
|
|
|
|
|
|
|
|
const eventIdsQuery = useMemo(
|
|
|
|
|
() => Object.keys(faceGroups).join(","),
|
|
|
|
|
[faceGroups],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { data: events } = useSWR<Event[]>([
|
|
|
|
|
"event_ids",
|
|
|
|
|
{ ids: eventIdsQuery },
|
|
|
|
|
]);
|
|
|
|
|
|
2025-05-08 01:31:24 +03:00
|
|
|
if (attemptImages.length == 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center text-center">
|
|
|
|
|
<LuFolderCheck className="size-16" />
|
|
|
|
|
{t("train.empty")}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-01 00:56:01 +03:00
|
|
|
return (
|
2025-10-22 16:36:09 +03:00
|
|
|
<div
|
|
|
|
|
ref={contentRef}
|
|
|
|
|
className={cn(
|
|
|
|
|
"scrollbar-container grid grid-cols-2 gap-3 overflow-y-scroll p-1 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8 2xl:grid-cols-10 3xl:grid-cols-12",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{Object.entries(faceGroups).map(([key, group]) => {
|
|
|
|
|
const event = events?.find((ev) => ev.id == key);
|
|
|
|
|
return (
|
|
|
|
|
<div key={key} className="aspect-square w-full">
|
2025-04-01 00:49:56 +03:00
|
|
|
<FaceAttemptGroup
|
|
|
|
|
config={config}
|
|
|
|
|
group={group}
|
|
|
|
|
event={event}
|
|
|
|
|
faceNames={faceNames}
|
|
|
|
|
selectedFaces={selectedFaces}
|
|
|
|
|
onClickFaces={onClickFaces}
|
|
|
|
|
onRefresh={onRefresh}
|
|
|
|
|
/>
|
2025-10-22 16:36:09 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2025-04-01 00:49:56 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FaceAttemptGroupProps = {
|
|
|
|
|
config: FrigateConfig;
|
2025-10-07 22:43:06 +03:00
|
|
|
group: ClassificationItemData[];
|
2025-04-01 00:49:56 +03:00
|
|
|
event?: Event;
|
|
|
|
|
faceNames: string[];
|
|
|
|
|
selectedFaces: string[];
|
|
|
|
|
onClickFaces: (image: string[], ctrl: boolean) => void;
|
|
|
|
|
onRefresh: () => void;
|
|
|
|
|
};
|
|
|
|
|
function FaceAttemptGroup({
|
|
|
|
|
config,
|
|
|
|
|
group,
|
|
|
|
|
event,
|
|
|
|
|
faceNames,
|
|
|
|
|
selectedFaces,
|
|
|
|
|
onClickFaces,
|
|
|
|
|
onRefresh,
|
|
|
|
|
}: FaceAttemptGroupProps) {
|
|
|
|
|
const { t } = useTranslation(["views/faceLibrary", "views/explore"]);
|
|
|
|
|
|
|
|
|
|
// data
|
|
|
|
|
|
2025-10-07 22:43:06 +03:00
|
|
|
const threshold = useMemo(() => {
|
|
|
|
|
return {
|
|
|
|
|
recognition: config.face_recognition.recognition_threshold,
|
|
|
|
|
unknown: config.face_recognition.unknown_score,
|
|
|
|
|
};
|
|
|
|
|
}, [config]);
|
2025-04-01 00:49:56 +03:00
|
|
|
|
|
|
|
|
// interaction
|
|
|
|
|
|
|
|
|
|
const handleClickEvent = useCallback(
|
|
|
|
|
(meta: boolean) => {
|
2025-10-22 16:36:09 +03:00
|
|
|
if (!meta) {
|
|
|
|
|
return;
|
2025-04-01 00:49:56 +03:00
|
|
|
} else {
|
|
|
|
|
const anySelected =
|
|
|
|
|
group.find((face) => selectedFaces.includes(face.filename)) !=
|
|
|
|
|
undefined;
|
|
|
|
|
|
|
|
|
|
if (anySelected) {
|
|
|
|
|
// deselect all
|
|
|
|
|
const toDeselect: string[] = [];
|
|
|
|
|
group.forEach((face) => {
|
|
|
|
|
if (selectedFaces.includes(face.filename)) {
|
|
|
|
|
toDeselect.push(face.filename);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
onClickFaces(toDeselect, false);
|
|
|
|
|
} else {
|
|
|
|
|
// select all
|
|
|
|
|
onClickFaces(
|
|
|
|
|
group.map((face) => face.filename),
|
|
|
|
|
true,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-10-22 16:36:09 +03:00
|
|
|
[group, selectedFaces, onClickFaces],
|
2025-04-01 00:49:56 +03:00
|
|
|
);
|
2025-03-28 21:52:12 +03:00
|
|
|
|
2025-03-18 17:32:15 +03:00
|
|
|
// api calls
|
|
|
|
|
|
2025-01-03 01:44:25 +03:00
|
|
|
const onTrainAttempt = useCallback(
|
2025-10-07 22:43:06 +03:00
|
|
|
(data: ClassificationItemData, trainName: string) => {
|
2025-01-03 01:44:25 +03:00
|
|
|
axios
|
2025-03-28 21:52:12 +03:00
|
|
|
.post(`/faces/train/${trainName}/classify`, {
|
|
|
|
|
training_file: data.filename,
|
|
|
|
|
})
|
2025-01-03 01:44:25 +03:00
|
|
|
.then((resp) => {
|
|
|
|
|
if (resp.status == 200) {
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.success(t("toast.success.trainedFace"), {
|
2025-01-03 01:44:25 +03:00
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
onRefresh();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
2025-03-08 19:01:08 +03:00
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
2025-03-16 18:36:20 +03:00
|
|
|
toast.error(t("toast.error.trainFailed", { errorMessage }), {
|
2025-03-08 19:01:08 +03:00
|
|
|
position: "top-center",
|
|
|
|
|
});
|
2025-01-03 01:44:25 +03:00
|
|
|
});
|
|
|
|
|
},
|
2025-10-07 22:43:06 +03:00
|
|
|
[onRefresh, t],
|
2025-01-03 01:44:25 +03:00
|
|
|
);
|
|
|
|
|
|
2025-10-07 22:43:06 +03:00
|
|
|
const onReprocess = useCallback(
|
|
|
|
|
(data: ClassificationItemData) => {
|
|
|
|
|
axios
|
|
|
|
|
.post(`/faces/reprocess`, { training_file: data.filename })
|
|
|
|
|
.then((resp) => {
|
|
|
|
|
if (resp.status == 200) {
|
|
|
|
|
toast.success(t("toast.success.updatedFaceScore"), {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
});
|
|
|
|
|
onRefresh();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
const errorMessage =
|
|
|
|
|
error.response?.data?.message ||
|
|
|
|
|
error.response?.data?.detail ||
|
|
|
|
|
"Unknown error";
|
|
|
|
|
toast.error(
|
|
|
|
|
t("toast.error.updateFaceScoreFailed", { errorMessage }),
|
|
|
|
|
{
|
|
|
|
|
position: "top-center",
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-03-08 19:01:08 +03:00
|
|
|
});
|
2025-10-07 22:43:06 +03:00
|
|
|
},
|
|
|
|
|
[onRefresh, t],
|
|
|
|
|
);
|
2025-01-29 17:41:35 +03:00
|
|
|
|
2025-01-01 00:56:01 +03:00
|
|
|
return (
|
2025-10-07 22:43:06 +03:00
|
|
|
<GroupedClassificationCard
|
|
|
|
|
group={group}
|
|
|
|
|
event={event}
|
|
|
|
|
threshold={threshold}
|
|
|
|
|
selectedItems={selectedFaces}
|
|
|
|
|
i18nLibrary="views/faceLibrary"
|
|
|
|
|
objectType="person"
|
|
|
|
|
onClick={(data) => {
|
|
|
|
|
if (data) {
|
|
|
|
|
onClickFaces([data.filename], true);
|
|
|
|
|
} else {
|
|
|
|
|
handleClickEvent(true);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{(data) => (
|
|
|
|
|
<>
|
|
|
|
|
<FaceSelectionDialog
|
|
|
|
|
faceNames={faceNames}
|
|
|
|
|
onTrainAttempt={(name) => onTrainAttempt(data, name)}
|
|
|
|
|
>
|
2025-10-24 20:08:59 +03:00
|
|
|
<div className="group relative inline-flex items-center justify-center">
|
|
|
|
|
<div className="pointer-events-none absolute inset-0 m-auto size-5 scale-95 rounded-full bg-black opacity-0 blur-sm transition-all duration-200 group-hover:scale-100 group-hover:opacity-100 group-hover:blur-xl" />
|
|
|
|
|
<AddFaceIcon className="relative z-10 size-5 cursor-pointer text-white/85 hover:text-white" />
|
|
|
|
|
</div>
|
2025-10-07 22:43:06 +03:00
|
|
|
</FaceSelectionDialog>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger>
|
2025-10-24 20:08:59 +03:00
|
|
|
<div className="group relative inline-flex items-center justify-center">
|
|
|
|
|
<div className="pointer-events-none absolute inset-0 m-auto size-5 scale-95 rounded-full bg-black opacity-0 blur-sm transition-all duration-200 group-hover:scale-100 group-hover:opacity-100 group-hover:blur-xl" />
|
|
|
|
|
<LuRefreshCw
|
|
|
|
|
className="relative z-10 size-5 cursor-pointer text-white/85 hover:text-white"
|
|
|
|
|
onClick={() => onReprocess(data)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2025-10-07 22:43:06 +03:00
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>{t("button.reprocessFace")}</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</GroupedClassificationCard>
|
2025-01-01 00:56:01 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FaceGridProps = {
|
2025-10-02 16:21:37 +03:00
|
|
|
contentRef: MutableRefObject<HTMLDivElement | null>;
|
2025-01-01 00:56:01 +03:00
|
|
|
faceImages: string[];
|
|
|
|
|
pageToggle: string;
|
2025-05-09 16:36:44 +03:00
|
|
|
selectedFaces: string[];
|
|
|
|
|
onClickFaces: (images: string[], ctrl: boolean) => void;
|
2025-03-17 22:50:13 +03:00
|
|
|
onDelete: (name: string, ids: string[]) => void;
|
2025-01-01 00:56:01 +03:00
|
|
|
};
|
2025-05-09 16:36:44 +03:00
|
|
|
function FaceGrid({
|
2025-10-02 16:21:37 +03:00
|
|
|
contentRef,
|
2025-05-09 16:36:44 +03:00
|
|
|
faceImages,
|
|
|
|
|
pageToggle,
|
|
|
|
|
selectedFaces,
|
|
|
|
|
onClickFaces,
|
|
|
|
|
onDelete,
|
|
|
|
|
}: FaceGridProps) {
|
2025-10-02 15:31:09 +03:00
|
|
|
const { t } = useTranslation(["views/faceLibrary"]);
|
|
|
|
|
|
2025-05-09 16:36:44 +03:00
|
|
|
const sortedFaces = useMemo(
|
|
|
|
|
() => (faceImages || []).sort().reverse(),
|
|
|
|
|
[faceImages],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (sortedFaces.length === 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center text-center">
|
|
|
|
|
<LuFolderCheck className="size-16" />
|
2025-10-02 15:31:09 +03:00
|
|
|
{t("nofaces")}
|
2025-05-09 16:36:44 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-03-28 21:52:12 +03:00
|
|
|
|
2025-01-01 00:56:01 +03:00
|
|
|
return (
|
2025-03-21 20:47:32 +03:00
|
|
|
<div
|
2025-10-02 16:21:37 +03:00
|
|
|
ref={contentRef}
|
2025-03-21 20:47:32 +03:00
|
|
|
className={cn(
|
2025-10-22 16:36:09 +03:00
|
|
|
"scrollbar-container grid grid-cols-2 gap-2 overflow-y-scroll p-1 md:grid-cols-4 xl:grid-cols-8 2xl:grid-cols-10 3xl:grid-cols-12",
|
2025-03-21 20:47:32 +03:00
|
|
|
)}
|
|
|
|
|
>
|
2025-03-28 21:52:12 +03:00
|
|
|
{sortedFaces.map((image: string) => (
|
2025-10-22 16:36:09 +03:00
|
|
|
<div key={image} className="aspect-square w-full">
|
|
|
|
|
<ClassificationCard
|
|
|
|
|
data={{
|
|
|
|
|
name: pageToggle,
|
|
|
|
|
filename: image,
|
|
|
|
|
filepath: `clips/faces/${pageToggle}/${image}`,
|
|
|
|
|
}}
|
|
|
|
|
selected={selectedFaces.includes(image)}
|
|
|
|
|
i18nLibrary="views/faceLibrary"
|
|
|
|
|
onClick={(data, meta) => onClickFaces([data.filename], meta)}
|
|
|
|
|
>
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger>
|
|
|
|
|
<LuTrash2
|
|
|
|
|
className="size-5 cursor-pointer text-gray-200 hover:text-danger"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onDelete(pageToggle, [image]);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>{t("button.deleteFaceAttempts")}</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</ClassificationCard>
|
|
|
|
|
</div>
|
2025-01-01 00:56:01 +03:00
|
|
|
))}
|
2024-11-26 23:41:49 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|