Select Git revision
main.py 2.59 KiB
from flask import Flask, render_template, url_for, request, redirect, flash
from datetime import datetime
from werkzeug.utils import secure_filename
import os, time, sys
"""
The following are the import for the backend. Just write the name of the script without .py
"""
sys.path.append(os.path.join(os.path.dirname(sys.path[0]),'backend'))
import input
#define the app
app = Flask(__name__)
#the secret key :)
app.secret_key = '54321'
#specifies where the upload directory is and the file type available for uploads
UPLOAD_FOLDER = 'upload'
ALLOWED_EXTENSIONS = {'.csv','.xes'}
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
#home page route
@app.route('/')
def index():
return render_template('index.html')
#the upload functionality. It then redirects to the case labeling page
@app.route('/', methods=['POST'])
def upload_file():
uploaded_file = request.files['file']
if uploaded_file.filename != '':
uploaded_file.save(os.path.join(app.config['UPLOAD_FOLDER'],uploaded_file.filename))
elif uploaded_file.filename == '':
flash('No files selected! Please select a file!')
return redirect(url_for('index'))
return redirect(url_for('case'))
#login page route. eventually will be removed
@app.route('/login.html')
def login():
return render_template('login.html')
#signup page route. eventually will be removed
@app.route('/signup.html')
def signup():
return render_template('signup.html')
#case selection page route
@app.route('/case.html')
def case():
return render_template('case.html')
#eventually to input the case ID, case ID is then sent to backend
@app.route('/case.html', methods=['POST'])
def get_caseid():
caseid = request.form['caseId']
if caseid != '':
return redirect(url_for('recommendation',id=caseid))
else:
flash('Please input a case ID!')
return redirect(url_for('case'))
#placeholder result page route. Will eventually be removed and is now defunct.
@app.route('/result.html')
def result():
return render_template('result.html')
#the actual result page route, accepts result from backend but for now it's specifically from input.py
@app.route('/result.html/<id>', methods=['GET'])
def recommendation(id):
res = input.foo(id)
return render_template('result.html',res=res)
#loading page route
@app.route('/loading.html')
def loading():
return render_template('loading.html')
#about us page route
@app.route('/aboutus.html')
def aboutus():
return render_template('aboutus.html')
if __name__ == "__main__":
port = int(os.environ.get('PORT', 5000))
app.run(debug=True, host='0.0.0.0', port=port)