-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcallbacks.py
31 lines (25 loc) · 960 Bytes
/
callbacks.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
import dash
import dash_html_components as html
from app import app
from dash.dependencies import Input, Output, State
from api import get_meme
@app.callback(Output('filename', 'children'),
[Input('upload-image', 'contents')],
[State('upload-image', 'filename')])
def show_filename(c, f):
if c is not None:
return html.H5("File uploaded: " + f)
@app.callback(Output('output-image-upload', 'children'),
[Input('submit-button', 'n_clicks')],
[State('upload-image', 'contents'),
State('meme-text', 'value')])
def update_output(n, c, t):
if c is not None:
children = [parse_contents(c, t.upper())]
return children
def parse_contents(contents, text):
return html.Div([
# HTML images accept base64 encoded strings in the same format
# that is supplied by the upload
html.Img(src=get_meme(contents, text)),
], id="image-holder")