-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.py
executable file
·73 lines (54 loc) · 1.84 KB
/
upload.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
70
71
72
73
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import base64
import errno
import json
import os
from flask import (Flask, jsonify, redirect, request, send_from_directory,
url_for)
from backend.vision_api import VisionApi
#from backend.preprocessing import Preprocessing
from flask_cors import CORS, cross_origin
from flask_sslify import SSLify
UPLOAD_FOLDER = '/tmp/uploads/'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
app = Flask(__name__)
CORS(app)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
img = request.form['img']
#img = Preprocessing.preprocess(img)
vision = VisionApi()
print("Received Image of Size %d" % len(img))
response = vision.detect_text(base64_str=img)
print response
return response
return app.send_static_file('index.html')
@app.route('/base64/&