Spaces:
Runtime error
Runtime error
yonatanbitton
commited on
Commit
Β·
4e4df51
1
Parent(s):
435f95e
testing timeout
Browse files- .gitignore +2 -0
- app.py +36 -79
- app_tabs.py +90 -0
.gitignore
CHANGED
@@ -11,6 +11,8 @@ inspectionProfiles
|
|
11 |
inspectionProfiles/
|
12 |
|
13 |
debug_dataset.py
|
|
|
|
|
14 |
|
15 |
# C extensions
|
16 |
*.so
|
|
|
11 |
inspectionProfiles/
|
12 |
|
13 |
debug_dataset.py
|
14 |
+
app2.py
|
15 |
+
app_tabs.py
|
16 |
|
17 |
# C extensions
|
18 |
*.so
|
app.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
from datasets import load_dataset
|
2 |
-
import gradio as gr
|
3 |
-
import os
|
4 |
import random
|
5 |
|
6 |
-
|
|
|
|
|
|
|
7 |
print(f"Loaded WMTIS, first example:")
|
8 |
-
print(
|
9 |
-
dataset_size = len(
|
10 |
-
print(f"
|
11 |
|
12 |
IMAGE = 'image'
|
13 |
IMAGE_DESIGNER = 'image_designer'
|
@@ -15,18 +15,21 @@ DESIGNER_EXPLANATION = 'designer_explanation'
|
|
15 |
CROWD_CAPTIONS = 'crowd_captions'
|
16 |
CROWD_EXPLANATIONS = 'crowd_explanations'
|
17 |
CROWD_UNDERSPECIFIED_CAPTIONS = 'crowd_underspecified_captions'
|
18 |
-
|
|
|
19 |
QA = 'question_answering_pairs'
|
20 |
IMAGE_ID = 'image_id'
|
21 |
left_side_columns = [IMAGE]
|
22 |
-
|
23 |
-
right_side_columns = [x for x in wmtis.features.keys() if x not in left_side_columns and x not in [QA]]
|
24 |
-
# right_side_columns = ["designer_explanation", "image_designer"]
|
25 |
enumerate_cols = [CROWD_CAPTIONS, CROWD_EXPLANATIONS, CROWD_UNDERSPECIFIED_CAPTIONS]
|
26 |
-
emoji_to_label = {
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
def func(index):
|
29 |
-
example =
|
30 |
values = get_instance_values(example)
|
31 |
return values
|
32 |
|
@@ -44,69 +47,24 @@ def get_instance_values(example):
|
|
44 |
values.append(value)
|
45 |
return values
|
46 |
|
47 |
-
def list_to_string(lst):
|
48 |
-
return '\n'.join(['{}. {}'.format(i+1, item) for i, item in enumerate(lst)])
|
49 |
-
|
50 |
-
# demo = gr.Blocks()
|
51 |
-
#
|
52 |
-
# with demo:
|
53 |
-
# gr.Markdown("# Slide to iterate WMTIS")
|
54 |
-
#
|
55 |
-
# with gr.Column():
|
56 |
-
# slider = gr.Slider(minimum=0, maximum=dataset_size, step=1, label='index')
|
57 |
-
# with gr.Row():
|
58 |
-
# # index = random.choice(range(0, dataset_size))
|
59 |
-
# index = slider.value
|
60 |
-
# example = wmtis[index]
|
61 |
-
# instance_values = get_instance_values(example)
|
62 |
-
# with gr.Column():
|
63 |
-
# # image_input = gr.Image(value=wmtis[index]["image"])
|
64 |
-
# inputs_left = []
|
65 |
-
# assert len(left_side_columns) == len(
|
66 |
-
# instance_values[:len(left_side_columns)]) # excluding the image & designer
|
67 |
-
# for key, value in zip(left_side_columns, instance_values[:len(left_side_columns)]):
|
68 |
-
# if key == IMAGE:
|
69 |
-
# input_k = gr.Image(value=wmtis[index]["image"], label=f"Image {emoji_to_label[key]}")
|
70 |
-
# else:
|
71 |
-
# label = key.capitalize().replace("_", " ")
|
72 |
-
# input_k = gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
73 |
-
# inputs_left.append(input_k)
|
74 |
-
# with gr.Column():
|
75 |
-
# text_inputs_right = []
|
76 |
-
# assert len(right_side_columns) == len(instance_values[len(left_side_columns):]) # excluding the image & designer
|
77 |
-
# for key, value in zip(right_side_columns, instance_values[len(left_side_columns):]):
|
78 |
-
# label = key.capitalize().replace("_", " ")
|
79 |
-
# text_input_k = gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
80 |
-
# text_inputs_right.append(text_input_k)
|
81 |
-
#
|
82 |
-
# slider.change(func, inputs=[slider], outputs=inputs_left + text_inputs_right)
|
83 |
-
#
|
84 |
-
# demo.launch()
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
import os
|
89 |
-
import random
|
90 |
-
import time
|
91 |
-
# auth_token = os.environ.get("token")
|
92 |
-
# winoground = load_dataset("facebook/winoground", use_auth_token=auth_token)["test"]
|
93 |
-
wmtis = load_dataset("nlphuji/wmtis")['test']
|
94 |
-
target_size = (1024, 1024)
|
95 |
|
96 |
-
def
|
97 |
-
example =
|
98 |
instance_values = get_instance_values(example)
|
99 |
assert len(left_side_columns) == len(
|
100 |
instance_values[:len(left_side_columns)]) # excluding the image & designer
|
101 |
for key, value in zip(left_side_columns, instance_values[:len(left_side_columns)]):
|
102 |
if key == IMAGE:
|
103 |
-
img =
|
104 |
img_resized = img.resize(target_size)
|
105 |
-
gr.Image(value=img_resized, label=
|
106 |
else:
|
107 |
label = key.capitalize().replace("_", " ")
|
108 |
gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
109 |
-
with gr.Accordion("
|
110 |
assert len(right_side_columns) == len(
|
111 |
instance_values[len(left_side_columns):]) # excluding the image & designer
|
112 |
for key, value in zip(right_side_columns, instance_values[len(left_side_columns):]):
|
@@ -114,19 +72,18 @@ def create_image_accordion_block(index):
|
|
114 |
gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
115 |
|
116 |
|
117 |
-
columns_number =
|
118 |
-
rows_number =
|
119 |
-
|
|
|
|
|
120 |
|
121 |
with gr.Blocks() as demo:
|
122 |
-
gr.Markdown(f"#
|
123 |
-
for
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
with gr.Column():
|
130 |
-
index = random.choice(range(0, dataset_size))
|
131 |
-
create_image_accordion_block(index)
|
132 |
demo.launch()
|
|
|
|
|
|
|
|
|
1 |
import random
|
2 |
|
3 |
+
import gradio as gr
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
whoops = load_dataset("nlphuji/whoops")['test']
|
7 |
print(f"Loaded WMTIS, first example:")
|
8 |
+
print(whoops[0])
|
9 |
+
dataset_size = len(whoops)
|
10 |
+
print(f"all dataset size: {dataset_size}")
|
11 |
|
12 |
IMAGE = 'image'
|
13 |
IMAGE_DESIGNER = 'image_designer'
|
|
|
15 |
CROWD_CAPTIONS = 'crowd_captions'
|
16 |
CROWD_EXPLANATIONS = 'crowd_explanations'
|
17 |
CROWD_UNDERSPECIFIED_CAPTIONS = 'crowd_underspecified_captions'
|
18 |
+
SELECTED_CAPTION = 'selected_caption'
|
19 |
+
COMMONSENSE_CATEGORY = 'commonsense_category'
|
20 |
QA = 'question_answering_pairs'
|
21 |
IMAGE_ID = 'image_id'
|
22 |
left_side_columns = [IMAGE]
|
23 |
+
right_side_columns = [x for x in whoops.features.keys() if x not in left_side_columns and x not in [QA]]
|
|
|
|
|
24 |
enumerate_cols = [CROWD_CAPTIONS, CROWD_EXPLANATIONS, CROWD_UNDERSPECIFIED_CAPTIONS]
|
25 |
+
emoji_to_label = {IMAGE_DESIGNER: 'π¨, π§βπ¨, π»', DESIGNER_EXPLANATION: 'π‘, π€, π§βπ¨',
|
26 |
+
CROWD_CAPTIONS: 'π₯, π¬, π', CROWD_EXPLANATIONS: 'π₯, π‘, π€', CROWD_UNDERSPECIFIED_CAPTIONS: 'π₯, π¬, π',
|
27 |
+
QA: 'β, π€, π‘', IMAGE_ID: 'π, π, πΎ', COMMONSENSE_CATEGORY: 'π€, π, π‘', SELECTED_CAPTION: 'π, π, π¬'}
|
28 |
+
target_size = (1024, 1024)
|
29 |
+
|
30 |
+
|
31 |
def func(index):
|
32 |
+
example = whoops[index]
|
33 |
values = get_instance_values(example)
|
34 |
return values
|
35 |
|
|
|
47 |
values.append(value)
|
48 |
return values
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
def list_to_string(lst):
|
52 |
+
return '\n'.join(['{}. {}'.format(i + 1, item) for i, item in enumerate(lst)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
def plot_image(index):
|
55 |
+
example = whoops[index]
|
56 |
instance_values = get_instance_values(example)
|
57 |
assert len(left_side_columns) == len(
|
58 |
instance_values[:len(left_side_columns)]) # excluding the image & designer
|
59 |
for key, value in zip(left_side_columns, instance_values[:len(left_side_columns)]):
|
60 |
if key == IMAGE:
|
61 |
+
img = whoops[index]["image"]
|
62 |
img_resized = img.resize(target_size)
|
63 |
+
gr.Image(value=img_resized, label=whoops[index]['commonsense_category'])
|
64 |
else:
|
65 |
label = key.capitalize().replace("_", " ")
|
66 |
gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
67 |
+
with gr.Accordion("Click for details", open=False):
|
68 |
assert len(right_side_columns) == len(
|
69 |
instance_values[len(left_side_columns):]) # excluding the image & designer
|
70 |
for key, value in zip(right_side_columns, instance_values[len(left_side_columns):]):
|
|
|
72 |
gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
73 |
|
74 |
|
75 |
+
columns_number = 4
|
76 |
+
# rows_number = int(dataset_size / columns_number)
|
77 |
+
rows_number = 30
|
78 |
+
whoops_sample = whoops.shuffle().select(range(0, columns_number * rows_number))
|
79 |
+
index = 0
|
80 |
|
81 |
with gr.Blocks() as demo:
|
82 |
+
gr.Markdown(f"# WHOOPS! Dataset Explorer")
|
83 |
+
for row_num in range(0, rows_number):
|
84 |
+
with gr.Row():
|
85 |
+
for col_num in range(0, columns_number):
|
86 |
+
with gr.Column():
|
87 |
+
plot_image(index)
|
88 |
+
index += 1
|
|
|
|
|
|
|
89 |
demo.launch()
|
app_tabs.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
wmtis = load_dataset("nlphuji/whoops")['test']
|
7 |
+
print(f"Loaded WMTIS, first example:")
|
8 |
+
print(wmtis[0])
|
9 |
+
dataset_size = len(wmtis)
|
10 |
+
print(f"dataset_size: {dataset_size}")
|
11 |
+
|
12 |
+
IMAGE = 'image'
|
13 |
+
IMAGE_DESIGNER = 'image_designer'
|
14 |
+
DESIGNER_EXPLANATION = 'designer_explanation'
|
15 |
+
CROWD_CAPTIONS = 'crowd_captions'
|
16 |
+
CROWD_EXPLANATIONS = 'crowd_explanations'
|
17 |
+
CROWD_UNDERSPECIFIED_CAPTIONS = 'crowd_underspecified_captions'
|
18 |
+
SELECTED_CAPTION = 'selected_caption'
|
19 |
+
COMMONSENSE_CATEGORY = 'commonsense_category'
|
20 |
+
QA = 'question_answering_pairs'
|
21 |
+
IMAGE_ID = 'image_id'
|
22 |
+
left_side_columns = [IMAGE]
|
23 |
+
right_side_columns = [x for x in wmtis.features.keys() if x not in left_side_columns and x not in [QA]]
|
24 |
+
enumerate_cols = [CROWD_CAPTIONS, CROWD_EXPLANATIONS, CROWD_UNDERSPECIFIED_CAPTIONS]
|
25 |
+
emoji_to_label = {IMAGE_DESIGNER: 'π¨, π§βπ¨, π»', DESIGNER_EXPLANATION: 'π‘, π€, π§βπ¨',
|
26 |
+
CROWD_CAPTIONS: 'π₯, π¬, π', CROWD_EXPLANATIONS: 'π₯, π‘, π€', CROWD_UNDERSPECIFIED_CAPTIONS: 'π₯, π¬, π',
|
27 |
+
QA: 'β, π€, π‘', IMAGE_ID: 'π, π, πΎ', COMMONSENSE_CATEGORY: 'π€, π, π‘', SELECTED_CAPTION: 'π, π, π¬'}
|
28 |
+
target_size = (1024, 1024)
|
29 |
+
|
30 |
+
|
31 |
+
def func(index):
|
32 |
+
example = wmtis[index]
|
33 |
+
values = get_instance_values(example)
|
34 |
+
return values
|
35 |
+
|
36 |
+
|
37 |
+
def get_instance_values(example):
|
38 |
+
values = []
|
39 |
+
for k in left_side_columns + right_side_columns:
|
40 |
+
if k in enumerate_cols:
|
41 |
+
value = list_to_string(example[k])
|
42 |
+
elif k == QA:
|
43 |
+
qa_list = [f"Q: {x[0]} A: {x[1]}" for x in example[k]]
|
44 |
+
value = list_to_string(qa_list)
|
45 |
+
else:
|
46 |
+
value = example[k]
|
47 |
+
values.append(value)
|
48 |
+
return values
|
49 |
+
|
50 |
+
|
51 |
+
def list_to_string(lst):
|
52 |
+
return '\n'.join(['{}. {}'.format(i + 1, item) for i, item in enumerate(lst)])
|
53 |
+
|
54 |
+
def create_image_accordion_block(index):
|
55 |
+
example = wmtis[index]
|
56 |
+
instance_values = get_instance_values(example)
|
57 |
+
assert len(left_side_columns) == len(
|
58 |
+
instance_values[:len(left_side_columns)]) # excluding the image & designer
|
59 |
+
for key, value in zip(left_side_columns, instance_values[:len(left_side_columns)]):
|
60 |
+
if key == IMAGE:
|
61 |
+
img = wmtis[index]["image"]
|
62 |
+
img_resized = img.resize(target_size)
|
63 |
+
gr.Image(value=img_resized, label=f"Image {emoji_to_label[key]}")
|
64 |
+
else:
|
65 |
+
label = key.capitalize().replace("_", " ")
|
66 |
+
gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
67 |
+
with gr.Accordion("Open for More!", open=False):
|
68 |
+
assert len(right_side_columns) == len(
|
69 |
+
instance_values[len(left_side_columns):]) # excluding the image & designer
|
70 |
+
for key, value in zip(right_side_columns, instance_values[len(left_side_columns):]):
|
71 |
+
label = key.capitalize().replace("_", " ")
|
72 |
+
gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
|
73 |
+
|
74 |
+
|
75 |
+
columns_number = 2
|
76 |
+
rows_number = 2
|
77 |
+
tabs_number = 27
|
78 |
+
|
79 |
+
with gr.Blocks() as demo:
|
80 |
+
gr.Markdown(f"# Whoops! images by category")
|
81 |
+
for tub_num in range(0, tabs_number):
|
82 |
+
print(f"create tab:{tub_num}")
|
83 |
+
with gr.Tab(f"Tab {tub_num}"):
|
84 |
+
for row_num in range(0, rows_number):
|
85 |
+
with gr.Row():
|
86 |
+
for col_num in range(0, columns_number):
|
87 |
+
with gr.Column():
|
88 |
+
index = random.choice(range(0, dataset_size))
|
89 |
+
create_image_accordion_block(index)
|
90 |
+
demo.launch()
|