Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1073,7 +1073,7 @@ def select(idx, choice, correct, player_score, choices):
|
|
1073 |
player_choice = choices[choice][0]
|
1074 |
player_correct = choice == correct_value
|
1075 |
player_score = player_score + int(player_correct)
|
1076 |
-
|
1077 |
correct_text = gr.Text(
|
1078 |
f"Correct was: '{correct_name}'. Question {idx+1}/{len(babel_imagenet['EN'][0])} ",
|
1079 |
label="Game",
|
@@ -1111,15 +1111,12 @@ def prepare(raw_idx, class_order):
|
|
1111 |
) # precomputing script uses torch.topk which sorts in reverse here
|
1112 |
if idx not in choices:
|
1113 |
choices = [idx] + choices[1:]
|
1114 |
-
# model_choice_idx = choices[-1]
|
1115 |
|
1116 |
numpy.random.shuffle(choices)
|
1117 |
|
1118 |
choice_names = [class_labels[idx] for idx in choices]
|
1119 |
choice_values = [0, 1, 2, 3]
|
1120 |
|
1121 |
-
# model_choice_idx = choices.index(model_choice_idx)
|
1122 |
-
# model_choice = [choice_names[model_choice_idx], choice_values[model_choice_idx]]
|
1123 |
correct_choice_idx = choices.index(idx)
|
1124 |
correct_choice = [
|
1125 |
choice_names[correct_choice_idx],
|
@@ -1158,8 +1155,7 @@ def prepare(raw_idx, class_order):
|
|
1158 |
next_image,
|
1159 |
raw_idx,
|
1160 |
correct_choice,
|
1161 |
-
|
1162 |
-
new_choice_values,
|
1163 |
)
|
1164 |
|
1165 |
|
@@ -1168,13 +1164,10 @@ with gr.Blocks(title="Babel-ImageNet Quiz", css=css) as demo:
|
|
1168 |
# setup state
|
1169 |
class_idx = gr.State(-1)
|
1170 |
player_score = gr.State(0)
|
1171 |
-
# clip_score = gr.State(0)
|
1172 |
class_order = gr.State([])
|
1173 |
choices = gr.State([])
|
1174 |
|
1175 |
-
# text_embeddings = gr.State(None)
|
1176 |
correct_choice = gr.State(["nan", 0]) # 0, 1, 2, 3
|
1177 |
-
# model_choice = gr.State(["nan", 0])
|
1178 |
|
1179 |
# Title Area
|
1180 |
gr.Markdown(
|
@@ -1213,17 +1206,13 @@ with gr.Blocks(title="Babel-ImageNet Quiz", css=css) as demo:
|
|
1213 |
class_idx,
|
1214 |
options,
|
1215 |
correct_choice,
|
1216 |
-
# model_choice,
|
1217 |
player_score,
|
1218 |
-
# clip_score,
|
1219 |
choices,
|
1220 |
],
|
1221 |
outputs=[
|
1222 |
correct_text,
|
1223 |
player_score_text,
|
1224 |
-
# clip_score_text,
|
1225 |
player_score,
|
1226 |
-
# clip_score,
|
1227 |
],
|
1228 |
).then(
|
1229 |
fn=prepare,
|
@@ -1238,20 +1227,16 @@ with gr.Blocks(title="Babel-ImageNet Quiz", css=css) as demo:
|
|
1238 |
fn=change_language,
|
1239 |
inputs=[],
|
1240 |
outputs=[
|
1241 |
-
# text_embeddings,
|
1242 |
class_idx,
|
1243 |
class_order,
|
1244 |
correct_text,
|
1245 |
player_score_text,
|
1246 |
-
# clip_score_text,
|
1247 |
player_score,
|
1248 |
-
# clip_score,
|
1249 |
],
|
1250 |
).then(
|
1251 |
fn=prepare,
|
1252 |
inputs=[
|
1253 |
class_idx,
|
1254 |
-
# text_embeddings,
|
1255 |
class_order,
|
1256 |
],
|
1257 |
outputs=[options, image, class_idx, correct_choice, choices],
|
|
|
1073 |
player_choice = choices[choice][0]
|
1074 |
player_correct = choice == correct_value
|
1075 |
player_score = player_score + int(player_correct)
|
1076 |
+
|
1077 |
correct_text = gr.Text(
|
1078 |
f"Correct was: '{correct_name}'. Question {idx+1}/{len(babel_imagenet['EN'][0])} ",
|
1079 |
label="Game",
|
|
|
1111 |
) # precomputing script uses torch.topk which sorts in reverse here
|
1112 |
if idx not in choices:
|
1113 |
choices = [idx] + choices[1:]
|
|
|
1114 |
|
1115 |
numpy.random.shuffle(choices)
|
1116 |
|
1117 |
choice_names = [class_labels[idx] for idx in choices]
|
1118 |
choice_values = [0, 1, 2, 3]
|
1119 |
|
|
|
|
|
1120 |
correct_choice_idx = choices.index(idx)
|
1121 |
correct_choice = [
|
1122 |
choice_names[correct_choice_idx],
|
|
|
1155 |
next_image,
|
1156 |
raw_idx,
|
1157 |
correct_choice,
|
1158 |
+
choice_values,
|
|
|
1159 |
)
|
1160 |
|
1161 |
|
|
|
1164 |
# setup state
|
1165 |
class_idx = gr.State(-1)
|
1166 |
player_score = gr.State(0)
|
|
|
1167 |
class_order = gr.State([])
|
1168 |
choices = gr.State([])
|
1169 |
|
|
|
1170 |
correct_choice = gr.State(["nan", 0]) # 0, 1, 2, 3
|
|
|
1171 |
|
1172 |
# Title Area
|
1173 |
gr.Markdown(
|
|
|
1206 |
class_idx,
|
1207 |
options,
|
1208 |
correct_choice,
|
|
|
1209 |
player_score,
|
|
|
1210 |
choices,
|
1211 |
],
|
1212 |
outputs=[
|
1213 |
correct_text,
|
1214 |
player_score_text,
|
|
|
1215 |
player_score,
|
|
|
1216 |
],
|
1217 |
).then(
|
1218 |
fn=prepare,
|
|
|
1227 |
fn=change_language,
|
1228 |
inputs=[],
|
1229 |
outputs=[
|
|
|
1230 |
class_idx,
|
1231 |
class_order,
|
1232 |
correct_text,
|
1233 |
player_score_text,
|
|
|
1234 |
player_score,
|
|
|
1235 |
],
|
1236 |
).then(
|
1237 |
fn=prepare,
|
1238 |
inputs=[
|
1239 |
class_idx,
|
|
|
1240 |
class_order,
|
1241 |
],
|
1242 |
outputs=[options, image, class_idx, correct_choice, choices],
|