-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
39 lines (28 loc) · 1.18 KB
/
application.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
from flask import Flask, render_template, jsonify, request, send_file
from src.exception import CustomException
from src.logger import logging
import os,sys
from src.pipelines.prediction_pipeline import predictionpipeline
app = Flask(__name__)
@app.route("/")
def home():
return "Welcome to my application"
@app.route('/predict', methods=['POST', 'GET'])
def upload():
try:
if request.method == 'POST':
# Instantiate prediction pipeline
pipeline = predictionpipeline(request=request)
# Run prediction pipeline
prediction_file_detail = pipeline.run_pipeline()
logging.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.html')
except Exception as e:
logging.exception("An error occurred during prediction.")
raise CustomException(e, sys)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug= True)