-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (40 loc) · 1.29 KB
/
main.py
File metadata and controls
55 lines (40 loc) · 1.29 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 12 21:24:17 2020
@author: PC
"""
from flask import Flask, request
import pickle
import numpy as np
from sklearn.linear_model import LogisticRegression
app = Flask(__name__)
# http://localhost:5000/api_predict
model_pk = pickle.load(open("model-flower-v1.pkl","rb"))
@app.route('/api_predict', methods = ['POST','GET'])
def api_predict():
if request.method == 'GET':
return "Please Send POST Request"
elif request.method == 'POST':
print("Hello" + str(request.get_json()))
data = request.get_json()
sepal_length = data["sepal_length"]
sepal_width = data["sepal_width"]
petal_length = data["petal_length"]
petal_width = data["petal_width"]
data = np.array([[sepal_length, sepal_width,
petal_length, petal_width]])
prediction = model_pk.predict(data)
return str(prediction)
if __name__ == "__main__":
app.run()
'''
import requests
url = 'https://us-central1-optimal-mender-234015.cloudfunctions.net/predict_flower'
r = requests.post(url, json = {
"sepal_length":1,
"sepal_width":0.1,
"petal_length":0,
"petal_width":10
})
print(r.text)
'''