In [1]:
from flask import Flask,request
from scipy import misc
import cv2

In [ ]:
import numpy as np
import pandas as pd
from keras.models import model_from_json


Using TensorFlow backend.
Couldn't import dot_parser, loading of dot files will not be possible.

In [ ]:
app = Flask(__name__)

@app.route('/upload', methods=['POST'])
def upload():
    f = request.files['file']
    im = misc.imread(f) 
    
    resized_image=cv2.resize(im,(100,100))
    img_arr=np.asarray(resized_image).reshape((1,resized_image.shape[1], resized_image.shape[0],3))
    X_test = img_arr.astype('float32')
    X_test_rescale=X_test/255
    
    # load json and create model
    json_file = open('cnn18.json', 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    loaded_model = model_from_json(loaded_model_json)
    # load weights into new model
    loaded_model.load_weights("cnn18.h5")
    
    y_pred_probas1 = loaded_model.predict(X_test_rescale)
    y_pred = np.argmax(y_pred_probas1)
    
    flower_dir={
                0:'African_daisy',
                1:'Cornflower',
                2:'Ice_plant',
                3:'Nigella',
                4:'Peony',
                5:'Ragged_robin',
                6:'Soapwort',
                7:'Spathiphyllum',
                8:'Spring_beauty',
                9:'Sunflower'}
    result=flower_dir[y_pred]
    result2='This is a ' + result +' image'
    return result2


@app.route('/')
def index():
    return '''
    <!doctype html>
    <html>
    <body>
    <form action='/upload' method='post' enctype='multipart/form-data'>
        <input type='file' name='file'>
    <input type='submit' value='Upload'>
    </form>
    '''    
if __name__ == '__main__':
    app.run()


 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [14/Sep/2017 08:51:54] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 08:52:06] "POST /upload HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 08:52:19] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 09:20:42] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 10:43:21] "POST /upload HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 10:43:28] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 10:43:58] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 11:58:41] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 11:58:55] "POST /upload HTTP/1.1" 200 -
127.0.0.1 - - [14/Sep/2017 11:59:09] "POST /upload HTTP/1.1" 200 -

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: