-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
74 lines (53 loc) · 1.67 KB
/
application.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
__author__ = 'len'
from flask import Flask
from sys import path
from os import getcwd
path.append(getcwd() + "/keras") #Yes, i'm on windows
print(path)
import my_cifar as cf
from image.cifar_image import CifarImage
import boto3
from io import BytesIO
# EB looks for an 'application' callable by default.
application = Flask(__name__)
@application.route('/s3')
def s3():
# Let's use Amazon S3
s3 = boto3.resource('s3')
bucket = s3.Bucket('unimind-userfiles-mobilehub-1656990244')
html = ""
for obj in bucket.objects.all():
key = obj.key
# only debugging specific case now
if key == 'public/w32/1472541858.06554/87.jpeg':
body = obj.get()['Body'].read()
html += key + "<br>"
return html
@application.route('/')
def root():
# Let's use Amazon S3
s3 = boto3.resource('s3')
bucket = s3.Bucket('unimind-userfiles-mobilehub-1656990244')
cifar_imgs = []
for obj in bucket.objects.all():
key = obj.key
# only debugging specific case now
if key.startswith('public/w32/1472541858.06554/'):
body = obj.get()['Body'].read()
#
ci = CifarImage()
ci.name = key
ci.body = BytesIO(body)
cifar_imgs.append(ci)
cf.path = 'keras/'
pre_processed_imgs = cf.pre_process(cifar_imgs)
result = cf.classify(cifar_imgs, pre_processed_imgs)
# upload result to ...
return result
# run the app.
if __name__ == "__main__":
# Setting debug to True enables debug output. This line should be
# removed before deploying a production app.
# application.debug = True
# application.run()
print(root())