yonatanbitton commited on
Commit
17d712b
1 Parent(s): 23bdfa8
Files changed (2) hide show
  1. app.py +26 -2
  2. app_basic.py +35 -0
app.py CHANGED
@@ -12,10 +12,26 @@ NORMAL_IMAGE = 'normal_image'
12
  STRANGE_IMAGE = 'strange_image'
13
  def func(index):
14
  example = wmtis[index]
15
- return example['normal_image'], example['normal_hash'], example['strange_image'], example['strange_hash']
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  demo = gr.Blocks()
18
 
 
 
 
 
 
19
  with demo:
20
  gr.Markdown("# Slide to iterate WMTIS: Normal vs. Strange Images")
21
 
@@ -26,10 +42,18 @@ with demo:
26
  with gr.Column():
27
  i1 = gr.Image(value=wmtis[index]["normal_image"], label='Normal Image')
28
  t1 = gr.Textbox(value=wmtis[index]["normal_hash"], label='Image ID')
 
 
 
 
29
  with gr.Column():
30
  i2 = gr.Image(value=wmtis[index]["strange_image"], label='Strange Image')
31
  t2 = gr.Textbox(value=wmtis[index]["strange_hash"], label='Image ID')
 
 
 
 
32
 
33
- slider.change(func, inputs=[slider], outputs=[i1, t1, i2, t2])
34
 
35
  demo.launch()
 
12
  STRANGE_IMAGE = 'strange_image'
13
  def func(index):
14
  example = wmtis[index]
15
+ outputs = []
16
+ for normal_key in ['normal_image', 'normal_hash', 'normal_image_caption', 'rating_normal', 'comments_normal']:
17
+ if normal_key == 'comments_normal':
18
+ outputs.append(get_empty_comment_if_needed(example[normal_key]))
19
+ else:
20
+ outputs.append(example[normal_key])
21
+ for strange_key in ['strange_image', 'strange_hash', 'strange_image_caption', 'rating_strange', 'comments_strange']:
22
+ if normal_key == 'comments_normal':
23
+ outputs.append(get_empty_comment_if_needed(example[strange_key]))
24
+ else:
25
+ outputs.append(example[strange_key])
26
+ return outputs
27
 
28
  demo = gr.Blocks()
29
 
30
+ def get_empty_comment_if_needed(item):
31
+ if item == 'nan':
32
+ return '-'
33
+ return item
34
+
35
  with demo:
36
  gr.Markdown("# Slide to iterate WMTIS: Normal vs. Strange Images")
37
 
 
42
  with gr.Column():
43
  i1 = gr.Image(value=wmtis[index]["normal_image"], label='Normal Image')
44
  t1 = gr.Textbox(value=wmtis[index]["normal_hash"], label='Image ID')
45
+ p1 = gr.Textbox(value=wmtis[index]["normal_image_caption"], label='BLIP2 Predicted Caption')
46
+ r1 = gr.Textbox(value=wmtis[index]["rating_normal"], label='Rating')
47
+ c1 = gr.Textbox(value=get_empty_comment_if_needed(wmtis[index]["comments_normal"]), label='Comments')
48
+ normal_outputs = [i1, t1, p1, r1, c1]
49
  with gr.Column():
50
  i2 = gr.Image(value=wmtis[index]["strange_image"], label='Strange Image')
51
  t2 = gr.Textbox(value=wmtis[index]["strange_hash"], label='Image ID')
52
+ p2 = gr.Textbox(value=wmtis[index]["strange_image_caption"], label='BLIP2 Predicted Caption')
53
+ r2 = gr.Textbox(value=wmtis[index]["rating_strange"], label='Rating')
54
+ c2 = gr.Textbox(value=get_empty_comment_if_needed(wmtis[index]["comments_strange"]), label='Comments')
55
+ strange_outputs = [i2, t2, p2, r2, c2]
56
 
57
+ slider.change(func, inputs=[slider], outputs=normal_outputs + strange_outputs)
58
 
59
  demo.launch()
app_basic.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import gradio as gr
3
+ import os
4
+ import random
5
+
6
+ wmtis = load_dataset("nlphuji/wmtis-identify")['test']
7
+ print(f"Loaded WMTIS identify, first example:")
8
+ print(wmtis[0])
9
+ dataset_size = len(wmtis) - 1
10
+
11
+ NORMAL_IMAGE = 'normal_image'
12
+ STRANGE_IMAGE = 'strange_image'
13
+ def func(index):
14
+ example = wmtis[index]
15
+ return example['normal_image'], example['normal_hash'], example['strange_image'], example['strange_hash']
16
+
17
+ demo = gr.Blocks()
18
+
19
+ with demo:
20
+ gr.Markdown("# Slide to iterate WMTIS: Normal vs. Strange Images")
21
+
22
+ with gr.Column():
23
+ slider = gr.Slider(minimum=0, maximum=dataset_size)
24
+ with gr.Row():
25
+ index = random.choice(range(0, dataset_size))
26
+ with gr.Column():
27
+ i1 = gr.Image(value=wmtis[index]["normal_image"], label='Normal Image')
28
+ t1 = gr.Textbox(value=wmtis[index]["normal_hash"], label='Image ID')
29
+ with gr.Column():
30
+ i2 = gr.Image(value=wmtis[index]["strange_image"], label='Strange Image')
31
+ t2 = gr.Textbox(value=wmtis[index]["strange_hash"], label='Image ID')
32
+
33
+ slider.change(func, inputs=[slider], outputs=[i1, t1, i2, t2])
34
+
35
+ demo.launch()