-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathusage.py
109 lines (92 loc) · 4.89 KB
/
usage.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
98
99
100
101
102
103
104
105
106
107
108
import dash_materialsintelligence as dmi
import dash
import dash_html_components as html
from dash.dependencies import Input, Output, State
import random
app = dash.Dash('')
app.title = "Dash - Materials Intelligence"
app.css.append_css({"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"})
app.config.suppress_callback_exceptions = True
app.scripts.config.serve_locally = True
testTokens = []
testTokens.append([[{'id': 'token-0-2', 'text': 'ab', 'start': 0, 'end': 2, 'annotation': None},
{'id': 'token-3-5', 'text': 'cd', 'start': 3, 'end': 5, 'annotation': None},
{'id': 'token-6-8', 'text': 'ef', 'start': 6, 'end': 8, 'annotation': ['label-2', 'label-1']},
{'id': 'token-8-9', 'text': '.', 'start': 8, 'end': 9, 'annotation': None},
{'id': 'token-10-12', 'text': 'gf', 'start': 10, 'end': 12, 'annotation': 'label-1'}],
[{'id': 'token-0-2', 'text': 'AB', 'start': 0, 'end': 2, 'annotation': None},
{'id': 'token-3-5', 'text': 'CD', 'start': 3, 'end': 5, 'annotation': None},
{'id': 'token-6-8', 'text': 'EF', 'start': 6, 'end': 8, 'annotation': [None, 'label-1']},
{'id': 'token-8-9', 'text': '.', 'start': 8, 'end': 9, 'annotation': 'label-4'},
{'id': 'token-10-12', 'text': 'GF', 'start': 10, 'end': 12, 'annotation': None}],
[{'id': 'token-0-2', 'text': 'AB', 'start': 0, 'end': 2, 'annotation': None},
{'id': 'token-3-5', 'text': 'CD', 'start': 3, 'end': 5, 'annotation': None},
{'id': 'token-6-8', 'text': 'EF', 'start': 6, 'end': 8, 'annotation': None},
{'id': 'token-8-9', 'text': '.', 'start': 8, 'end': 9, 'annotation': 'label-3'},
{'id': 'token-10-12', 'text': 'GF', 'start': 10, 'end': 12, 'annotation': None}]])
testTokens.append([[{'id': 'token-0-2', 'text': 'AB', 'start': 0, 'end': 2, 'annotation': None},
{'id': 'token-3-5', 'text': 'CD', 'start': 3, 'end': 5, 'annotation': None},
{'id': 'token-6-8', 'text': 'EF', 'start': 6, 'end': 8, 'annotation': None},
{'id': 'token-8-9', 'text': ',', 'start': 8, 'end': 9, 'annotation': None},
{'id': 'token-10-12', 'text': 'GF', 'start': 10, 'end': 12, 'annotation': None}],
[{'id': 'token-0-2', 'text': 'ab', 'start': 0, 'end': 2, 'annotation': None},
{'id': 'token-3-5', 'text': 'cd', 'start': 3, 'end': 5, 'annotation': None},
{'id': 'token-6-8', 'text': 'ef', 'start': 6, 'end': 8, 'annotation': None},
{'id': 'token-8-9', 'text': ',', 'start': 8, 'end': 9, 'annotation': None},
{'id': 'token-10-12', 'text': 'gf', 'start': 10, 'end': 12, 'annotation': None}],
[{'id': 'token-0-2', 'text': 'ab', 'start': 0, 'end': 2, 'annotation': None},
{'id': 'token-3-5', 'text': 'cd', 'start': 3, 'end': 5, 'annotation': None},
{'id': 'token-6-8', 'text': 'ef', 'start': 6, 'end': 8, 'annotation': None},
{'id': 'token-8-9', 'text': ',', 'start': 8, 'end': 9, 'annotation': None},
{'id': 'token-10-12', 'text': 'gf', 'start': 10, 'end': 12, 'annotation': None}]])
testLabels = [{'text': 'Material', 'value': 'label-1'},
{'text': 'Inorganic Crystal', 'value': 'label-2'},
{'text': 'Main Material', 'value': 'label-3'}]
def serve_layout(doi="none", tokens=testTokens[0]):
return html.Div([
dmi.AnnotationContainer(
doi=doi,
tokens=tokens,
labels=testLabels,
passiveLabels=[],
className="testClass",
id="annotation_container",
selectedValue=None
),
dmi.DropdownCreatable(
options=[
{'value': '', 'label': 'material:'},
{'value': '', 'label': 'property:'},
{'value': '', 'label': 'application:'}],
multi=True,
id="tags_selector",
placeholder="Add filters...",
promptText="Add filter ",
value=None,
),
html.Div("doi is " + doi, id="test_output"),
html.Div(html.Button("Confirm", id="annotate_confirm"))
])
app.layout = html.Div(serve_layout(),id="content")
"""
App Callbacks
"""
@app.callback(
Output('content', 'children'),
[Input('annotate_confirm', 'n_clicks')],
[State('annotation_container', 'tokens'),
State('tags_selector', 'value')])
def load_next_abstract(
n_clicks,
tokens,
tags):
doi="none"
if n_clicks is not None:
# do something to record the annotation
for tokenRow in tokens:
print([token["annotation"] for token in tokenRow])
doi = str(random.randint(1, 100000))
tokens = testTokens[random.randint(1, 2) - 1]
return serve_layout(doi=doi, tokens=tokens)
if __name__ == '__main__':
app.run_server(debug=True)