Commit 54b2eedd authored by janithgamage1.ed's avatar janithgamage1.ed

fix: update

desc : update project
parent 44218348
...@@ -3,29 +3,34 @@ import { exec } from "child_process"; ...@@ -3,29 +3,34 @@ import { exec } from "child_process";
export const marksCalculator = async (req, res) => { export const marksCalculator = async (req, res) => {
const imageData = req.file.buffer.toString('base64'); const imageData = req.file.buffer.toString('base64');
const targetClass = req.body.class; const targetClass = req.body.class;
const { curriculumIndex, tutorialIndex } = req.params;
try { console.log(curriculumIndex, tutorialIndex);
// Run Python script to perform prediction
const pythonProcess = exec('python prediction_config/C1T1/predict.py', (error, stdout, stderr) => {
if (error) {
console.error(error);
return res.status(500).json({ error: 'An error occurred' });
}
const [predictedClass, confidence] = stdout.trim().split(',');
res.status(200).json({ try {
code: "01", if (curriculumIndex == 1 && tutorialIndex == 1) {
result: { // Run Python script to perform prediction
predictedClass, const pythonProcess = exec('python prediction_config/C1T1/predict.py', (error, stdout, stderr) => {
confidence: parseFloat(confidence).toFixed(2), if (error) {
console.error(error);
return res.status(500).json({ error: 'An error occurred' });
} }
}); const [predictedClass, confidence] = stdout.trim().split(',');
});
pythonProcess.stdin.write(`${imageData}\n${targetClass}`); res.status(200).json({
pythonProcess.stdin.end(); code: "01",
result: {
predictedClass,
confidence: parseFloat(confidence).toFixed(2),
}
});
});
pythonProcess.stdin.write(`${imageData}\n${targetClass}`);
pythonProcess.stdin.end();
} else {
return res.status(400).json({ code: "02", message: "Curriculum Index or Tutorial Index Invalid" })
}
} catch (error) { } catch (error) {
res.status(500).json({ code: "00", message: "Something went wrong" }) res.status(500).json({ code: "00", message: "Something went wrong" })
} }
......
...@@ -8,6 +8,6 @@ const upload = multer({ storage: storage }); ...@@ -8,6 +8,6 @@ const upload = multer({ storage: storage });
const router = express.Router(); const router = express.Router();
router.post('/curriculum/tutorial', upload.single('image'), marksCalculator) router.post('/curriculum/:curriculumIndex/tutorial/:tutorialIndex', upload.single('image'), marksCalculator)
export default router; export default router;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment