yonatanbitton commited on
Commit
435f95e
β€’
1 Parent(s): c4454c9

testing timeout

Browse files
Files changed (2) hide show
  1. app.py +82 -30
  2. app2.py +81 -0
app.py CHANGED
@@ -7,6 +7,7 @@ wmtis = load_dataset("nlphuji/wmtis")['test']
7
  print(f"Loaded WMTIS, first example:")
8
  print(wmtis[0])
9
  dataset_size = len(wmtis) - 1
 
10
 
11
  IMAGE = 'image'
12
  IMAGE_DESIGNER = 'image_designer'
@@ -20,8 +21,9 @@ IMAGE_ID = 'image_id'
20
  left_side_columns = [IMAGE]
21
  # left_side_columns = [IMAGE, DESIGNER_EXPLANATION, IMAGE_DESIGNER, IMAGE_ID]
22
  right_side_columns = [x for x in wmtis.features.keys() if x not in left_side_columns and x not in [QA]]
 
23
  enumerate_cols = [CROWD_CAPTIONS, CROWD_EXPLANATIONS, CROWD_UNDERSPECIFIED_CAPTIONS]
24
- emoji_to_label = {IMAGE: 'πŸ–ΌοΈ, πŸ“·, πŸŒ„', IMAGE_DESIGNER: '🎨, πŸ§‘β€πŸŽ¨, πŸ’»', DESIGNER_EXPLANATION: 'πŸ’‘, πŸ€”, πŸ§‘β€πŸŽ¨', CROWD_CAPTIONS: 'πŸ‘₯, πŸ’¬, πŸ“', CROWD_EXPLANATIONS: 'πŸ‘₯, πŸ’‘, πŸ€”', CROWD_UNDERSPECIFIED_CAPTIONS: 'πŸ‘₯, πŸ’¬, πŸ‘Ž',
25
  QA: '❓, πŸ€”, πŸ’‘', IMAGE_ID: 'πŸ”, πŸ“„, πŸ’Ύ'}
26
  def func(index):
27
  example = wmtis[index]
@@ -41,40 +43,90 @@ def get_instance_values(example):
41
  value = example[k]
42
  values.append(value)
43
  return values
 
44
  def list_to_string(lst):
45
  return '\n'.join(['{}. {}'.format(i+1, item) for i, item in enumerate(lst)])
46
 
47
- demo = gr.Blocks()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
- with demo:
50
- gr.Markdown("# Slide to iterate WMTIS")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
- with gr.Column():
53
- slider = gr.Slider(minimum=0, maximum=dataset_size, step=1, label='index')
54
- with gr.Row():
55
- index = random.choice(range(0, dataset_size))
56
- example = wmtis[index]
57
- instance_values = get_instance_values(example)
58
- with gr.Column():
59
- # image_input = gr.Image(value=wmtis[index]["image"])
60
- inputs_left = []
61
- assert len(left_side_columns) == len(
62
- instance_values[:len(left_side_columns)]) # excluding the image & designer
63
- for key, value in zip(left_side_columns, instance_values[:len(left_side_columns)]):
64
- if key == IMAGE:
65
- input_k = gr.Image(value=wmtis[index]["image"], label=f"Image {emoji_to_label[key]}")
66
- else:
67
- label = key.capitalize().replace("_", " ")
68
- input_k = gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
69
- inputs_left.append(input_k)
70
- with gr.Column():
71
- text_inputs_right = []
72
- assert len(right_side_columns) == len(instance_values[len(left_side_columns):]) # excluding the image & designer
73
- for key, value in zip(right_side_columns, instance_values[len(left_side_columns):]):
74
- label = key.capitalize().replace("_", " ")
75
- text_input_k = gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
76
- text_inputs_right.append(text_input_k)
77
 
78
- slider.change(func, inputs=[slider], outputs=inputs_left + text_inputs_right)
 
 
79
 
 
 
 
 
 
 
 
 
 
 
 
80
  demo.launch()
 
7
  print(f"Loaded WMTIS, first example:")
8
  print(wmtis[0])
9
  dataset_size = len(wmtis) - 1
10
+ print(f"dataset_size: {dataset_size}")
11
 
12
  IMAGE = 'image'
13
  IMAGE_DESIGNER = 'image_designer'
 
21
  left_side_columns = [IMAGE]
22
  # left_side_columns = [IMAGE, DESIGNER_EXPLANATION, IMAGE_DESIGNER, IMAGE_ID]
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 = {IMAGE: 'πŸŒ„', IMAGE_DESIGNER: '🎨, πŸ§‘β€πŸŽ¨, πŸ’»', DESIGNER_EXPLANATION: 'πŸ’‘, πŸ€”, πŸ§‘β€πŸŽ¨', CROWD_CAPTIONS: 'πŸ‘₯, πŸ’¬, πŸ“', CROWD_EXPLANATIONS: 'πŸ‘₯, πŸ’‘, πŸ€”', CROWD_UNDERSPECIFIED_CAPTIONS: 'πŸ‘₯, πŸ’¬, πŸ‘Ž',
27
  QA: '❓, πŸ€”, πŸ’‘', IMAGE_ID: 'πŸ”, πŸ“„, πŸ’Ύ'}
28
  def func(index):
29
  example = wmtis[index]
 
43
  value = example[k]
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
+ from datasets import load_dataset
87
+ import gradio as gr
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 create_image_accordion_block(index):
97
+ example = wmtis[index]
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 = wmtis[index]["image"]
104
+ img_resized = img.resize(target_size)
105
+ gr.Image(value=img_resized, label=f"Image {emoji_to_label[key]}")
106
+ else:
107
+ label = key.capitalize().replace("_", " ")
108
+ gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
109
+ with gr.Accordion("Open for More!", open=False):
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):]):
113
+ label = key.capitalize().replace("_", " ")
114
+ gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
+ columns_number = 3
118
+ rows_number = 2
119
+ tabs_number = 27
120
 
