Spaces:
Runtime error
Runtime error
Image mods
Browse files
app.py
CHANGED
@@ -23,7 +23,6 @@ model = LayoutLMv3ForTokenClassification.from_pretrained("nielsr/layoutlmv3-fine
|
|
23 |
dataset = load_dataset("nielsr/cord-layoutlmv3", split="test")
|
24 |
#image = Image.open(dataset[0]["image_path"]).convert("RGB")
|
25 |
image = Image.open("./test0.jpeg")
|
26 |
-
#image.save("document.png")
|
27 |
# define id2label, label2color
|
28 |
labels = dataset.features['ner_tags'].feature.names
|
29 |
id2label = {v: k for v, k in enumerate(labels)}
|
@@ -35,8 +34,6 @@ label2color = {}
|
|
35 |
for k,v in id2label.items():
|
36 |
label2color[v[2:]]=label_color[k]
|
37 |
|
38 |
-
#label2color = {'question':'blue', 'answer':'green', 'header':'orange', 'other':'violet'}
|
39 |
-
|
40 |
def unnormalize_box(bbox, width, height):
|
41 |
return [
|
42 |
width * (bbox[0] / 1000),
|
@@ -75,8 +72,6 @@ def process_image(image):
|
|
75 |
font = ImageFont.load_default()
|
76 |
for prediction, box in zip(true_predictions, true_boxes):
|
77 |
predicted_label = iob_to_label(prediction) #.lower()
|
78 |
-
#print (predicted_label)
|
79 |
-
#print (label2color[predicted_label])
|
80 |
draw.rectangle(box, outline=label2color[predicted_label])
|
81 |
draw.text((box[0]+10, box[1]-10), text=predicted_label, fill=label2color[predicted_label], font=font)
|
82 |
|
@@ -84,13 +79,14 @@ def process_image(image):
|
|
84 |
|
85 |
|
86 |
title = "Interactive demo: LayoutLMv3"
|
87 |
-
description = "Demo for Microsoft's LayoutLMv3, a Transformer for state-of-the-art document image understanding tasks. This particular model is fine-tuned on CORD, a dataset of
|
88 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2204.08387' target='_blank'>LayoutLMv3: Multi-modal Pre-training for Visually-Rich Document Understanding</a> | <a href='https://github.com/microsoft/unilm' target='_blank'>Github Repo</a></p>"
|
89 |
examples =[['test0.jpeg'],['./test1.jpeg'],['test2.jpeg']]
|
90 |
|
91 |
-
css = ".output-image, .input-image
|
|
|
92 |
#css = "@media screen and (max-width: 600px) { .output_image, .input_image {height:20rem !important; width: 100% !important;} }"
|
93 |
-
|
94 |
|
95 |
css = ".image-preview {height: auto !important;}"
|
96 |
|
|
|
23 |
dataset = load_dataset("nielsr/cord-layoutlmv3", split="test")
|
24 |
#image = Image.open(dataset[0]["image_path"]).convert("RGB")
|
25 |
image = Image.open("./test0.jpeg")
|
|
|
26 |
# define id2label, label2color
|
27 |
labels = dataset.features['ner_tags'].feature.names
|
28 |
id2label = {v: k for v, k in enumerate(labels)}
|
|
|
34 |
for k,v in id2label.items():
|
35 |
label2color[v[2:]]=label_color[k]
|
36 |
|
|
|
|
|
37 |
def unnormalize_box(bbox, width, height):
|
38 |
return [
|
39 |
width * (bbox[0] / 1000),
|
|
|
72 |
font = ImageFont.load_default()
|
73 |
for prediction, box in zip(true_predictions, true_boxes):
|
74 |
predicted_label = iob_to_label(prediction) #.lower()
|
|
|
|
|
75 |
draw.rectangle(box, outline=label2color[predicted_label])
|
76 |
draw.text((box[0]+10, box[1]-10), text=predicted_label, fill=label2color[predicted_label], font=font)
|
77 |
|
|
|
79 |
|
80 |
|
81 |
title = "Interactive demo: LayoutLMv3"
|
82 |
+
description = "Demo for Microsoft's LayoutLMv3, a Transformer for state-of-the-art document image understanding tasks. This particular model is fine-tuned on CORD, a dataset of receipts. It annotates the words appearing in the image as ***. To use it, simply upload an image or use the example image below and click 'Submit'. Results will show up in a few seconds. If you want to make the output bigger, right-click on it and select 'Open image in new tab'."
|
83 |
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2204.08387' target='_blank'>LayoutLMv3: Multi-modal Pre-training for Visually-Rich Document Understanding</a> | <a href='https://github.com/microsoft/unilm' target='_blank'>Github Repo</a></p>"
|
84 |
examples =[['test0.jpeg'],['./test1.jpeg'],['test2.jpeg']]
|
85 |
|
86 |
+
css = ".output-image, .input-image"
|
87 |
+
#css = ".output-image, .input-image {height: 40rem !important; width: 100% !important;}"
|
88 |
#css = "@media screen and (max-width: 600px) { .output_image, .input_image {height:20rem !important; width: 100% !important;} }"
|
89 |
+
#$css = ".output_image, .input_image {height: 600px !important}"
|
90 |
|
91 |
css = ".image-preview {height: auto !important;}"
|
92 |
|