Spaces:
Sleeping
Sleeping
Nathan Schneider
commited on
Commit
·
966702f
1
Parent(s):
ab8be7a
linking Examples to outputs: ditch LazyObj strategy, simply use .render(). Params enabling caching.
Browse files
app.py
CHANGED
|
@@ -377,25 +377,12 @@ def classify_tokens(text: str, use_canned=False):
|
|
| 377 |
|
| 378 |
|
| 379 |
# instantiate output component proxies before layout so they can be provided to Examples component
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
self.__getattr__ = lambda self, name: self._o.__getattr__(name)
|
| 387 |
-
self.__setattr__ = lambda self, name, val: self._o.__setattr__(name, val) # type: ignore
|
| 388 |
-
def __call__(self):
|
| 389 |
-
assert self._o is None
|
| 390 |
-
self._o = self._construct()
|
| 391 |
-
return self._o
|
| 392 |
-
|
| 393 |
-
simple_output = LazyObj(lambda: gr.HighlightedText(label="Tagged Text"))
|
| 394 |
-
output1 = LazyObj(lambda: gr.HTML(label="SNACS Tagged Sentence"))
|
| 395 |
-
output2 = LazyObj(lambda: gr.HTML(label="SNACS Table with Colored Labels"))
|
| 396 |
-
output3 = LazyObj(lambda: gr.HTML(label="SNACS Tagged Sentence with No Label Aggregation"))
|
| 397 |
-
json_spans = LazyObj(lambda: gr.Code(language="json"))
|
| 398 |
-
json_tokens = LazyObj(lambda: gr.Code(language="json"))
|
| 399 |
|
| 400 |
#final rendering of the Gradio interface
|
| 401 |
with gr.Blocks(title="SNACS Tagging", css=CUSTOM_CSS) as demo:
|
|
@@ -415,20 +402,21 @@ with gr.Blocks(title="SNACS Tagging", css=CUSTOM_CSS) as demo:
|
|
| 415 |
with gr.Column():
|
| 416 |
input_text = gr.Textbox(lines=4, placeholder="Enter a sentence...", label="Input Text"),
|
| 417 |
tag_btn = gr.Button("Tag!", variant="primary")
|
| 418 |
-
examples = gr.Examples(EXAMPLES, input_text, [simple_output,json_spans,json_tokens,output1,output2,output3],
|
|
|
|
| 419 |
with gr.Column() as output:
|
| 420 |
with gr.Tab("Simple Output"):
|
| 421 |
-
|
| 422 |
with gr.Tab("Detailed Output"):
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
with gr.Tab("JSON Spans"):
|
| 427 |
-
|
| 428 |
with gr.Tab("JSON Tokens"):
|
| 429 |
-
|
| 430 |
|
| 431 |
-
tag_btn.click(fn=classify_tokens, inputs=input_text, outputs=[
|
| 432 |
|
| 433 |
|
| 434 |
demo.launch()
|
|
|
|
| 377 |
|
| 378 |
|
| 379 |
# instantiate output component proxies before layout so they can be provided to Examples component
|
| 380 |
+
simple_output = gr.HighlightedText(label="Tagged Text")
|
| 381 |
+
output1 = gr.HTML(label="SNACS Tagged Sentence")
|
| 382 |
+
output2 = gr.HTML(label="SNACS Table with Colored Labels")
|
| 383 |
+
output3 = gr.HTML(label="SNACS Tagged Sentence with No Label Aggregation")
|
| 384 |
+
json_spans = gr.Code(language="json")
|
| 385 |
+
json_tokens = gr.Code(language="json")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
|
| 387 |
#final rendering of the Gradio interface
|
| 388 |
with gr.Blocks(title="SNACS Tagging", css=CUSTOM_CSS) as demo:
|
|
|
|
| 402 |
with gr.Column():
|
| 403 |
input_text = gr.Textbox(lines=4, placeholder="Enter a sentence...", label="Input Text"),
|
| 404 |
tag_btn = gr.Button("Tag!", variant="primary")
|
| 405 |
+
examples = gr.Examples(EXAMPLES, input_text, [simple_output,json_spans,json_tokens,output1,output2,output3], # type: ignore
|
| 406 |
+
fn=classify_tokens, cache_examples=True, cache_mode="lazy", example_labels=EXAMPLE_LABELS)
|
| 407 |
with gr.Column() as output:
|
| 408 |
with gr.Tab("Simple Output"):
|
| 409 |
+
simple_output.render()
|
| 410 |
with gr.Tab("Detailed Output"):
|
| 411 |
+
output1.render()
|
| 412 |
+
output2.render()
|
| 413 |
+
output3.render()
|
| 414 |
with gr.Tab("JSON Spans"):
|
| 415 |
+
json_spans.render()
|
| 416 |
with gr.Tab("JSON Tokens"):
|
| 417 |
+
json_tokens.render()
|
| 418 |
|
| 419 |
+
tag_btn.click(fn=classify_tokens, inputs=input_text, outputs=[simple_output,json_spans,json_tokens,output1,output2,output3])
|
| 420 |
|
| 421 |
|
| 422 |
demo.launch()
|