-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
51 lines (36 loc) · 1.39 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
import pickle
from flask import Flask,request,jsonify,render_template
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
import secrets
app = Flask(__name__)
#Generate a secure random key
secret_key = secrets.token_hex(16)
app.secret_key = secret_key
## import ridge regressor model and standard scaler pickle
ridge_model=pickle.load(open('models/ridge.pkl','rb'))
standard_scaler=pickle.load(open('models/scaler.pkl','rb'))
## Route for home page
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict_datapoint',methods=['GET','POST'])
def predict_datapoint():
if request.method=='POST':
Temperature=float(request.form.get('Temperature'))
RH=float(request.form.get('RH'))
Ws=float(request.form.get('Ws'))
Rain=float(request.form.get('Rain'))
FFMC=float(request.form.get('FFMC'))
DMC=float(request.form.get('DMC'))
ISI=float(request.form.get('ISI'))
Classes=float(request.form.get('Classes'))
Region=float(request.form.get('Region'))
new_data_scaled=standard_scaler.transform([[Temperature,RH,Ws,Rain,FFMC,DMC,ISI,Classes,Region]])
result=ridge_model.predict(new_data_scaled)
return render_template('index.html',result=result[0])
else:
return render_template("index.html")
if __name__=="__main__":
app.run(host="0.0.0.0")