-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (55 loc) · 1.98 KB
/
main.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from flask import Flask
from flask import request
from flask import json
from flask.wrappers import Request
from ocr import draw_boxes, parse, parse_to_image, image_boxes, image_boxes_to_text, image_boxes_to_text_vision_api, image_2dboxes_to_text, image_2dboxes_to_text_vision_api
from six.moves import urllib
import os
app = Flask(__name__)
from flask import send_file
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/ocr')
def ocr():
url = request.args.get("url")
#url = urllib.parse.unquote(url)
print(url)
boxes = parse(url)
print(boxes)
return json.jsonify(boxes)
@app.route('/ocr-to-image')
def ocr2image():
url = request.args.get("url")
#url = urllib.parse.unquote(url)
print(url)
filename = parse_to_image(url)
return send_file(filename, mimetype='image/png')
@app.route('/image-rect', methods=['GET', 'POST'])
def imagerect():
url = request.args.get("url")
content = request.json
filename = image_boxes(url, content["positions"])
#url = urllib.parse.unquote(url)
print(url)
return send_file(filename, mimetype='image/png')
@app.route('/imageboxes2text', methods=['GET', 'POST'])
def imageboxes2text():
url = request.args.get("url")
content = request.json
print("imageboxes2text : Positions")
print(content["positions"])
#positions = image_boxes_to_text(url, content["positions"])
positions = image_boxes_to_text_vision_api(url, content["positions"])
return json.jsonify(positions)
@app.route('/image2dboxes2text', methods=['GET', 'POST'])
def image2dboxes2text():
url = request.args.get("url")
content = request.json
print("/image2dboxes2text: Positions")
print(content["positions"])
#positions = image_2dboxes_to_text(url, content["positions"])
positions = image_2dboxes_to_text_vision_api(url, content["positions"])
return json.jsonify(positions)
if __name__ == '__main__':
app.run(host='0.0.0.0',port=os.environ['APPLICATION_PORT'])