-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (34 loc) · 1.12 KB
/
app.py
File metadata and controls
42 lines (34 loc) · 1.12 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
from flask import Flask,render_template,request
import pickle
import numpy as np
import pandas as pd
model=pickle.load(open('model.pkl','rb'))
model1=pickle.load(open('model1.pkl','rb'))
app=Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict_ted_talk_views():
c=float(request.form.get('comments'))
d=float(request.form.get('duration'))
p_date=request.form.get('p_date')
r_date=request.form.get('r_date')
recorded_date=pd.to_datetime(r_date)
published_date=pd.to_datetime(p_date)
days_old=(published_date-recorded_date).days
is_weekend=published_date.dayofweek
#converting weekend-1 and otherwise-0
if is_weekend >=5:
is_weekend=1
else:
is_weekend=0
alc=int(request.form.get('alc'))
#prediction
x=np.array([c,d,days_old,is_weekend,alc]).reshape(1,5)
y=model1.transform(x)
result=model.predict(y)
result1=np.exp(result)
return render_template('index.html',result=result1)
if __name__ == '__main__':
app.run(debug=True)