-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
97 lines (85 loc) · 3.06 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import base64
import datetime
import io
import dash
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import requests
import io
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css', dbc.themes.BOOTSTRAP]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.layout = html.Div([
dbc.Jumbotron([
html.Div([
html.H1("Image Classifier", className="jumbotron-heading justify-content-center"),
], className="text-center")
], className="mt-4"),
dbc.Row([
dbc.Col([
html.Div([
dcc.Upload(
id='upload-data',
children=html.Div([
'Drag and Drop or ',
html.A('Select File (JPG)')
]),
style={
'width': '100%',
'height': '100px',
'lineHeight': '100px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '5px',
'textAlign': 'center',
'font-size': '17px'
# 'margin': '10px'
},
# Allow multiple files to be uploaded
multiple=False
),
])
])
]),
dbc.Row([
dbc.Col([
html.Div(id='output-data-upload', className="d-flex justify-content-center mt-4")
]),
dbc.Col([
html.Div(id='output-data-result', className="d-flex justify-content-center mt-4")
])
])
], className="container")
@app.callback(Output('output-data-upload', 'children'),
Output('output-data-result', 'children'),
Input('upload-data', 'contents'),
State('upload-data', 'filename'),
State('upload-data', 'last_modified'))
def update_output(list_of_contents, list_of_names, list_of_dates):
print("In: update output", flush=True)
# for content in list_of_contents:
# print(list_of_contents)
image_html = []
url = 'https://torch-serve-stackn-demo-cyb-60d7.studio-dev.local.stackn.dev/predictions/vgg11_scripted'
pred_res = ""
try:
content_type, content_string = list_of_contents.split(',')
print(content_type)
contentb64_decode = base64.b64decode(content_string)
file_obj = io.BytesIO(contentb64_decode)
try:
res = requests.put(url, data=file_obj)
except Exception as e:
print(e)
print(res.text)
image_html = html.Img(src='data:image/png;base64,{}'.format(content_string), width="90%")
pred_res = html.Pre([res.text], style={'font-size': '20px'})
except Exception as err:
print("No image.")
print(err)
return image_html, pred_res
if __name__ == '__main__':
app.run_server(debug=True)