-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
60 lines (50 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
53
54
55
56
57
58
59
60
#importing libraries
import os
import numpy as np
import flask
import pickle
import plotly
import plotly.graph_objects as go
import chart_studio.plotly as py
import json
import pandas as pd
from flask import Flask, render_template, request
from datetime import time
#creating instance of the class
app=Flask(__name__)
#to tell flask what url shoud trigger the function index()
@app.route('/')
# @app.route('/index')
def index():
return flask.render_template('index.html')
@app.route('/tentang')
def tentang():
return flask.render_template('tentang.html')
@app.route('/grafik')
def grafik():
# fn = secure_filename(myFile.filename)
# df = pd.read_csv(fn)
df = pd.read_csv('data.csv')
x = np.array(list(df['Tanggal']))
y = np.array(list(df['Jumlah Ch']))
plot = go.Scatter(x=x, y=y)
plot = [plot]
plotJSON = json.dumps(plot, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('grafik.html', x=plotJSON)
def ValuePredictor(to_predict_list):
to_predict = np.array(to_predict_list).reshape(1,3)
loaded_model = pickle.load(open("model.pkl","rb"))
result = loaded_model.predict(to_predict)
return result[0]
@app.route('/result',methods = ['POST'])
def result():
if request.method == 'POST':
to_predict_list = request.form.to_dict()
to_predict_list=list(to_predict_list.values())
to_predict_list = list(map(int, to_predict_list))
result = ValuePredictor(to_predict_list)
if int(result)>500:
prediction='Terjadi potensi banjir'
else:
prediction='Tidak terjadi potensi banjir'
return render_template("result.html",prediction=prediction, result=result)