Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1145,10 +1145,8 @@ def prepare(raw_idx, text_embeddings, class_order):
|
|
| 1145 |
keep = random.choice(other_choices)
|
| 1146 |
new_choice_values = [correct_tuple, keep]
|
| 1147 |
random.shuffle(new_choice_values)
|
| 1148 |
-
|
| 1149 |
-
warnings.warn(f"
|
| 1150 |
-
warnings.warn(f"choice_values: {choice_values}")
|
| 1151 |
-
warnings.warn(f"correct_choice: {new_choice_values}")
|
| 1152 |
|
| 1153 |
next_radio = gr.Radio(
|
| 1154 |
choices=choice_values,
|
|
@@ -1163,60 +1161,7 @@ def prepare(raw_idx, text_embeddings, class_order):
|
|
| 1163 |
label="What class does this image belong to?",
|
| 1164 |
)
|
| 1165 |
|
| 1166 |
-
return next_radio, next_image, raw_idx, correct_choice, model_choice,
|
| 1167 |
-
|
| 1168 |
-
|
| 1169 |
-
# def reroll(raw_idx, text_embeddings, class_order):
|
| 1170 |
-
# # prepared next question, loads image, and computes choices
|
| 1171 |
-
|
| 1172 |
-
# idx = class_order[raw_idx]
|
| 1173 |
-
# lang_class_idxs = babel_imagenet["EN"][0]
|
| 1174 |
-
# class_idx = lang_class_idxs[idx]
|
| 1175 |
-
|
| 1176 |
-
# img_idx = 0
|
| 1177 |
-
# img_idx = np.random.choice(min(len(babelnet_images[class_idx]), max_image_choices))
|
| 1178 |
-
# img_url = babelnet_images[class_idx][img_idx]["url"]
|
| 1179 |
-
# class_labels = openai_en_classes
|
| 1180 |
-
|
| 1181 |
-
# choices = list(
|
| 1182 |
-
# reversed(precomputed_results["EN"][idx][img_idx])
|
| 1183 |
-
# ) # precomputing script uses torch.topk which sorts in reverse here
|
| 1184 |
-
# if idx not in choices:
|
| 1185 |
-
# choices = [idx] + choices[1:]
|
| 1186 |
-
# model_choice_idx = choices[-1]
|
| 1187 |
-
|
| 1188 |
-
# numpy.random.shuffle(choices)
|
| 1189 |
-
|
| 1190 |
-
# choice_names = [class_labels[idx] for idx in choices]
|
| 1191 |
-
# choice_values = [0, 1, 2, 3]
|
| 1192 |
-
|
| 1193 |
-
# model_choice_idx = choices.index(model_choice_idx)
|
| 1194 |
-
# model_choice = [choice_names[model_choice_idx], choice_values[model_choice_idx]]
|
| 1195 |
-
# correct_choice_idx = choices.index(idx)
|
| 1196 |
-
# correct_choice = [
|
| 1197 |
-
# choice_names[correct_choice_idx],
|
| 1198 |
-
# choice_values[correct_choice_idx],
|
| 1199 |
-
# ]
|
| 1200 |
-
|
| 1201 |
-
# choice_values = list(zip(choice_names, choice_values))
|
| 1202 |
-
|
| 1203 |
-
# warnings.warn(f"reroll correct_choice: {correct_choice}")
|
| 1204 |
-
# warnings.warn(f"reroll choice_values: {choice_values}")
|
| 1205 |
-
|
| 1206 |
-
# next_radio = gr.Radio(
|
| 1207 |
-
# choices=choice_values,
|
| 1208 |
-
# interactive=True,
|
| 1209 |
-
# label="Select the correct answer:",
|
| 1210 |
-
# value=None,
|
| 1211 |
-
# )
|
| 1212 |
-
# next_image = gr.Image(
|
| 1213 |
-
# value=img_url,
|
| 1214 |
-
# width=IMG_WIDTH,
|
| 1215 |
-
# height=IMG_WIDTH,
|
| 1216 |
-
# label="What class does this image belong to?",
|
| 1217 |
-
# )
|
| 1218 |
-
|
| 1219 |
-
# return next_radio, next_image, raw_idx, correct_choice, model_choice, choice_values
|
| 1220 |
|
| 1221 |
|
| 1222 |
with gr.Blocks(title="Babel-ImageNet Quiz", css=css) as demo:
|
|
@@ -1256,13 +1201,12 @@ with gr.Blocks(title="Babel-ImageNet Quiz", css=css) as demo:
|
|
| 1256 |
choices=["Click", "start"],
|
| 1257 |
interactive=False,
|
| 1258 |
label="Please click start to begin.",
|
| 1259 |
-
elem_classes="choices-group"
|
| 1260 |
)
|
| 1261 |
# with gr.Row():
|
| 1262 |
correct_text = gr.Text("Please click start to begin.")
|
| 1263 |
player_score_text = gr.Text(f"Player score: 0")
|
| 1264 |
clip_score_text = gr.Text(f"mSigLIP score: 0")
|
| 1265 |
-
# reroll_btn = gr.Button(value="Reroll the image (for bad images or errors)")
|
| 1266 |
|
| 1267 |
options.select(
|
| 1268 |
fn=select,
|
|
@@ -1315,14 +1259,5 @@ with gr.Blocks(title="Babel-ImageNet Quiz", css=css) as demo:
|
|
| 1315 |
outputs=[options, image, class_idx, correct_choice, model_choice, choices],
|
| 1316 |
)
|
| 1317 |
|
| 1318 |
-
# reroll_btn.click(
|
| 1319 |
-
# fn=reroll,
|
| 1320 |
-
# inputs=[
|
| 1321 |
-
# class_idx,
|
| 1322 |
-
# text_embeddings,
|
| 1323 |
-
# class_order,
|
| 1324 |
-
# ],
|
| 1325 |
-
# outputs=[options, image, class_idx, correct_choice, model_choice, choices],
|
| 1326 |
-
# )
|
| 1327 |
|
| 1328 |
-
demo.launch()
|
|
|
|
| 1145 |
keep = random.choice(other_choices)
|
| 1146 |
new_choice_values = [correct_tuple, keep]
|
| 1147 |
random.shuffle(new_choice_values)
|
| 1148 |
+
|
| 1149 |
+
warnings.warn(f"model_choice: {model_choice}\n\n")
|
|
|
|
|
|
|
| 1150 |
|
| 1151 |
next_radio = gr.Radio(
|
| 1152 |
choices=choice_values,
|
|
|
|
| 1161 |
label="What class does this image belong to?",
|
| 1162 |
)
|
| 1163 |
|
| 1164 |
+
return next_radio, next_image, raw_idx, correct_choice, model_choice, new_choice_values
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1165 |
|
| 1166 |
|
| 1167 |
with gr.Blocks(title="Babel-ImageNet Quiz", css=css) as demo:
|
|
|
|
| 1201 |
choices=["Click", "start"],
|
| 1202 |
interactive=False,
|
| 1203 |
label="Please click start to begin.",
|
| 1204 |
+
elem_classes="choices-group",
|
| 1205 |
)
|
| 1206 |
# with gr.Row():
|
| 1207 |
correct_text = gr.Text("Please click start to begin.")
|
| 1208 |
player_score_text = gr.Text(f"Player score: 0")
|
| 1209 |
clip_score_text = gr.Text(f"mSigLIP score: 0")
|
|
|
|
| 1210 |
|
| 1211 |
options.select(
|
| 1212 |
fn=select,
|
|
|
|
| 1259 |
outputs=[options, image, class_idx, correct_choice, model_choice, choices],
|
| 1260 |
)
|
| 1261 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1262 |
|
| 1263 |
+
demo.launch()
|