-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
90 lines (73 loc) · 2.95 KB
/
main.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
85
86
87
88
89
90
# -*- coding: utf-8 -*-
"""
Valerie DESNOUX
8 avril 2021
Testing flask script file.
"""
from flask import Flask, request, redirect, send_from_directory, Response
from werkzeug.utils import secure_filename
import os
from flask import render_template
import Solex_recon_flask as sol
UPLOAD_FOLDER='static/myupload'
app = Flask(__name__)
ALLOWED_EXTENSIONS = {'ser'}
app.config['UPLOAD_FOLDER']=UPLOAD_FOLDER
app.secret_key = 'QRVulHD192685'
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/result/<basefich>')
def results(basefich):
#basefich=session['basefich']
print('result :', basefich)
basefich2=basefich
myfichtxt=os.path.join(app.config['UPLOAD_FOLDER'],basefich+'.txt')
basefich='/'+os.path.join(app.config['UPLOAD_FOLDER'], basefich)
list_files=[]
list_files2=[]
list_files.append(basefich+'_recon.fits')
list_files.append(basefich+'_img.fits')
list_files.append(basefich+'_mean.fits')
list_files.append(basefich+'.txt')
list_files2.append(basefich2+'_recon.fits')
list_files2.append(basefich2+'_img.fits')
list_files2.append(basefich2+'_mean.fits')
list_files2.append(basefich2+'.txt')
myimage=basefich+'_disk.png'
with open(myfichtxt, "r") as txtf:
log_txt=txtf.read().split(';')
return render_template('result.html', base=basefich2+'.ser', log=log_txt,name=list_files, name2=list_files2, img=myimage)
@app.route('/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
@app.route('/',methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
print(request.method)
print (request.files)
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit an empty part without filename
print (file)
if file.filename == '':
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
serfile=os.path.join(app.config['UPLOAD_FOLDER'], filename)
#basefich=os.path.splitext(serfile)[0]
#print ('upload ',basefich)
#session['basefich']=basefich
def inner():
sol.solex_proc_all(serfile, filename)
return Response(sol.solex_proc_all(serfile, filename), mimetype='text/html')
#return render_template('yield_results.html', base=filename)
#return render_template('yield_results.html', base=filename, name=list_files, img=myimage)
return render_template('upload.html')
if __name__== "__main__":
app.run(debug=True)
#app.run (host='192.168.1.27')