Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,12 @@ model = AutoModelForTokenClassification.from_pretrained("SickBoy/layoutlm_docume
|
|
25 |
|
26 |
|
27 |
# load image example
|
28 |
-
dataset = load_dataset("
|
|
|
|
|
|
|
|
|
|
|
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")
|
@@ -76,8 +81,9 @@ def process_image(image):
|
|
76 |
width, height = image.size
|
77 |
|
78 |
# encode
|
79 |
-
encoding = processor(image, truncation=True, return_offsets_mapping=True, return_tensors="pt")
|
80 |
-
|
|
|
81 |
|
82 |
# forward pass
|
83 |
outputs = model(**encoding)
|
|
|
25 |
|
26 |
|
27 |
# load image example
|
28 |
+
dataset = load_dataset("SickBoy/layout_documents", split="train")
|
29 |
+
example = dataset[0]
|
30 |
+
image1 = example["image"]
|
31 |
+
words = example["tokens"]
|
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")
|
|
|
81 |
width, height = image.size
|
82 |
|
83 |
# encode
|
84 |
+
#encoding = processor(image, truncation=True, return_offsets_mapping=True, return_tensors="pt")
|
85 |
+
encoding = processor(image1, words, boxes=boxes, word_labels=word_labels, return_tensors="pt")
|
86 |
+
#offset_mapping = encoding.pop('offset_mapping')
|
87 |
|
88 |
# forward pass
|
89 |
outputs = model(**encoding)
|