-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.py
77 lines (55 loc) · 2.29 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
76
77
import os
from flask import Flask, flash, request, redirect, render_template
from werkzeug.utils import secure_filename
import subprocess
app=Flask(__name__)
app.secret_key = "secret key"
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 * 1024 * 1024
# Get current path
path = os.getcwd()
# file Upload
UPLOAD_FOLDER = "/home/input"
# os.path.join(path, 'uploads')
# Make directory if uploads is not exists
# if not os.path.isdir(UPLOAD_FOLDER):
# os.mkdir(UPLOAD_FOLDER)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Allowed extension you can set your own
ALLOWED_EXTENSIONS = set(['dcm', 'nii.gz', 'dicom', 'jpg', 'jpeg', 'gif'])
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/test')
def upload_form():
return render_template('upload.html')
@app.route('/')
def home():
message = "Kidney and Kidney Tumor Segmentation Challenge." +" Segmentation targets kidney and kidney tumors," +"Input modalities are 0: abdominal CT scan. \n"
return message
@app.route('/test', methods=['POST'])
def upload():
if request.method == 'POST':
if 'files[]' not in request.files:
flash('No file part')
return redirect(request.url)
files = request.files.getlist('files[]')
for file in files:
filename = secure_filename(file.filename)
print(filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# if file and allowed_file(file.filename):
# filename = secure_filename(file.filename)
# file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# flash('File(s) successfully uploaded')
# session = Popen(['./some.sh'], stdout=PIPE, stderr=PIPE)
print(app.config['UPLOAD_FOLDER'])
my = os.listdir(app.config['UPLOAD_FOLDER'])
print("input dir = ",my)
# subprocess.check_output("/home/predict.sh", shell=True)
return redirect('/test')
@app.route('/prediction', methods=['POST'])
def prediction():
if request.method == 'POST':
subprocess.check_output("/home/predict.sh", shell=True)
return redirect('/test')
if __name__ == "__main__":
app.run(host='0.0.0.0',port=5000,debug=False,threaded=True)