-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
53 lines (37 loc) · 1.46 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
from flask import Flask, render_template, request,send_file
from src.exception import CustomException
from src.logger import logging as lg
import os,sys
from src.pipelines.train_pipeline import TrainingPipeline
from src.pipelines.predict_pipeline import PredictPipeline
app = Flask(__name__)
@app.route("/")
def home():
return "Welcome to my application"
@app.route("/train")
def train_route():
try:
train_pipeline = TrainingPipeline()
train_pipeline.run_pipeline()
return "Training Completed."
except Exception as e:
raise CustomException(e,sys)
@app.route('/predict', methods=['POST', 'GET'])
def upload():
try:
if request.method == 'POST':
# it is a object of prediction pipeline
prediction_pipeline = PredictPipeline(request)
#now we are running this run pipeline method
prediction_file_detail = prediction_pipeline.run_pipeline()
lg.info("prediction completed. Downloading prediction file.")
return send_file(prediction_file_detail.prediction_file_path,
download_name= prediction_file_detail.prediction_file_name,
as_attachment= True)
else:
return render_template('upload_file.html')
except Exception as e:
raise CustomException(e,sys)
# Code execution starts here
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug= True)