Spaces:
Runtime error
Runtime error
Commit
·
d1016a3
1
Parent(s):
07d2543
Update app.py
Browse files
app.py
CHANGED
|
@@ -94,50 +94,40 @@ categories = labels + ["all"]
|
|
| 94 |
# function to get a rendom image and all data from DocLayNet
|
| 95 |
def generate_annotated_image(dataset_name, split, domain, category):
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
if
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
example =
|
| 128 |
-
if len(example) == 0:
|
| 129 |
-
msg_error = f'There is no image with at least one annotated bounding box that matches to your parameters (category: "{category}" / domain: "{domain}" / dataset: "DocLayNet {dataset_name}" / split: "{split}").'
|
| 130 |
-
example = dict()
|
| 131 |
-
return example, msg_error
|
| 132 |
-
|
| 133 |
-
return example, msg_error
|
| 134 |
-
|
| 135 |
-
# get results
|
| 136 |
-
example, msg_error = get_dataset(dataset_name, split, domain, category)
|
| 137 |
|
| 138 |
if len(msg_error) > 0:
|
| 139 |
return msg_error, images_wo_content, images_wo_content, df_paragraphs_wo_content, df_lines_wo_content
|
| 140 |
-
|
| 141 |
else:
|
| 142 |
# get random image & PDF data
|
| 143 |
image_files = example["image"]
|
|
@@ -310,4 +300,4 @@ with gr.Blocks(title="DocLayNet image viewer", css=".gradio-container") as demo:
|
|
| 310 |
cache_examples=True,
|
| 311 |
)
|
| 312 |
|
| 313 |
-
demo.launch(
|
|
|
|
| 94 |
# function to get a rendom image and all data from DocLayNet
|
| 95 |
def generate_annotated_image(dataset_name, split, domain, category):
|
| 96 |
|
| 97 |
+
# error message
|
| 98 |
+
msg_error = ""
|
| 99 |
+
|
| 100 |
+
# get dataset
|
| 101 |
+
if dataset_name == "small": example = dataset_small
|
| 102 |
+
else: example = dataset_base
|
| 103 |
+
|
| 104 |
+
# get split
|
| 105 |
+
if split == "all":
|
| 106 |
+
example = concatenate_datasets([example["train"], example["validation"], example["test"]])
|
| 107 |
+
else:
|
| 108 |
+
example = example[split]
|
| 109 |
+
|
| 110 |
+
# get domain
|
| 111 |
+
domain_name = domains_names[domains.index(domain)]
|
| 112 |
+
if domain_name != "all":
|
| 113 |
+
example = example.filter(lambda example: example["doc_category"] == domain_name)
|
| 114 |
+
if len(example) == 0:
|
| 115 |
+
msg_error = f'There is no image with at least one annotated bounding box that matches to your parameters (domain: "{domain}" / dataset: "DocLayNet {dataset_name}" / split: "{split}").'
|
| 116 |
+
example = dict()
|
| 117 |
+
|
| 118 |
+
# get category
|
| 119 |
+
idx_list = list()
|
| 120 |
+
if category != "all":
|
| 121 |
+
for idx, categories_list in zip(example["id"], example["categories"]):
|
| 122 |
+
if category in categories_list:
|
| 123 |
+
idx_list.append(idx)
|
| 124 |
+
example = example.select(idx_list)
|
| 125 |
+
if len(example) == 0:
|
| 126 |
+
msg_error = f'There is no image with at least one annotated bounding box that matches to your parameters (category: "{category}" / domain: "{domain}" / dataset: "DocLayNet {dataset_name}" / split: "{split}").'
|
| 127 |
+
example = dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
if len(msg_error) > 0:
|
| 130 |
return msg_error, images_wo_content, images_wo_content, df_paragraphs_wo_content, df_lines_wo_content
|
|
|
|
| 131 |
else:
|
| 132 |
# get random image & PDF data
|
| 133 |
image_files = example["image"]
|
|
|
|
| 300 |
cache_examples=True,
|
| 301 |
)
|
| 302 |
|
| 303 |
+
demo.launch()
|