Guest User

Untitled

a guest
Nov 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. ...
  2.  
  3. // Our prediction endpoint (Receives an image as req.file)
  4. app.post('/predict', upload.single('img'), async function (req, res) {
  5. const { path } = req.file
  6. try {
  7. const prediction = await PythonConnector.invoke('predict_from_img', path);
  8. res.json(prediction);
  9. }
  10. catch (e) {
  11. console.log(`error in ${req.url}`, e);
  12. res.sendStatus(404);
  13. }
  14.  
  15. // delete the uploaded file (regardless whether prediction successful or not)
  16. fs.unlink(path, (err) => {
  17. if (err) console.error(err)
  18. console.log('Cleaned up', path)
  19. })
  20. })
  21.  
  22. ...
Add Comment
Please, Sign In to add comment