-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (33 loc) · 1.19 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
import urllib.request
import os
import shutil
import tempfile
import assessment_service
from flask import Flask, request, render_template
index_path = 'index.html'
TEMP_DIRIMAGE_TO_ANALYZE = tempdir = tempfile.mkdtemp()
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return render_template(index_path)
@app.route("/", methods=["POST"])
def process_image():
uploadurl = request.form['url']
filename = uploadurl[uploadurl.rfind("/") + 1:]
save_image(filename, uploadurl)
assessment = assessment_service.assess(TEMP_DIRIMAGE_TO_ANALYZE, filename)
# analyze
result = Response(filename, uploadurl, assessment)
return render_template(index_path, results=[result])
def save_image(filename, uploadurl):
shutil.rmtree(TEMP_DIRIMAGE_TO_ANALYZE)
os.makedirs(TEMP_DIRIMAGE_TO_ANALYZE)
imagepath = os.path.join(TEMP_DIRIMAGE_TO_ANALYZE, filename)
urllib.request.urlretrieve(uploadurl, imagepath)
class Response:
def __init__(self, imagename, imageurl, chance):
self.imagename = imagename
self.imageurl = imageurl
self.chance = chance
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(8080), debug=False)