-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (39 loc) · 1.58 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
import logging
from flask import Flask, request, render_template
from src.logger import logger
from src.exception import CustomException
import sys
from src.pipeline.prediction_pipeline import PredictPipeline, CustomData
app = Flask(__name__)
# Configure logging
logging.basicConfig(level=logging.DEBUG)
@app.route('/')
def home_page():
return render_template("index.html")
@app.route("/predict", methods=["GET", "POST"])
def predict_datapoint():
if request.method == "GET":
return render_template("form.html")
else:
try:
data = CustomData(
carat=float(request.form.get("carat")),
depth=float(request.form.get("depth")),
table=float(request.form.get("table")),
x=float(request.form.get("x")),
y=float(request.form.get("y")),
z=float(request.form.get("z")),
cut=request.form.get("cut"),
color=request.form.get("color"),
clarity=request.form.get("clarity")
)
final_data = data.get_data_as_dataframe()
predict_pipeline = PredictPipeline()
pred = predict_pipeline.predict(final_data)
result = round(pred[0], 2)
return render_template("result.html", final_result=result)
except Exception as e:
logging.error("Error during prediction: %s", e)
return render_template("form.html", error="An error occurred during prediction. Please check your input and try again.")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)