forked from IBMDeveloperUK/Machine-Learning-with-Minishift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
31 lines (21 loc) · 747 Bytes
/
server.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
from flask import Flask, request
from flask import render_template
import keras, sys, json
import numpy as np
application = Flask(__name__)
stored_model = None
@application.route("/")
def hello():
return render_template('index.html')
@application.route("/predict", methods=['POST'])
def classifyCharacter():
global stored_model
body = request.get_json()
reshapedData = np.array(body['data'])
reshapedData = reshapedData.reshape(1,28,28,1)
return json.dumps( { 'prediction' : int(stored_model.predict_classes( reshapedData )[0]) } )
def start():
global stored_model
stored_model = keras.models.load_model('mnist.h5')
stored_model._make_predict_function()
application.run(host='0.0.0.0', port=8080)