minor caption changes
Browse files
app.py
CHANGED
@@ -11,6 +11,9 @@ from pytorch_ie.documents import TextDocumentWithLabeledSpansBinaryRelationsAndL
|
|
11 |
from pytorch_ie.models import * # noqa: F403
|
12 |
from pytorch_ie.taskmodules import * # noqa: F403
|
13 |
|
|
|
|
|
|
|
14 |
|
15 |
def render_pretty_table(
|
16 |
document: TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions, **render_kwargs
|
@@ -130,18 +133,18 @@ def predict(text: str) -> Tuple[dict, str]:
|
|
130 |
return document_dict, json.dumps(document_dict)
|
131 |
|
132 |
|
133 |
-
def render(document_txt: str,
|
134 |
document_dict = json.loads(document_txt)
|
135 |
document = TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions.fromdict(
|
136 |
document_dict
|
137 |
)
|
138 |
render_kwargs = json.loads(render_kwargs_json)
|
139 |
-
if
|
140 |
html = render_pretty_table(document, **render_kwargs)
|
141 |
-
elif
|
142 |
html = render_spacy(document, **render_kwargs)
|
143 |
else:
|
144 |
-
raise ValueError(f"Unknown
|
145 |
|
146 |
return html
|
147 |
|
@@ -216,9 +219,9 @@ if __name__ == "__main__":
|
|
216 |
|
217 |
with gr.Accordion("Render Options", open=False):
|
218 |
render_as = gr.Dropdown(
|
219 |
-
label="Render
|
220 |
-
choices=[
|
221 |
-
value=
|
222 |
)
|
223 |
render_kwargs = gr.Textbox(
|
224 |
label="Render Arguments",
|
|
|
11 |
from pytorch_ie.models import * # noqa: F403
|
12 |
from pytorch_ie.taskmodules import * # noqa: F403
|
13 |
|
14 |
+
RENDER_WITH_DISPLACY = "displaCy + highlighted arguments"
|
15 |
+
RENDER_WITH_PRETTY_TABLE = "Pretty Table"
|
16 |
+
|
17 |
|
18 |
def render_pretty_table(
|
19 |
document: TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions, **render_kwargs
|
|
|
133 |
return document_dict, json.dumps(document_dict)
|
134 |
|
135 |
|
136 |
+
def render(document_txt: str, render_with: str, render_kwargs_json: str) -> str:
|
137 |
document_dict = json.loads(document_txt)
|
138 |
document = TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions.fromdict(
|
139 |
document_dict
|
140 |
)
|
141 |
render_kwargs = json.loads(render_kwargs_json)
|
142 |
+
if render_with == RENDER_WITH_PRETTY_TABLE:
|
143 |
html = render_pretty_table(document, **render_kwargs)
|
144 |
+
elif render_with == RENDER_WITH_DISPLACY:
|
145 |
html = render_spacy(document, **render_kwargs)
|
146 |
else:
|
147 |
+
raise ValueError(f"Unknown render_with value: {render_with}")
|
148 |
|
149 |
return html
|
150 |
|
|
|
219 |
|
220 |
with gr.Accordion("Render Options", open=False):
|
221 |
render_as = gr.Dropdown(
|
222 |
+
label="Render with",
|
223 |
+
choices=[RENDER_WITH_PRETTY_TABLE, RENDER_WITH_DISPLACY],
|
224 |
+
value=RENDER_WITH_DISPLACY,
|
225 |
)
|
226 |
render_kwargs = gr.Textbox(
|
227 |
label="Render Arguments",
|