-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
52 lines (33 loc) · 1.67 KB
/
app.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
from flask import Flask, render_template, request
import os, sys
import numpy as np
import pandas as pd
from src.irisdataprediction.pipeline.prediction_pipeline import PredictionPipeline
from src.irisdataprediction.exception import IrisPredictionException
from src.irisdataprediction.utils.ml_utils.preprocessor.helper import data_standardization
app = Flask(__name__)
@app.route('/', methods=['GET'])
def homepage():
return render_template("index.html")
@app.route('/predict', methods=['POST','GET'])
def index():
if request.method == 'POST':
try:
sepal_length = float(request.form['sepal_length'])
sepal_width = float(request.form['sepal_width'])
petal_length = float(request.form['petal_length'])
petal_width = float(request.form['petal_width'])
data = [sepal_length, sepal_width, petal_length, petal_width]
independent_features = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
data=pd.DataFrame(np.array(data).reshape(1,-1),columns=independent_features,index=None)
normalized_data = data_standardization(data,independent_features)
prediction_pipeline = PredictionPipeline()
spicies = prediction_pipeline.predict(normalized_data)
flower_type = ['setosa', 'versicolor', 'virginica']
return render_template("index.html", prediction=str(flower_type[int(spicies[0])]))
except Exception as e:
raise IrisPredictionException(e,sys)
else:
return render_template("index.html")
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8080)