bottle创建python的rest接口

来源:互联网 发布:淘宝微博运营团队 编辑:程序博客网 时间:2024/04/30 00:29


# -*- coding: utf-8 -*-"""Created on Wed Nov 15 16:00:06 2017@author: ESRI"""from PIL import Imageimport numpy as npimport pandas as pd from sklearn.externals import joblibfrom bottle import route, run, template@route('/hello/<name>')def index(name):    file='E:\\python\\kaggle\\DigitRecognizer\\picture\\picture'+ name + '.jpg'    pixel_lists = []    print 'file path is:'    print file    img = Image.open(file)    img = img.convert("L")    print img    img = img.resize((28, 28))      print img.size    img_array = np.asarray(img)    print type(img_array)    print img_array    vec = img_array.reshape(1,784)    print vec    pixel_lists.append(vec[0])    columns = ['pixel'+ str(s) for s in range(0,784)]        df = pd.DataFrame(pixel_lists,columns=columns)    #print df.describe()    print df.values        clf1 = joblib.load("E:\\python\\kaggle\\DigitRecognizer\\train_model.m")    print clf1    result = clf1.predict(df.values)    print result[0]    #return result[0]    return "success_jsonpCallback("  +  str(result[0])  + ");" run(host='localhost', port=8088)



原创粉丝点击