Spaces:
Running
Running
sample a puzzle
Browse files
app.py
CHANGED
@@ -90,8 +90,8 @@ def _tab_leaderboard():
|
|
90 |
mode_selection_radio.change(fn=df_filters, inputs=[mode_selection_radio, _gstr("")], outputs=[leaderboard_table])
|
91 |
|
92 |
|
93 |
-
def sample_explore_item(model_name, size_H, size_W
|
94 |
-
print(model_name, size_H, size_W
|
95 |
explore_item = get_random_item(model_name, size_H, size_W)
|
96 |
if explore_item is None:
|
97 |
return "No item found", "No item found", "No item found", "No item found"
|
@@ -99,7 +99,8 @@ def sample_explore_item(model_name, size_H, size_W, greedy_or_sample):
|
|
99 |
example_id = explore_item['id']
|
100 |
puzzle_md = f"### Puzzle [{example_id}]:\n\n" + explore_item['puzzle'].replace("## Clues", "### Clues").replace("\n", "<br>")
|
101 |
model_reasoning_md = f"### {model_name}'s Reasoning:\n\n {explore_item['reasoning']}"
|
102 |
-
model_prediction_md = f"### {model_name}'s Prediction:\n\n {explore_item['solution']}"
|
|
|
103 |
puzzle_solved = explore_item['correct_cells'] == explore_item['total_cells']
|
104 |
cell_acc = explore_item["correct_cells"] / explore_item["total_cells"] * 100
|
105 |
model_eval_md = f"### Evaluation:\n\n **Total Cells**: {explore_item['total_cells']} | **Correct Cells**: {explore_item['correct_cells']} | **Puzzle solved**: {puzzle_solved} | **Cell Acc**: {cell_acc:.2f}%"
|
@@ -109,13 +110,16 @@ def sample_explore_item(model_name, size_H, size_W, greedy_or_sample):
|
|
109 |
def _tab_explore():
|
110 |
global raw_data
|
111 |
model_names = [item["Model"] for item in raw_data]
|
|
|
|
|
112 |
with gr.Row():
|
113 |
model_selection = gr.Dropdown(choices = ["random"] + model_names, label="Model: ", elem_id="select-models", value="random", interactive=True)
|
114 |
size_H_selection = gr.Dropdown(choices = ["random"] + [f"{i}" for i in range(2,7)], label="Num of Houses", elem_id="select-H", value="random", interactive=True)
|
115 |
size_W_selection = gr.Dropdown(choices = ["random"] + [f"{i}" for i in range(2,7)], label="Num of Features", elem_id="select-W", value="random", interactive=True)
|
116 |
with gr.Column(scale=1):
|
117 |
-
greedy_or_sample = gr.Radio(["greedy", "sampling"], show_label=False, elem_id="greedy-or-sample", value="greedy", interactive=True)
|
118 |
-
|
|
|
119 |
|
120 |
puzzle_md = gr.Markdown("\n\nTo be loaded", elem_id="puzzle-md", elem_classes="box_md")
|
121 |
model_reasoning_md = gr.Markdown("\n\nTo be loaded", elem_id="model-reasoning-md", elem_classes="box_md")
|
@@ -123,7 +127,7 @@ def _tab_explore():
|
|
123 |
model_eval_md = gr.Markdown("\n\nTo be loaded", elem_id="model-eval-md", elem_classes="box_md")
|
124 |
|
125 |
explore_button.click(fn=sample_explore_item,
|
126 |
-
inputs=[model_selection, size_H_selection, size_W_selection
|
127 |
outputs=[puzzle_md, model_reasoning_md, model_prediction_md, model_eval_md])
|
128 |
|
129 |
|
|
|
90 |
mode_selection_radio.change(fn=df_filters, inputs=[mode_selection_radio, _gstr("")], outputs=[leaderboard_table])
|
91 |
|
92 |
|
93 |
+
def sample_explore_item(model_name, size_H, size_W):
|
94 |
+
print(model_name, size_H, size_W)
|
95 |
explore_item = get_random_item(model_name, size_H, size_W)
|
96 |
if explore_item is None:
|
97 |
return "No item found", "No item found", "No item found", "No item found"
|
|
|
99 |
example_id = explore_item['id']
|
100 |
puzzle_md = f"### Puzzle [{example_id}]:\n\n" + explore_item['puzzle'].replace("## Clues", "### Clues").replace("\n", "<br>")
|
101 |
model_reasoning_md = f"### {model_name}'s Reasoning:\n\n {explore_item['reasoning']}"
|
102 |
+
model_prediction_md = f"### {model_name}'s Prediction:\n\n {str(explore_item['solution']).replace('___', 'null')}" + \
|
103 |
+
"\n\n" + explore_item['solution_table_md']
|
104 |
puzzle_solved = explore_item['correct_cells'] == explore_item['total_cells']
|
105 |
cell_acc = explore_item["correct_cells"] / explore_item["total_cells"] * 100
|
106 |
model_eval_md = f"### Evaluation:\n\n **Total Cells**: {explore_item['total_cells']} | **Correct Cells**: {explore_item['correct_cells']} | **Puzzle solved**: {puzzle_solved} | **Cell Acc**: {cell_acc:.2f}%"
|
|
|
110 |
def _tab_explore():
|
111 |
global raw_data
|
112 |
model_names = [item["Model"] for item in raw_data]
|
113 |
+
# deduplicate and preserve the order
|
114 |
+
model_names = list(dict.fromkeys(model_names))
|
115 |
with gr.Row():
|
116 |
model_selection = gr.Dropdown(choices = ["random"] + model_names, label="Model: ", elem_id="select-models", value="random", interactive=True)
|
117 |
size_H_selection = gr.Dropdown(choices = ["random"] + [f"{i}" for i in range(2,7)], label="Num of Houses", elem_id="select-H", value="random", interactive=True)
|
118 |
size_W_selection = gr.Dropdown(choices = ["random"] + [f"{i}" for i in range(2,7)], label="Num of Features", elem_id="select-W", value="random", interactive=True)
|
119 |
with gr.Column(scale=1):
|
120 |
+
# greedy_or_sample = gr.Radio(["greedy", "sampling"], show_label=False, elem_id="greedy-or-sample", value="greedy", interactive=True)
|
121 |
+
gr.Markdown("### 🚀 Click below to sample a puzzle. ⬇️ ")
|
122 |
+
explore_button = gr.Button("🦓 Sample a Zebra Puzzle!", elem_id="explore-button")
|
123 |
|
124 |
puzzle_md = gr.Markdown("\n\nTo be loaded", elem_id="puzzle-md", elem_classes="box_md")
|
125 |
model_reasoning_md = gr.Markdown("\n\nTo be loaded", elem_id="model-reasoning-md", elem_classes="box_md")
|
|
|
127 |
model_eval_md = gr.Markdown("\n\nTo be loaded", elem_id="model-eval-md", elem_classes="box_md")
|
128 |
|
129 |
explore_button.click(fn=sample_explore_item,
|
130 |
+
inputs=[model_selection, size_H_selection, size_W_selection],
|
131 |
outputs=[puzzle_md, model_reasoning_md, model_prediction_md, model_eval_md])
|
132 |
|
133 |
|