done
This commit is contained in:
31
Server/routes/classificationRoute.js
Normal file
31
Server/routes/classificationRoute.js
Normal file
@ -0,0 +1,31 @@
|
||||
const express = require('express');
|
||||
const multer = require('multer');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { classifyImage } = require('../controllers/classificationController');
|
||||
|
||||
const router = express.Router();
|
||||
const upload = multer({ dest: 'uploads/' });
|
||||
|
||||
router.post('/classify', upload.single('image'), async (req, res) => {
|
||||
try {
|
||||
if (!req.file) {
|
||||
return res.status(400).json({ error: 'No image file uploaded' });
|
||||
}
|
||||
|
||||
const imagePath = path.join(__dirname, `../${req.file.path}`);
|
||||
const predictedClass = await classifyImage(imagePath);
|
||||
|
||||
fs.unlinkSync(imagePath);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
predictedClass,
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
Reference in New Issue
Block a user