wip scaffold

This commit is contained in:
Manav Rathi
2024-07-19 10:13:43 +05:30
parent 941b02f750
commit 67e41f4bcd
5 changed files with 12 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
import type { EnteFile } from "../types/file";
import ExifReader from "exifreader";
/**
* Index Exif in the given file.
@@ -23,8 +24,10 @@ import type { EnteFile } from "../types/file";
*
* We don't really index Exif, we
*/
export const indexExif = (enteFile: EnteFile) => {
export const indexExif = async (enteFile: EnteFile) => {
const tags = await ExifReader.load(fileBuffer, { async: true })
return {
title: enteFile.title ?? "",
tags
};
};

View File

@@ -9,7 +9,7 @@ import DownloadManager from "../download";
import type { UploadItem } from "../upload/types";
import type { MLWorkerElectron } from "./worker-types";
export interface ImageBitmapAndData {
export interface IndexableImage {
bitmap: ImageBitmap;
data: ImageData;
}
@@ -20,7 +20,7 @@ export interface ImageBitmapAndData {
*/
export const imageBitmapAndData = async (
imageBlob: Blob,
): Promise<ImageBitmapAndData> => {
): Promise<IndexableImage> => {
const imageBitmap = await createImageBitmap(imageBlob);
const { width, height } = imageBitmap;

View File

@@ -1,5 +1,5 @@
import type { Electron } from "@/base/types/ipc";
import type { ImageBitmapAndData } from "./blob";
import type { IndexableImage } from "./blob";
import { clipIndexes } from "./db";
import { pixelRGBBicubic } from "./image";
import { dotProduct, norm } from "./math";
@@ -102,7 +102,7 @@ export type LocalCLIPIndex = CLIPIndex & {
* our Node.js layer to run the ONNX inference.
*/
export const indexCLIP = async (
image: ImageBitmapAndData,
image: IndexableImage,
electron: MLWorkerElectron,
): Promise<CLIPIndex> => ({
embedding: await computeEmbedding(image.data, electron),

View File

@@ -17,7 +17,7 @@ import {
translate,
type Matrix as TransformationMatrix,
} from "transformation-matrix";
import type { ImageBitmapAndData } from "./blob";
import type { IndexableImage } from "./blob";
import {
grayscaleIntMatrixFromNormalized2List,
pixelRGBBilinear,
@@ -241,7 +241,7 @@ export interface Box {
*/
export const indexFaces = async (
enteFile: EnteFile,
{ data: imageData }: ImageBitmapAndData,
{ data: imageData }: IndexableImage,
electron: MLWorkerElectron,
): Promise<FaceIndex> => ({
width: imageData.width,

View File

@@ -15,7 +15,7 @@ import type { UploadItem } from "../upload/types";
import {
imageBitmapAndData,
renderableBlob,
type ImageBitmapAndData,
type IndexableImage,
} from "./blob";
import { clipIndexingVersion, indexCLIP, type CLIPIndex } from "./clip";
import { saveFaceCrops } from "./crop";
@@ -410,7 +410,7 @@ const index = async (
const imageBlob = await renderableBlob(enteFile, uploadItem, electron);
let image: ImageBitmapAndData;
let image: IndexableImage;
try {
image = await imageBitmapAndData(imageBlob);
} catch (e) {