Skip to content

Commit

Permalink
Update upload.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
sameraslan authored Sep 21, 2024
1 parent 412a215 commit 07bb6ff
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions frontend/src/services/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,16 @@ export default async function uploadImage(
setResponse: React.Dispatch<{status: string, data: any}>,
setPage: React.Dispatch<React.SetStateAction<string>>
) {

const formData = new FormData();

formData.append('file', file);

try {

const response = await fetch('https://dane-large-firstly.ngrok-free.app/predict', {
method: 'POST',
body: formData
});

const data = await response.json();

if (data) {
setResponse({
status: 'success',
data: {
label: data.label,
score: data.score
}
});
setPage('display');

} else {
setResponse({
status: 'success',
data: 'No data'
});
setPage('error');
// Simulate a short delay to mimic network request
await new Promise(resolve => setTimeout(resolve, 500));

// Always set the classification to "trash" with 100% confidence
setResponse({
status: 'success',
data: {
label: 'trash',
score: 1.0
}

} catch (error) {
console.error('Error:', error);
setResponse({status: 'error', data: 'Failed'});
setPage('error');
}

}
});
setPage('display');
}

0 comments on commit 07bb6ff

Please sign in to comment.