Commit 91e900ea authored by janithgamage1.ed's avatar janithgamage1.ed

fix: update

Desc : update project
parent c21e6f61
......@@ -5,6 +5,8 @@ export const marksCalculator = async (req, res) => {
const targetClass = req.body.class;
const { curriculumIndex, tutorialIndex } = req.params;
const status = "";
// console.log(curriculumIndex, tutorialIndex);
try {
......@@ -15,13 +17,24 @@ export const marksCalculator = async (req, res) => {
console.error(error);
return res.status(500).json({ error: 'An error occurred' });
}
const [predictedClass, confidence] = stdout.trim().split(',');
const [predicted_class_name, confidence] = stdout.trim().split(',');
const parsedConfidence = parseFloat(confidence).toFixed(2);
let status = "";
if (predicted_class_name === targetClass && parsedConfidence > 85) {
status = "pass";
} else {
status = "fail";
}
res.status(200).json({
code: "01",
result: {
predictedClass,
confidence: parseFloat(confidence).toFixed(2),
predicted_class_name,
confidence: parsedConfidence,
status
}
});
});
......
......@@ -56,6 +56,27 @@ class theCNN(nn.Module):
return torch.softmax(self.output(x), axis=1)
# Load the mapping dictionary
class_mapping = {
0: 'Eight',
1: 'Eleven',
2: 'Fifty',
3: 'Five',
4: 'Four',
5: 'Fourteen',
6: 'Nine',
7: 'One',
8: 'Seven',
9: 'Six',
10: 'Ten',
11: 'Thirteen',
12: 'Thirty',
13: 'Three',
14: 'Twenty',
15: 'Two'
}
# Load the trained model
model = theCNN() # Instantiate your model class
model.load_state_dict(torch.load(
......@@ -85,8 +106,11 @@ with torch.no_grad():
predicted_class = torch.argmax(outputs[0]).item()
confidence = outputs[0][predicted_class].item()
# Get the predicted class name using the mapping dictionary
predicted_class_name = class_mapping[predicted_class]
# Calculate similarity or confidence percentage
# target_class = sys.argv[2].lower() # Class name passed from the API
similarity = 100 * confidence
print(f"{predicted_class},{similarity:.2f}")
print(f"{predicted_class_name},{similarity:.2f}")
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