Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -26,14 +26,9 @@ model = AutoModelForTokenClassification.from_pretrained("SickBoy/layoutlm_docume
|
|
26 |
|
27 |
# load image example
|
28 |
dataset = load_dataset("SickBoy/layout_documents", split="train")
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
boxes = example["bboxes"]
|
33 |
-
labels = example["ner_tags"]
|
34 |
-
#Image.open(dataset[2]["image_path"]).convert("RGB").save("example1.png")
|
35 |
-
#Image.open(dataset[1]["image_path"]).convert("RGB").save("example2.png")
|
36 |
-
#Image.open(dataset[0]["image_path"]).convert("RGB").save("example3.png")
|
37 |
# define id2label, label2color
|
38 |
#labels = dataset.features['ner_tags'].feature.names
|
39 |
labels = ['O', 'HEADER', 'SUBHEADER', 'TEXTO', 'NUMERAL', 'RESUMEN']
|
@@ -81,9 +76,9 @@ def process_image(image):
|
|
81 |
width, height = image.size
|
82 |
|
83 |
# encode
|
84 |
-
#encoding = processor(
|
85 |
-
encoding = processor(
|
86 |
-
|
87 |
|
88 |
# forward pass
|
89 |
outputs = model(**encoding)
|
@@ -113,7 +108,7 @@ description = "Invoice Information Extraction - We use Microsoft's LayoutLMv3 tr
|
|
113 |
|
114 |
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>"
|
115 |
|
116 |
-
|
117 |
|
118 |
css = """.output_image, .input_image {height: 600px !important}"""
|
119 |
|
@@ -123,7 +118,7 @@ iface = gr.Interface(fn=process_image,
|
|
123 |
title=title,
|
124 |
description=description,
|
125 |
article=article,
|
126 |
-
|
127 |
css=css,
|
128 |
analytics_enabled = True, enable_queue=True)
|
129 |
|
|
|
26 |
|
27 |
# load image example
|
28 |
dataset = load_dataset("SickBoy/layout_documents", split="train")
|
29 |
+
Image.open(dataset[2]["image_path"]).convert("RGB").save("example1.png")
|
30 |
+
Image.open(dataset[1]["image_path"]).convert("RGB").save("example2.png")
|
31 |
+
Image.open(dataset[0]["image_path"]).convert("RGB").save("example3.png")
|
|
|
|
|
|
|
|
|
|
|
32 |
# define id2label, label2color
|
33 |
#labels = dataset.features['ner_tags'].feature.names
|
34 |
labels = ['O', 'HEADER', 'SUBHEADER', 'TEXTO', 'NUMERAL', 'RESUMEN']
|
|
|
76 |
width, height = image.size
|
77 |
|
78 |
# encode
|
79 |
+
#encoding = processor(image1, words, boxes=boxes, word_labels=word_labels, return_tensors="pt")
|
80 |
+
encoding = processor(image, truncation=True, return_offsets_mapping=True, return_tensors="pt")
|
81 |
+
offset_mapping = encoding.pop('offset_mapping')
|
82 |
|
83 |
# forward pass
|
84 |
outputs = model(**encoding)
|
|
|
108 |
|
109 |
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>"
|
110 |
|
111 |
+
examples =[['example1.png'],['example2.png'],['example3.png']]
|
112 |
|
113 |
css = """.output_image, .input_image {height: 600px !important}"""
|
114 |
|
|
|
118 |
title=title,
|
119 |
description=description,
|
120 |
article=article,
|
121 |
+
examples=examples,
|
122 |
css=css,
|
123 |
analytics_enabled = True, enable_queue=True)
|
124 |
|