Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,7 +51,14 @@ processor = LayoutLMv3Processor.from_pretrained("microsoft/layoutlmv3-base",appl
|
|
| 51 |
|
| 52 |
model = LayoutLMv3ForTokenClassification.from_pretrained("nielsr/layoutlmv3-finetuned-funsd")
|
| 53 |
|
| 54 |
-
dataset = load_dataset("nielsr/funsd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
example = dataset["test"][0]
|
| 57 |
example["image"].save("example1.png")
|
|
@@ -106,7 +113,7 @@ def get_label_list(labels):
|
|
| 106 |
label_list.sort()
|
| 107 |
return label_list
|
| 108 |
|
| 109 |
-
label2color = {'question':'blue', 'answer':'green', 'header':'orange', 'other':'violet'}
|
| 110 |
|
| 111 |
def unnormalize_box(bbox, width, height):
|
| 112 |
return [
|
|
@@ -116,14 +123,11 @@ def unnormalize_box(bbox, width, height):
|
|
| 116 |
height * (bbox[3] / 1000),
|
| 117 |
]
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
'bbox': Array2D(dtype="int64", shape=(512, 4)),
|
| 125 |
-
'labels': Sequence(feature=Value(dtype='int64')),
|
| 126 |
-
})
|
| 127 |
|
| 128 |
def process_image(image):
|
| 129 |
width, height = image.size
|
|
@@ -148,12 +152,6 @@ def process_image(image):
|
|
| 148 |
draw = ImageDraw.Draw(image)
|
| 149 |
font = ImageFont.load_default()
|
| 150 |
|
| 151 |
-
def iob_to_label(labels):
|
| 152 |
-
labels= labels[2:]
|
| 153 |
-
if not labels:
|
| 154 |
-
return 'other'
|
| 155 |
-
return labels
|
| 156 |
-
|
| 157 |
label2color = {'question':'blue', 'answer':'green', 'header':'orange', 'other':'violet'}
|
| 158 |
for prediction, box in zip(true_predictions, true_boxes):
|
| 159 |
predicted_label = iob_to_label(prediction) #.lower()
|
|
|
|
| 51 |
|
| 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("document.png")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
#dataset = load_dataset("nielsr/funsd-layoutlmv3")
|
| 62 |
|
| 63 |
example = dataset["test"][0]
|
| 64 |
example["image"].save("example1.png")
|
|
|
|
| 113 |
label_list.sort()
|
| 114 |
return label_list
|
| 115 |
|
| 116 |
+
#label2color = {'question':'blue', 'answer':'green', 'header':'orange', 'other':'violet'}
|
| 117 |
|
| 118 |
def unnormalize_box(bbox, width, height):
|
| 119 |
return [
|
|
|
|
| 123 |
height * (bbox[3] / 1000),
|
| 124 |
]
|
| 125 |
|
| 126 |
+
def iob_to_label(label):
|
| 127 |
+
label= label[2:]
|
| 128 |
+
if not label:
|
| 129 |
+
return 'other'
|
| 130 |
+
return label
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
def process_image(image):
|
| 133 |
width, height = image.size
|
|
|
|
| 152 |
draw = ImageDraw.Draw(image)
|
| 153 |
font = ImageFont.load_default()
|
| 154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
label2color = {'question':'blue', 'answer':'green', 'header':'orange', 'other':'violet'}
|
| 156 |
for prediction, box in zip(true_predictions, true_boxes):
|
| 157 |
predicted_label = iob_to_label(prediction) #.lower()
|