Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -52,28 +52,35 @@ processor = LayoutLMv3Processor.from_pretrained("microsoft/layoutlmv3-base",appl
|
|
52 |
model = LayoutLMv3ForTokenClassification.from_pretrained("nielsr/layoutlmv3-finetuned-funsd")
|
53 |
|
54 |
dataset = load_dataset("nielsr/funsd", split="test")
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
|
61 |
#dataset = load_dataset("nielsr/funsd-layoutlmv3")
|
62 |
|
63 |
-
example = dataset["test"][0]
|
64 |
-
example["image"].save("example1.png")
|
65 |
|
66 |
-
example1 = dataset["test"][1]
|
67 |
-
example1["image"].save("example2.png")
|
68 |
|
69 |
-
example2 = dataset["test"][2]
|
70 |
-
example2["image"].save("example3.png")
|
71 |
|
72 |
#example2["image"]
|
73 |
|
74 |
-
labels = dataset
|
75 |
|
76 |
-
words, boxes, ner_tags = example["tokens"], example["bboxes"], example["ner_tags"]
|
77 |
|
78 |
features = dataset["test"].features
|
79 |
|
@@ -86,7 +93,7 @@ label_column_name = "ner_tags"
|
|
86 |
|
87 |
# In the event the labels are not a `Sequence[ClassLabel]`, we will need to go through the dataset to get the
|
88 |
# unique labels.
|
89 |
-
|
90 |
id2label = {v: k for v, k in enumerate(labels)}
|
91 |
|
92 |
label2color = {
|
@@ -150,7 +157,7 @@ description = "Extraction of Form or Invoice Extraction - We use Microsoft's Lay
|
|
150 |
|
151 |
article="<b>References</b><br>[1] Y. Xu et al., “LayoutLMv3: Pre-training for Document AI with Unified Text and Image Masking.” 2022. <a href='https://arxiv.org/abs/2204.08387'>Paper Link</a><br>[2] <a href='https://github.com/NielsRogge/Transformers-Tutorials/tree/master/LayoutLMv3'>LayoutLMv3 training and inference</a>"
|
152 |
|
153 |
-
examples =[['
|
154 |
|
155 |
css = """.output_image, .input_image {height: 600px !important}"""
|
156 |
|
|
|
52 |
model = LayoutLMv3ForTokenClassification.from_pretrained("nielsr/layoutlmv3-finetuned-funsd")
|
53 |
|
54 |
dataset = load_dataset("nielsr/funsd", split="test")
|
55 |
+
image = Image.open(dataset[0]["image_path"]).convert("RGB")
|
56 |
+
image = Image.open("./invoice.png")
|
57 |
+
image.save("document1.png")
|
58 |
|
59 |
+
image = Image.open(dataset[1]["image_path"]).convert("RGB")
|
60 |
+
image = Image.open("./invoice2.png")
|
61 |
+
image.save("document2.png")
|
62 |
+
|
63 |
+
image = Image.open(dataset[2]["image_path"]).convert("RGB")
|
64 |
+
image = Image.open("./invoice3.png")
|
65 |
+
image.save("document3.png")
|
66 |
|
67 |
|
68 |
#dataset = load_dataset("nielsr/funsd-layoutlmv3")
|
69 |
|
70 |
+
#example = dataset["test"][0]
|
71 |
+
#example["image"].save("example1.png")
|
72 |
|
73 |
+
#example1 = dataset["test"][1]
|
74 |
+
#example1["image"].save("example2.png")
|
75 |
|
76 |
+
#example2 = dataset["test"][2]
|
77 |
+
#example2["image"].save("example3.png")
|
78 |
|
79 |
#example2["image"]
|
80 |
|
81 |
+
labels = dataset.features['ner_tags'].feature.names
|
82 |
|
83 |
+
#words, boxes, ner_tags = example["tokens"], example["bboxes"], example["ner_tags"]
|
84 |
|
85 |
features = dataset["test"].features
|
86 |
|
|
|
93 |
|
94 |
# In the event the labels are not a `Sequence[ClassLabel]`, we will need to go through the dataset to get the
|
95 |
# unique labels.
|
96 |
+
|
97 |
id2label = {v: k for v, k in enumerate(labels)}
|
98 |
|
99 |
label2color = {
|
|
|
157 |
|
158 |
article="<b>References</b><br>[1] Y. Xu et al., “LayoutLMv3: Pre-training for Document AI with Unified Text and Image Masking.” 2022. <a href='https://arxiv.org/abs/2204.08387'>Paper Link</a><br>[2] <a href='https://github.com/NielsRogge/Transformers-Tutorials/tree/master/LayoutLMv3'>LayoutLMv3 training and inference</a>"
|
159 |
|
160 |
+
examples =[['document1.png'],['document1.png'],['document1.png']]
|
161 |
|
162 |
css = """.output_image, .input_image {height: 600px !important}"""
|
163 |
|