-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathocr_correction_api.py
More file actions
executable file
·38 lines (30 loc) · 912 Bytes
/
Copy pathocr_correction_api.py
File metadata and controls
executable file
·38 lines (30 loc) · 912 Bytes
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
#!/bin/python
# -*- coding: utf-8 -*-
from flask import request, jsonify, Flask
import os
# import sys
from util import evaluate
from decode import decode, load_vocab, load_model
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
@app.route("/predict", methods=['POST'])
def predict():
if request.method == 'POST':
ocr_text = request.get_json()
print(ocr_text)
original_sent = ocr_text['ocr_text']
output_sent = decode(original_sent)[0][0]
evals = evaluate(original_sent, output_sent)
result = {'predicted': output_sent,
'evaluated': evals}
print(result)
return jsonify(result)
else:
return '<h1>Error</h1>'
if __name__ == '__main__':
# load vocabulary and model
load_vocab()
load_model()
# run app
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
app.run(port=6002, host="0.0.0.0")