forked from DayBreak-u/chineseocr_lite
-
Notifications
You must be signed in to change notification settings - Fork 22
/
app.py
39 lines (32 loc) · 1.02 KB
/
app.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
import ocr
import json
import tornado.web
import tornado.ioloop
from tornado.options import define, options
define('port', default=1234, help='运行端口', type=int)
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')
class OcrHandler(tornado.web.RequestHandler):
def post(self):
files = self.request.files['files']
for file in files:
filename = file['filename']
img = file['body']
result = ocr.result(img)
result = json.dumps(result, ensure_ascii=False)
print(result)
self.write('<p>{}: {}</p>'.format(filename, result))
self.flush()
if __name__ == '__main__':
settings = {
'template_path': 'templates',
}
app = tornado.web.Application(
[
(r'/', MainHandler),
(r'/ocr', OcrHandler),
], **settings)
app.listen(options.port)
print('http://localhost:{}/'.format(options.port))
tornado.ioloop.IOLoop.current().start()