mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(ml) backend takes image over HTTP (#2783)
* using pydantic BaseSetting * ML API takes image file as input * keeping image in memory * reducing duplicate code * using bytes instead of UploadFile & other small code improvements * removed form-multipart, using HTTP body * format code --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
3e804f16df
commit
34201be74c
8 changed files with 116 additions and 80 deletions
|
|
@ -1,21 +1,26 @@
|
|||
import { DetectFaceResult, IMachineLearningRepository, MachineLearningInput, MACHINE_LEARNING_URL } from '@app/domain';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { createReadStream } from 'fs';
|
||||
|
||||
const client = axios.create({ baseURL: MACHINE_LEARNING_URL });
|
||||
|
||||
@Injectable()
|
||||
export class MachineLearningRepository implements IMachineLearningRepository {
|
||||
private post<T>(input: MachineLearningInput, endpoint: string): Promise<T> {
|
||||
return client.post<T>(endpoint, createReadStream(input.imagePath)).then((res) => res.data);
|
||||
}
|
||||
|
||||
classifyImage(input: MachineLearningInput): Promise<string[]> {
|
||||
return client.post<string[]>('/image-classifier/tag-image', input).then((res) => res.data);
|
||||
return this.post<string[]>(input, '/image-classifier/tag-image');
|
||||
}
|
||||
|
||||
detectFaces(input: MachineLearningInput): Promise<DetectFaceResult[]> {
|
||||
return client.post<DetectFaceResult[]>('/facial-recognition/detect-faces', input).then((res) => res.data);
|
||||
return this.post<DetectFaceResult[]>(input, '/facial-recognition/detect-faces');
|
||||
}
|
||||
|
||||
encodeImage(input: MachineLearningInput): Promise<number[]> {
|
||||
return client.post<number[]>('/sentence-transformer/encode-image', input).then((res) => res.data);
|
||||
return this.post<number[]>(input, '/sentence-transformer/encode-image');
|
||||
}
|
||||
|
||||
encodeText(input: string): Promise<number[]> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue