-
Notifications
You must be signed in to change notification settings - Fork 5
/
prediction.py
73 lines (60 loc) · 1.89 KB
/
prediction.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
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#python3
from flask import Flask, request, jsonify
import json
from flask_cors import CORS
import pandas as pd
import numpy as np
import pickle
app = Flask(__name__)
CORS(app)
@app.route("/")
def hello():
return "testing"
@app.route("/predict", methods=['POST'])
def predict():
print("hello")
print(request.form)
state = float(request.form['state'])
i = float(request.form['iodine'])
sex = float(request.form['gender'])
age = float(request.form['age'])
weight = float(request.form['weight'])
height = float(request.form['height'])
haem = float(request.form['haemoglobin'])
first_breast_feed = float(request.form['firstBf'])
curr_breast_feed = float(request.form['isCurrBf'])
no_bf = float(request.form['bfduration'])
water = float(request.form['watermonth'])
ani = float(request.form['animalmilk'])
semi_solid = float(request.form['semisolid'])
solid = float(request.form['solid'])
veg = float(request.form['vegetable'])
attributes = np.array([state, i, sex, age, weight, height, haem, first_breast_feed, curr_breast_feed, no_bf, water, ani, semi_solid, solid, veg])
response = predictor(attributes)
print("the response")
print(response)
response = jsonify(response)
response.headers.add('Access-Control-Allow-Origin', '*')
return response
def res(x):
if x == 0:
return 'No illness'
elif x == 1:
return 'Dyssentry/Diarhhoea'
elif x == 2:
return 'Acute Respiratory Infection'
elif x == 3:
return 'Fever of any type'
elif x == 4:
return 'Other illnesses'
def predictor(test):
classifier = pickle.load(open('model.sav', 'rb'))
test = test.reshape(1, -1)
result = classifier.predict(test)
print("result")
print(res(result[0]))
ret = {'type' : "JSON/TXT"}
ret['result'] = str(res(result[0]))
print(ret)
return ret
app.run()