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";
export const marksCalculator = async (req, res) => {
const imageData = req.file.buffer.toString('base64');
const targetClass = req.body.class;
const { curriculumIndex, tutorialIndex } = req.params;
try {
// 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(',');
console.log(curriculumIndex, tutorialIndex);
res.status(200).json({
code: "01",
result: {
predictedClass,
confidence: parseFloat(confidence).toFixed(2),
try {
if (curriculumIndex == 1 && tutorialIndex == 1) {
// 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(',');
pythonProcess.stdin.write(`${imageData}\n${targetClass}`);
pythonProcess.stdin.end();
res.status(200).json({
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) {
res.status(500).json({ code: "00", message: "Something went wrong" })
}
......
......@@ -8,6 +8,6 @@ const upload = multer({ storage: storage });
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;
\ 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