-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplication.py
37 lines (27 loc) · 844 Bytes
/
application.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
from flask import Flask, render_template, request, make_response
from flask_cors import CORS, cross_origin
import base64
import io
from PIL import Image
import numpy as np
import json
app = Flask(__name__)
cors = CORS(app)
@app.route('/')
def index():
return render_template('index2.html')
@app.route('/send_image', methods=['POST'])
@cross_origin()
def send_image():
data = request.form.get('send')
data = data.split(',')[1]
im = base64.b64decode(data)
buf = io.BytesIO(im)
img = Image.open(buf)
img = img.resize((28, 28), Image.ANTIALIAS)
image_data = np.array(list(img.getdata()))[:, -1].reshape(28, 28)
image_data = image_data/max(image_data.ravel())
image_data = image_data.reshape(1, 28, 28, 1)
return json.dumps({"image": image_data.tolist()})
if __name__=='__main__':
app.run()