-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
76 lines (48 loc) · 1.89 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import csv
import shutil
import pandas as pd
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, send_file
from flask_cors import CORS, cross_origin
from predictFromModel import prediction
app = Flask(__name__)
app.config["csv_file"] = "Prediction_Output_File/"
app.config["sample_file"] = "Prediction_SampleFile/"
@app.route('/')
@cross_origin()
def home():
return render_template('index.html')
@app.route('/return_sample_file/')
@cross_origin()
def return_sample_file():
sample_file = os.listdir("Prediction_SampleFile/")[0]
return send_from_directory(app.config["sample_file"], sample_file)
@app.route('/return_file/')
@cross_origin()
def return_file():
final_file = os.listdir("Prediction_Output_File/")[0]
return send_from_directory(app.config["csv_file"], final_file)
@app.route('/result')
@cross_origin()
def result():
return render_template('result.html')
@app.route('/predict', methods=['POST'])
@cross_origin()
def predict():
if request.method == 'POST':
try:
if 'csvfile' not in request.files:
return render_template("invalid.html")
file = request.files['csvfile']
df = pd.read_csv(file, index_col=[0])
path = 'Prediction_InputFileFromUser/'
#if os.path.isfile('Prediction_InputFileFromUser/InputFile.csv'):
#os.remove('Prediction_InputFileFromUser/InputFile.csv')
df.to_csv('Prediction_InputFileFromUser/InputFile.csv')
pred = prediction() #object initialization
pred.predictionFromModel()
except Exception as e:
return render_template("invalid.html")
return redirect(url_for('result'))
if __name__ == '__main__':
app.run(debug=True)