-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
52 lines (43 loc) · 1.41 KB
/
Copy pathcontroller.js
File metadata and controls
52 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { extractTextFromImage } from './ocr.js';
import { solveMathProblem } from './agent.js';
export const solveMathProblemFromImage = async (req, res) => {
try {
// Check if image file exists
if (!req.file) {
return res.status(400).json({
error: 'No image file provided'
});
}
console.log('Processing image:', req.file.originalname);
// Extract text from image using OCR
const extractedText = await extractTextFromImage(req.file.buffer);
if (!extractedText || extractedText === 'No text detected') {
return res.status(400).json({
error: 'Could not extract text from image. Please ensure the image contains clear, readable text.'
});
}
console.log('Extracted text:', extractedText);
// Solve the math problem using the agent
const solution = await solveMathProblem(extractedText);
// Return the complete solution
res.json({
success: true,
originalImage: req.file.originalname,
extractedText: extractedText,
solution: solution
});
} catch (error) {
console.error('Error in solveMathProblemFromImage:', error);
res.status(500).json({
error: 'Failed to process math problem',
details: error.message
});
}
};
export const healthCheck = (req, res) => {
res.json({
status: 'OK',
message: 'Math Solver API is running',
timestamp: new Date().toISOString()
});
};