-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
84 lines (71 loc) · 2.75 KB
/
run.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
76
77
78
79
80
81
82
83
84
import os
from flask import Flask, render_template, redirect, url_for, request, flash
from werkzeug.utils import secure_filename
from plugins import *
UPLOAD_FOLDER = 'templates/uploads'
ALLOWED_EXTENSIONS = set(['txt'])
app = Flask(__name__, static_folder='templates/static')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
# @app.route('/')
# def welcome():
# return redirect('/login')
@app.route('/upfile', methods=['GET', 'POST'])
def upload_file():
error = None
if request.method == 'POST':
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
# os.remove('templates/img/res.png')
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
filepath = app.config['UPLOAD_FOLDER'] + '/' + filename
upload_res = []
FULL_SET.clear()
with open(filepath, 'r') as f:
for line in f.readlines():
temp_list_attr = line.split('\t')
FULL_SET.append(Human(
temp_list_attr[0],
int(temp_list_attr[2]),
int(temp_list_attr[3]),
temp_list_attr[1].strip()
).get_fuzzy_info())
f.close()
upload_res = boosting2('a').values()
shape, num = getIndex(upload_res)
os.remove(filepath)
return render_template('res.html', error=error, shape=shape, num_res=num)
return redirect(url_for('/'))
@app.route('/check', methods=['POST'])
def check():
if request.method == 'POST':
h = request.form['height']
w = request.form['weight']
g = request.form['gender']
hum = Human("a", int(h), int(w), g)
create_training_data()
FULL_SET.append(hum.get_fuzzy_info())
res = boosting()
return res
return redirect(url_for('/'))
# Route for handling the login page logic
@app.route('/', methods=['GET'])
def index():
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or request.form['password'] != 'admin':
error = 'Invalid Credentials. Please try again.'
else:
return redirect(url_for('home'))
return render_template('index.html', error=error)
if __name__ == '__main__':
app.run(host='localhost', port=5000, debug=True)