-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
42 lines (33 loc) · 1.13 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
from flask import Flask, render_template, request
from werkzeug.utils import secure_filename
import os
from pdf import read_liver_pdf
from body_models import model_liver
clf = model_liver()
UPLOAD_FOLDER = os.getcwd()
ALLOWED_EXTENSIONS = set(['pdf'])
template_dir = os.getcwd()+'/docs/'
app = Flask(__name__, template_folder=template_dir,static_folder="docs")
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/',methods = ['GET','POST'])
def index():
if request.method == "GET":
return render_template('index.html')
if request.method == "POST":
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
path = os.path.join(app.config['UPLOAD_FOLDER'])
try:
c ,dic = read_liver_pdf(path, file.filename)
os.remove('lft.pdf')
result = str(clf.predict(c)[0])
return render_template('result.html',flag = result, dic = dic)
except Exception as e:
return str(e)
return request.form['firstname']
if __name__=='__main__':
app.run(debug=True)