Skip to content

Commit

Permalink
Add PyOCR Endpoints!
Browse files Browse the repository at this point in the history
  • Loading branch information
luccadimario committed Feb 26, 2024
1 parent 46765b8 commit cfafa56
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
30 changes: 30 additions & 0 deletions PyOCR/requestOcrFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default async function getFromOcrEndpointCompgen(b64String) {
url = "127.0.0.1:5000/ocr/compgen/"
const response = await fetch(url, {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json", //Body will be in json format
},
body: {
b64: b64String
},
});
return response.json();
}

export default async function getFromOcrEndpointHandwritten(b64String) {
url = "127.0.0.1:5000/ocr/handwritten/"
const response = await fetch(url, {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json", //Body will be in json format
},
body: {
b64: b64String
},
});
return response.json();
}

26 changes: 26 additions & 0 deletions routes/externalRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const DebugAPI = require(__dirname + "./../lib/aircraftLookup.js");
const JSONbig = require('json-bigint');
const jwt = require('jsonwebtoken');
const fs = require('fs');
const ocr = require('../PyOCR/requestOcrFunctions')


function authenticateToken(req, res, next) {
Expand Down Expand Up @@ -294,6 +295,31 @@ function startExternalRoutes(app, passport) {

/* END FILE MANAGMENT */

/* BEGIN B64 POST */


app.post('/api/ocr', authenticateToken, async (req, res) => {
if (req.body.b64 != null && req.body.handwritten == true) {
try {
let text = ocr.getFromOcrEndpointCompgen(req.body.b64);
res.send(text);

} catch (error) {
res.status(500).send('Server Error');
}
} else if(req.body.b64 != null && req.body.handwritten == false) {
try {
let text = ocr.getFromOcrEndpointHandwritten(req.body.b64);
res.send(text);
} catch (error) {
res.status(500).send('Server Error');
}
} else {
res.sendStatus(400);
}
});




}
Expand Down

0 comments on commit cfafa56

Please sign in to comment.