-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (28 loc) · 1.09 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
'''
This module contains the main function for the training pipeline.
author: Saurabh Bhardwaj
date: October 2023
'''
# import necessary libraries
import pandas as pd
from src.pipeline.prediction_pipeline import PredictPipeline
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/predict", methods=["POST"])
def predict():
# In a real-world scenario, you might check if the pipeline is running or handle errors here.
# Assuming you receive the data from a form with a file input named 'data_file'
uploaded_file = request.files['data_file']
if not uploaded_file:
return "No file uploaded."
# Assuming the file is in CSV format
data = pd.read_csv(uploaded_file)
# Assuming you have a PredictPipeline class
predictions_data = PredictPipeline().predict(data)
predictions = predictions_data['predicted_column'].tolist()
return render_template("predict.html", predictions=predictions)
if __name__ == "__main__":
app.run(debug=True, port=8000)