-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
38 lines (29 loc) · 1.13 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
import pickle
import pandas as pd
import numpy as np
from flask import Flask, render_template, request, redirect, url_for
filename = 'model.sav'
model = pickle.load(open(filename, 'rb'))
app = Flask(__name__)
@app.route("/")
def input():
return render_template("index.html")
@app.route("/result/<float:price>")
def result(price):
price = "$ "+str(price)
return render_template("result.html", amount=price)
@app.route("/predict", methods=["POST", "GET"])
def predict():
if request.method == "POST":
wheelbase = float(request.form["wheelbase"])
carlength = float(request.form["carlength"])
curbweight = float(request.form["curbweight"])
boreratio = float(request.form["boreratio"])
enginesize = float(request.form["enginesize"])
horsepower = float(request.form["horsepower"])
data = np.array([wheelbase, carlength, curbweight, boreratio, enginesize, horsepower])
data = data.reshape(1, 6)
output = model.predict(data)
return redirect(url_for("result", price=output))
if __name__ == "__main__":
app.run(debug=True)