π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[rust][desktop] Make ML image input bytes-only
laurenspriem27a9207a4836
diff --git a/desktop/src/main/services/ml-worker.ts b/desktop/src/main/services/ml-worker.tsindex b439e62cfd..06f17a9379 100644--- a/desktop/src/main/services/ml-worker.ts+++ b/desktop/src/main/services/ml-worker.ts@@ -170,8 +170,7 @@ export const releaseMLRuntime = () => {export interface MLWorkerAnalyzeImageRequest {fileID: number;- path?: string | undefined;- bytes?: Uint8Array | undefined;+ bytes: Uint8Array;runFaces: boolean;runClip: boolean;runPets: boolean;@@ -217,15 +216,6 @@ const analyzeImageOnce = async (native: MLNative,req: MLWorkerAnalyzeImageRequest,) => {- let source;- if (req.path !== undefined) {- source = { imagePath: req.path };- } else if (req.bytes) {- source = { imageBytes: uint8ArrayToBuffer(req.bytes) };- } else {- throw new Error("The analyze request has neither a path nor bytes");- }-const modelPaths = await indexingModelPaths(req.runFaces,req.runClip,@@ -234,7 +224,7 @@ const analyzeImageOnce = async (ensureMLRuntime(native, modelPaths);return await native.analyzeImage({fileId: req.fileID,- ...source,+ imageBytes: uint8ArrayToBuffer(req.bytes),runFaces: req.runFaces,runClip: req.runClip,runPets: req.runPets,diff --git a/infra/ml/test/tools/desktop_parity_runner.js b/infra/ml/test/tools/desktop_parity_runner.jsindex 28b4b207fd..b66fb13090 100755--- a/infra/ml/test/tools/desktop_parity_runner.js+++ b/infra/ml/test/tools/desktop_parity_runner.js@@ -104,10 +104,10 @@ const mlModelPaths = (models) => ({petBodyEmbeddingCat: "",});-const analyzeFixture = async (native, fileID, imagePath, modelPaths) => {+const analyzeFixture = async (native, fileID, imageBytes, modelPaths) => {const result = await native.analyzeImage({fileId: fileID,- imagePath,+ imageBytes,runFaces: true,runClip: true,runPets: false,@@ -185,11 +185,13 @@ const main = async () => {for (const [index, item] of items.entries()) {const t = Date.now();try {- const imagePath = path.resolve(args["ml-dir"], item.source);+ const imageBytes = await fsp.readFile(+ path.resolve(args["ml-dir"], item.source),+ );const result = await analyzeFixture(native,index + 1,- imagePath,+ imageBytes,modelPaths,);results.push(diff --git a/rust/bindings/napi/photos/src/lib.rs b/rust/bindings/napi/photos/src/lib.rsindex e1d568a003..5903e7a58c 100644--- a/rust/bindings/napi/photos/src/lib.rs+++ b/rust/bindings/napi/photos/src/lib.rs@@ -124,8 +124,7 @@ impl AssetStore {#[napi(object)]pub struct AnalyzeImageRequest {pub file_id: i64,- pub image_path: Option<String>,- pub image_bytes: Option<Buffer>,+ pub image_bytes: Buffer,pub run_faces: bool,pub run_clip: bool,pub run_pets: bool,@@ -213,28 +212,18 @@ impl Task for AnalyzeImageTask {}#[napi(ts_return_type = "Promise<AnalyzeImageResult>")]-pub fn analyze_image(req: AnalyzeImageRequest) -> Result<AsyncTask<AnalyzeImageTask>> {- let source = match (req.image_path, req.image_bytes) {- (Some(path), None) => shared_indexing::ImageSource::Path(path),- (None, Some(bytes)) => shared_indexing::ImageSource::Bytes(bytes.to_vec()),- _ => {- return Err(Error::from_reason(- "InvalidRequest: exactly one of imagePath and imageBytes must be set".to_string(),- ));- }- };-- Ok(AsyncTask::new(AnalyzeImageTask {+pub fn analyze_image(req: AnalyzeImageRequest) -> AsyncTask<AnalyzeImageTask> {+ AsyncTask::new(AnalyzeImageTask {req: Some(shared_indexing::AnalyzeImageRequest {file_id: req.file_id,- source,+ source: shared_indexing::ImageSource::Bytes(req.image_bytes.to_vec()),run_faces: req.run_faces,run_clip: req.run_clip,run_pets: req.run_pets,generate_face_crops: req.generate_face_crops,model_paths: to_shared_model_paths(&req.model_paths),}),- }))+ })}#[napi(object)]diff --git a/web/packages/base/types/ipc.ts b/web/packages/base/types/ipc.tsindex 8881e65a93..5ed8f3702f 100644--- a/web/packages/base/types/ipc.ts+++ b/web/packages/base/types/ipc.ts@@ -140,8 +140,7 @@ export interface ElectronMLWorker {export interface MLWorkerAnalyzeImageRequest {fileID: number;- path?: string | undefined;- bytes?: Uint8Array | undefined;+ bytes: Uint8Array;runFaces: boolean;runClip: boolean;runPets: boolean;