ArneBinder
commited on
Commit
•
5003662
1
Parent(s):
bfcba2d
Upload 5 files
Browse files- __init__.py +5 -0
- app.py +3 -5
- rendering_utils.py +3 -5
- requirements.txt +0 -1
__init__.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
|
4 |
+
# add current folder to the python path
|
5 |
+
sys.path.append(os.path.dirname(__file__))
|
app.py
CHANGED
@@ -9,8 +9,7 @@ from pytorch_ie.auto import AutoPipeline
|
|
9 |
from pytorch_ie.documents import TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
10 |
from pytorch_ie.models import * # noqa: F403
|
11 |
from pytorch_ie.taskmodules import * # noqa: F403
|
12 |
-
|
13 |
-
from rendering_utils import render_pretty_table, render_spacy
|
14 |
|
15 |
RENDER_WITH_DISPLACY = "displaCy + highlighted arguments"
|
16 |
RENDER_WITH_PRETTY_TABLE = "Pretty Table"
|
@@ -38,7 +37,7 @@ def render(document_txt: str, render_with: str, render_kwargs_json: str) -> str:
|
|
38 |
if render_with == RENDER_WITH_PRETTY_TABLE:
|
39 |
html = render_pretty_table(document, **render_kwargs)
|
40 |
elif render_with == RENDER_WITH_DISPLACY:
|
41 |
-
html =
|
42 |
else:
|
43 |
raise ValueError(f"Unknown render_with value: {render_with}")
|
44 |
|
@@ -70,8 +69,7 @@ if __name__ == "__main__":
|
|
70 |
)
|
71 |
|
72 |
default_render_kwargs = {
|
73 |
-
"
|
74 |
-
"options": {
|
75 |
# we need to convert the keys to uppercase because the spacy rendering function expects them in uppercase
|
76 |
"colors": {
|
77 |
"own_claim".upper(): "#009933",
|
|
|
9 |
from pytorch_ie.documents import TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
10 |
from pytorch_ie.models import * # noqa: F403
|
11 |
from pytorch_ie.taskmodules import * # noqa: F403
|
12 |
+
from rendering_utils import render_displacy, render_pretty_table
|
|
|
13 |
|
14 |
RENDER_WITH_DISPLACY = "displaCy + highlighted arguments"
|
15 |
RENDER_WITH_PRETTY_TABLE = "Pretty Table"
|
|
|
37 |
if render_with == RENDER_WITH_PRETTY_TABLE:
|
38 |
html = render_pretty_table(document, **render_kwargs)
|
39 |
elif render_with == RENDER_WITH_DISPLACY:
|
40 |
+
html = render_displacy(document, **render_kwargs)
|
41 |
else:
|
42 |
raise ValueError(f"Unknown render_with value: {render_with}")
|
43 |
|
|
|
69 |
)
|
70 |
|
71 |
default_render_kwargs = {
|
72 |
+
"entity_options": {
|
|
|
73 |
# we need to convert the keys to uppercase because the spacy rendering function expects them in uppercase
|
74 |
"colors": {
|
75 |
"own_claim".upper(): "#009933",
|
rendering_utils.py
CHANGED
@@ -4,7 +4,6 @@ from typing import Dict, List, Optional, Union
|
|
4 |
|
5 |
from pytorch_ie.annotations import BinaryRelation
|
6 |
from pytorch_ie.documents import TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
7 |
-
|
8 |
from rendering_utils_displacy import EntityRenderer
|
9 |
|
10 |
|
@@ -25,12 +24,11 @@ def render_pretty_table(
|
|
25 |
return html
|
26 |
|
27 |
|
28 |
-
def
|
29 |
document: TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions,
|
30 |
-
style="ent",
|
31 |
inject_relations=True,
|
32 |
colors_hover=None,
|
33 |
-
|
34 |
**render_kwargs,
|
35 |
):
|
36 |
|
@@ -43,7 +41,7 @@ def render_spacy(
|
|
43 |
"title": None,
|
44 |
}
|
45 |
|
46 |
-
renderer = EntityRenderer(options=
|
47 |
html = renderer.render([spacy_doc], page=True, minify=True).strip()
|
48 |
|
49 |
html = "<div style='max-width:100%; max-height:360px; overflow:auto'>" + html + "</div>"
|
|
|
4 |
|
5 |
from pytorch_ie.annotations import BinaryRelation
|
6 |
from pytorch_ie.documents import TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions
|
|
|
7 |
from rendering_utils_displacy import EntityRenderer
|
8 |
|
9 |
|
|
|
24 |
return html
|
25 |
|
26 |
|
27 |
+
def render_displacy(
|
28 |
document: TextDocumentWithLabeledSpansBinaryRelationsAndLabeledPartitions,
|
|
|
29 |
inject_relations=True,
|
30 |
colors_hover=None,
|
31 |
+
entity_options={},
|
32 |
**render_kwargs,
|
33 |
):
|
34 |
|
|
|
41 |
"title": None,
|
42 |
}
|
43 |
|
44 |
+
renderer = EntityRenderer(options=entity_options)
|
45 |
html = renderer.render([spacy_doc], page=True, minify=True).strip()
|
46 |
|
47 |
html = "<div style='max-width:100%; max-height:360px; overflow:auto'>" + html + "</div>"
|
requirements.txt
CHANGED
@@ -2,5 +2,4 @@ transformers==4.36.0
|
|
2 |
gradio
|
3 |
prettytable==3.10.0
|
4 |
pie-modules>=0.10.9,<0.11.0
|
5 |
-
spacy==2.3.9
|
6 |
beautifulsoup4==4.12.3
|
|
|
2 |
gradio
|
3 |
prettytable==3.10.0
|
4 |
pie-modules>=0.10.9,<0.11.0
|
|
|
5 |
beautifulsoup4==4.12.3
|