feat: implement backend image classification with TensorFlow.js model
- Extend shared types for image classification, including PredictionProbability, UploaderMetadata, and ImageClassificationRecord. - Create image_classifications table in the database with necessary fields and foreign key constraints. - Implement disease mappers to convert database rows to shared disease records. - Develop uploader client to handle image uploads to external service. - Create image model service to load and classify images using TensorFlow.js. - Add API routes for image classification, including GET for history and POST for new classifications. - Implement frontend components for image classification form and display results. - Update dashboard to integrate image classification functionality and display results. - Document implementation plan for backend image classification.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import type { UploaderMetadata } from '@zeavis/shared';
|
||||
|
||||
export async function uploadImageToStorage(file: File): Promise<UploaderMetadata> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('fileName', file.name);
|
||||
|
||||
const response = await fetch('https://upload.asepharyana.tech/api/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Upload failed with status ${response.status}`);
|
||||
}
|
||||
|
||||
const data = (await response.json()) as Record<string, unknown>;
|
||||
|
||||
if (!data.download_url) {
|
||||
throw new Error('Upload response missing download_url');
|
||||
}
|
||||
|
||||
if (!data.public_id) {
|
||||
throw new Error('Upload response missing public_id');
|
||||
}
|
||||
|
||||
return data as UploaderMetadata;
|
||||
}
|
||||
Reference in New Issue
Block a user