-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: UTF-8 -*- | ||
import pickle | ||
import gzip | ||
|
||
# 載入Model | ||
with gzip.open('./model/xgboost-iris.pgz', 'rb') as f: | ||
xgboostModel = pickle.load(f) | ||
|
||
def predict(input): | ||
pred=xgboostModel.predict(input)[0] | ||
return pred |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Flask | ||
Flask-Cors | ||
numpy | ||
scikit-learn | ||
xgboost |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: UTF-8 -*- | ||
import numpy as np | ||
import model | ||
|
||
from flask import Flask, request, jsonify | ||
from flask_cors import CORS | ||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
|
||
@app.route('/') | ||
def index(): | ||
return 'hello!!' | ||
|
||
@app.route('/predict', methods=['POST']) | ||
def postInput(): | ||
# 取得前端傳過來的數值 | ||
insertValues = request.get_json() | ||
x1=insertValues['sepalLengthCm'] | ||
x2=insertValues['sepalWidthCm'] | ||
x3=insertValues['petalLengthCm'] | ||
x4=insertValues['petalWidthCm'] | ||
input = np.array([[x1, x2, x3, x4]]) | ||
|
||
result = model.predict(input) | ||
|
||
return jsonify({'return': str(result)}) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=3000, debug=True) |