-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (26 loc) · 1.02 KB
/
app.py
File metadata and controls
31 lines (26 loc) · 1.02 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
from flask import Flask, request, render_template, jsonify
import pickle
from src.pipeline.predict_pipeline import FlightDataPreprocessor
app = Flask(__name__)
preprocessor = FlightDataPreprocessor()
def load_model(model_path='artifacts/model.pkl'):
with open(model_path, 'rb') as file:
model = pickle.load(file)
return model
@app.route("/")
def index():
return render_template("index.html")
@app.route("/predict", methods=["POST"])
def predict():
try:
form_data = request.form.to_dict()
features = preprocessor.preprocess_form_data(form_data)
model = load_model()
prediction = model.predict(features)
prediction_text = f"Predicted Flight Price: {round(prediction[0])}"
return render_template("index.html", prediction_text=prediction_text)
except Exception as e:
error_message = f"An error occurred: {str(e)}"
return render_template("index.html", prediction_text=error_message)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)