kokuma commited on
Commit
46ebc31
·
verified ·
1 Parent(s): c0584d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -12
app.py CHANGED
@@ -40,12 +40,11 @@ if not precomputed_results:
40
  device = "cuda" if torch.cuda.is_available() else "cpu"
41
  model = model.to(device)
42
 
43
- def change_language(lang, randomize_imgs, randomize_labels):
44
  # compute text embeddings
45
  labels = babel_imagenet[lang][1]
46
  class_order = list(range(len(labels)))
47
- if randomize_labels:
48
- np.random.shuffle(class_order)
49
  ### We use no prompt ensembling for now
50
  if not precomputed_results:
51
  text_tokens = tokenizer(labels).to(device)
@@ -208,7 +207,6 @@ with (gr.Blocks(title="Babel-ImageNet Quiz") as demo):
208
  # language select dropdown
209
  with gr.Row():
210
  language_select = gr.Dropdown(choices=main_language_values, value="EN", interactive=True, label="Select your language:")
211
- randomize_classes = gr.Checkbox(label="Randomize class order (or play in canonic order)", value=True)
212
  randomize_images = gr.Checkbox(label="Randomize images (if unchecked, will always show the same image). Other images might be less relevant.", value=True)
213
  start_btn = gr.Button(value="Start", variant="primary")
214
 
@@ -237,7 +235,7 @@ with (gr.Blocks(title="Babel-ImageNet Quiz") as demo):
237
  outputs=[options, image, class_idx, correct_choice, model_choice, choices])
238
 
239
  start_btn.click(fn=change_language,
240
- inputs=[language_select, randomize_images, randomize_classes],
241
  outputs=[text_embeddings, class_idx, class_order, correct_text, player_score_text, clip_score_text, player_score, clip_score]
242
  ).then(fn=prepare,
243
  inputs=[class_idx, language_select, text_embeddings, class_order, randomize_images],
@@ -247,13 +245,6 @@ with (gr.Blocks(title="Babel-ImageNet Quiz") as demo):
247
  inputs=[class_idx, language_select, text_embeddings, class_order, randomize_images],
248
  outputs=[options, image, class_idx, correct_choice, model_choice, choices])
249
 
250
- # initialization
251
- # demo.load(fn=change_language,
252
- # inputs=[language_select],
253
- # outputs=[text_embeddings, class_idx, correct_text, player_score_text, clip_score_text, player_score, clip_score]
254
- # ).then(fn=prepare,
255
- # inputs=[class_idx, language_select, text_embeddings],
256
- # outputs=[options, image, class_idx, correct_choice, model_choice])
257
 
258
 
259
 
 
40
  device = "cuda" if torch.cuda.is_available() else "cpu"
41
  model = model.to(device)
42
 
43
+ def change_language(lang, randomize_imgs):
44
  # compute text embeddings
45
  labels = babel_imagenet[lang][1]
46
  class_order = list(range(len(labels)))
47
+ np.random.shuffle(class_order)
 
48
  ### We use no prompt ensembling for now
49
  if not precomputed_results:
50
  text_tokens = tokenizer(labels).to(device)
 
207
  # language select dropdown
208
  with gr.Row():
209
  language_select = gr.Dropdown(choices=main_language_values, value="EN", interactive=True, label="Select your language:")
 
210
  randomize_images = gr.Checkbox(label="Randomize images (if unchecked, will always show the same image). Other images might be less relevant.", value=True)
211
  start_btn = gr.Button(value="Start", variant="primary")
212
 
 
235
  outputs=[options, image, class_idx, correct_choice, model_choice, choices])
236
 
237
  start_btn.click(fn=change_language,
238
+ inputs=[language_select, randomize_images],
239
  outputs=[text_embeddings, class_idx, class_order, correct_text, player_score_text, clip_score_text, player_score, clip_score]
240
  ).then(fn=prepare,
241
  inputs=[class_idx, language_select, text_embeddings, class_order, randomize_images],
 
245
  inputs=[class_idx, language_select, text_embeddings, class_order, randomize_images],
246
  outputs=[options, image, class_idx, correct_choice, model_choice, choices])
247
 
 
 
 
 
 
 
 
248
 
249
 
250