-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·63 lines (50 loc) · 1.75 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
import os
from flask import Flask, render_template, request
import DGS
import random
import StringIO
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
app = Flask(__name__)
UPLOAD_FOLDER = os.path.basename('static')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def hello_world():
return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload_file():
file = request.files['image']
f = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
# add your custom code to check that the uploaded file is a valid image and not a malicious file (out-of-scope for this post)
file.save(f)
image='./static/'+file.filename
print image
resolution =request.form['resolution']
density = request.form['density']
dofilter=request.form['dofilter']
maxscale=request.form['maxscale']
mag=int(request.form['mag_he'])
print request.form['mag_he']
notes=request.form['notes']
ans = DGS.dgs(image, density, resolution, dofilter, maxscale, notes,1)
print ans
means=ans['mean grain size']*mag
kuto = ans['grain size kurtosis']
stdev = ans['grain size skewness']*mag
y=ans['grain size frequencies']
x=ans['grain size bins']*mag
for num in range(len(y)):
y[num] *= 100
for num in range(len(x)):
x[num] *= mag
print x
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(x,y,align='center',width=means)
ax.set_xlabel('Grain Size (mm)')
ax.set_ylabel('Grain Size Frequency' )
fig.savefig('./static/test.png')
bar_chart= './static/test.png'
return render_template('output.html',means=means,image=image,stdev=stdev,kuto=kuto,bar_chart=bar_chart)
app.run(host='0.0.0.0',debug=False)