121
+ with gr.Blocks() as demo:
122
+ gr.Markdown(f"# Whoops! images by category")
123
+ for tub_num in range(0, tabs_number):
124
+ print(f"create tab:{tub_num}")
125
+ with gr.Tab(f"Tab {tub_num}"):
126
+ for row_num in range(0, rows_number):
127
+ with gr.Row():
128
+ for col_num in range(0, columns_number):
129
+ with gr.Column():
130
+ index = random.choice(range(0, dataset_size))
131
+ create_image_accordion_block(index)
132
  demo.launch()
app2.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import gradio as gr
3
+ import os
4
+ import random
5
+
6
+ wmtis = load_dataset("nlphuji/wmtis")['test']
7
+ print(f"Loaded WMTIS, first example:")
8
+ print(wmtis[0])
9
+ dataset_size = len(wmtis) - 1
10
+
11
+ IMAGE = 'image'
12
+ IMAGE_DESIGNER = 'image_designer'
13
+ DESIGNER_EXPLANATION = 'designer_explanation'
14
+ CROWD_CAPTIONS = 'crowd_captions'
15
+ CROWD_EXPLANATIONS = 'crowd_explanations'
16
+ CROWD_UNDERSPECIFIED_CAPTIONS = 'crowd_underspecified_captions'
17
+ # CROWD_NEGATIVE_EXPLANATIONS = 'crowd_negative_explanations'
18
+ QA = 'question_answering_pairs'
19
+ IMAGE_ID = 'image_id'
20
+ left_side_columns = [IMAGE]
21
+ # left_side_columns = [IMAGE, DESIGNER_EXPLANATION, IMAGE_DESIGNER, IMAGE_ID]
22
+ right_side_columns = [x for x in wmtis.features.keys() if x not in left_side_columns and x not in [QA]]
23
+ enumerate_cols = [CROWD_CAPTIONS, CROWD_EXPLANATIONS, CROWD_UNDERSPECIFIED_CAPTIONS]
24
+ emoji_to_label = {IMAGE: 'πŸ–ΌοΈ, πŸ“·, πŸŒ„', IMAGE_DESIGNER: '🎨, πŸ§‘β€πŸŽ¨, πŸ’»', DESIGNER_EXPLANATION: 'πŸ’‘, πŸ€”, πŸ§‘β€πŸŽ¨', CROWD_CAPTIONS: 'πŸ‘₯, πŸ’¬, πŸ“', CROWD_EXPLANATIONS: 'πŸ‘₯, πŸ’‘, πŸ€”', CROWD_UNDERSPECIFIED_CAPTIONS: 'πŸ‘₯, πŸ’¬, πŸ‘Ž',
25
+ QA: '❓, πŸ€”, πŸ’‘', IMAGE_ID: 'πŸ”, πŸ“„, πŸ’Ύ'}
26
+ def func(index):
27
+ example = wmtis[index]
28
+ values = get_instance_values(example)
29
+ return values
30
+
31
+
32
+ def get_instance_values(example):
33
+ values = []
34
+ for k in left_side_columns + right_side_columns:
35
+ if k in enumerate_cols:
36
+ value = list_to_string(example[k])
37
+ elif k == QA:
38
+ qa_list = [f"Q: {x[0]} A: {x[1]}" for x in example[k]]
39
+ value = list_to_string(qa_list)
40
+ else:
41
+ value = example[k]
42
+ values.append(value)
43
+ return values
44
+ def list_to_string(lst):
45
+ return '\n'.join(['{}. {}'.format(i+1, item) for i, item in enumerate(lst)])
46
+
47
+ demo = gr.Blocks()
48
+
49
+ with demo:
50
+ gr.Markdown("# Slide to iterate WMTIS")
51
+
52
+ with gr.Column():
53
+ slider = gr.Slider(minimum=0, maximum=dataset_size, step=1, label='index')
54
+ with gr.Row():
55
+ # index = random.choice(range(0, dataset_size))
56
+ index = slider.label
57
+ example = wmtis[index]
58
+ instance_values = get_instance_values(example)
59
+ with gr.Column():
60
+ # image_input = gr.Image(value=wmtis[index]["image"])
61
+ inputs_left = []
62
+ assert len(left_side_columns) == len(
63
+ instance_values[:len(left_side_columns)]) # excluding the image & designer
64
+ for key, value in zip(left_side_columns, instance_values[:len(left_side_columns)]):
65
+ if key == IMAGE:
66
+ input_k = gr.Image(value=wmtis[index]["image"], label=f"Image {emoji_to_label[key]}")
67
+ else:
68
+ label = key.capitalize().replace("_", " ")
69
+ input_k = gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
70
+ inputs_left.append(input_k)
71
+ with gr.Column():
72
+ text_inputs_right = []
73
+ assert len(right_side_columns) == len(instance_values[len(left_side_columns):]) # excluding the image & designer
74
+ for key, value in zip(right_side_columns, instance_values[len(left_side_columns):]):
75
+ label = key.capitalize().replace("_", " ")
76
+ text_input_k = gr.Textbox(value=value, label=f"{label} {emoji_to_label[key]}")
77
+ text_inputs_right.append(text_input_k)
78
+
79
+ slider.change(func, inputs=[slider], outputs=inputs_left + text_inputs_right)
80
+
81
+ demo.launch()