Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- // Our prediction endpoint (Receives an image as req.file)
- app.post('/predict', upload.single('img'), async function (req, res) {
- const { path } = req.file
- try {
- const prediction = await PythonConnector.invoke('predict_from_img', path);
- res.json(prediction);
- }
- catch (e) {
- console.log(`error in ${req.url}`, e);
- res.sendStatus(404);
- }
- // delete the uploaded file (regardless whether prediction successful or not)
- fs.unlink(path, (err) => {
- if (err) console.error(err)
- console.log('Cleaned up', path)
- })
- })
- ...
Add Comment
Please, Sign In to add comment