Spaces:
Running
Running
xiezhihui.x
commited on
Commit
·
9db537a
1
Parent(s):
4265423
cleanup viewer
Browse files- app.py +1 -1
- data_reviewer.py +12 -11
app.py
CHANGED
@@ -90,7 +90,7 @@ with demo:
|
|
90 |
leaderboard = init_leaderboard(df)
|
91 |
|
92 |
with gr.TabItem("📊 Data Viewer"):
|
93 |
-
|
94 |
|
95 |
with gr.TabItem("ℹ️ About"):
|
96 |
gr.Markdown(ABOUT_TEXT)
|
|
|
90 |
leaderboard = init_leaderboard(df)
|
91 |
|
92 |
with gr.TabItem("📊 Data Viewer"):
|
93 |
+
dataset_split, sample_idx = create_data_viewer()
|
94 |
|
95 |
with gr.TabItem("ℹ️ About"):
|
96 |
gr.Markdown(ABOUT_TEXT)
|
data_reviewer.py
CHANGED
@@ -8,6 +8,9 @@ import gradio as gr
|
|
8 |
from datasets import load_dataset
|
9 |
from PIL import Image
|
10 |
|
|
|
|
|
|
|
11 |
|
12 |
@lru_cache(maxsize=1)
|
13 |
def load_cached_dataset(dataset_name, split):
|
@@ -31,9 +34,9 @@ def get_responses(responses, rankings):
|
|
31 |
return chosen, rejected
|
32 |
|
33 |
|
34 |
-
def load_and_display_sample(
|
35 |
try:
|
36 |
-
dataset = load_cached_dataset(
|
37 |
max_idx = len(dataset) - 1
|
38 |
idx = min(max(0, int(idx)), max_idx)
|
39 |
|
@@ -75,14 +78,12 @@ def load_and_display_sample(dataset_name, split, idx):
|
|
75 |
|
76 |
def create_data_viewer():
|
77 |
# Pre-fetch initial data
|
78 |
-
initial_dataset_name = "MMInstruction/VRewardBench"
|
79 |
initial_split = "test"
|
80 |
initial_idx = 0
|
81 |
-
initial_data = load_and_display_sample(
|
82 |
|
83 |
with gr.Column():
|
84 |
with gr.Row():
|
85 |
-
dataset_name = gr.Textbox(label="Dataset Name", value=initial_dataset_name, interactive=True)
|
86 |
dataset_split = gr.Radio(choices=["test"], value=initial_split, label="Dataset Split")
|
87 |
sample_idx = gr.Number(label="Sample Index", value=initial_idx, minimum=0, step=1, interactive=True)
|
88 |
total_samples = gr.Textbox(
|
@@ -92,6 +93,7 @@ def create_data_viewer():
|
|
92 |
with gr.Row():
|
93 |
with gr.Column():
|
94 |
image = gr.Image(label="Sample Image", type="pil", value=initial_data[0]) # Set initial image
|
|
|
95 |
|
96 |
with gr.Column():
|
97 |
sample_id = gr.Textbox(
|
@@ -106,14 +108,13 @@ def create_data_viewer():
|
|
106 |
interactive=False,
|
107 |
)
|
108 |
|
109 |
-
with gr.Row():
|
110 |
judge = gr.Textbox(label="Judge", value=initial_data[4], interactive=False) # Set initial judge
|
111 |
query_source = gr.Textbox(
|
112 |
label="Query Source", value=initial_data[5], interactive=False # Set initial query source
|
113 |
)
|
114 |
-
query = gr.Textbox(label="Query", value=initial_data[6], interactive=False) # Set initial query
|
115 |
|
116 |
-
with gr.Row():
|
117 |
with gr.Column():
|
118 |
models_json = gr.JSON(label="Models", value=json.loads(initial_data[7])) # Set initial models
|
119 |
meta_json = gr.JSON(label="Meta", value=json.loads(initial_data[8])) # Set initial meta
|
@@ -130,10 +131,10 @@ def create_data_viewer():
|
|
130 |
)
|
131 |
|
132 |
# Auto-update when any input changes
|
133 |
-
for input_component in [
|
134 |
input_component.change(
|
135 |
fn=load_and_display_sample,
|
136 |
-
inputs=[
|
137 |
outputs=[
|
138 |
image,
|
139 |
sample_id,
|
@@ -151,4 +152,4 @@ def create_data_viewer():
|
|
151 |
],
|
152 |
)
|
153 |
|
154 |
-
return
|
|
|
8 |
from datasets import load_dataset
|
9 |
from PIL import Image
|
10 |
|
11 |
+
IGNORE_DETAILS = True
|
12 |
+
DATASET_NAME = "MMInstruction/VRewardBench"
|
13 |
+
|
14 |
|
15 |
@lru_cache(maxsize=1)
|
16 |
def load_cached_dataset(dataset_name, split):
|
|
|
34 |
return chosen, rejected
|
35 |
|
36 |
|
37 |
+
def load_and_display_sample(split, idx):
|
38 |
try:
|
39 |
+
dataset = load_cached_dataset(DATASET_NAME, split)
|
40 |
max_idx = len(dataset) - 1
|
41 |
idx = min(max(0, int(idx)), max_idx)
|
42 |
|
|
|
78 |
|
79 |
def create_data_viewer():
|
80 |
# Pre-fetch initial data
|
|
|
81 |
initial_split = "test"
|
82 |
initial_idx = 0
|
83 |
+
initial_data = load_and_display_sample(initial_split, initial_idx)
|
84 |
|
85 |
with gr.Column():
|
86 |
with gr.Row():
|
|
|
87 |
dataset_split = gr.Radio(choices=["test"], value=initial_split, label="Dataset Split")
|
88 |
sample_idx = gr.Number(label="Sample Index", value=initial_idx, minimum=0, step=1, interactive=True)
|
89 |
total_samples = gr.Textbox(
|
|
|
93 |
with gr.Row():
|
94 |
with gr.Column():
|
95 |
image = gr.Image(label="Sample Image", type="pil", value=initial_data[0]) # Set initial image
|
96 |
+
query = gr.Textbox(label="Query", value=initial_data[6], interactive=False) # Set initial query
|
97 |
|
98 |
with gr.Column():
|
99 |
sample_id = gr.Textbox(
|
|
|
108 |
interactive=False,
|
109 |
)
|
110 |
|
111 |
+
with gr.Row(visible=not IGNORE_DETAILS):
|
112 |
judge = gr.Textbox(label="Judge", value=initial_data[4], interactive=False) # Set initial judge
|
113 |
query_source = gr.Textbox(
|
114 |
label="Query Source", value=initial_data[5], interactive=False # Set initial query source
|
115 |
)
|
|
|
116 |
|
117 |
+
with gr.Row(visible=not IGNORE_DETAILS):
|
118 |
with gr.Column():
|
119 |
models_json = gr.JSON(label="Models", value=json.loads(initial_data[7])) # Set initial models
|
120 |
meta_json = gr.JSON(label="Meta", value=json.loads(initial_data[8])) # Set initial meta
|
|
|
131 |
)
|
132 |
|
133 |
# Auto-update when any input changes
|
134 |
+
for input_component in [dataset_split, sample_idx]:
|
135 |
input_component.change(
|
136 |
fn=load_and_display_sample,
|
137 |
+
inputs=[dataset_split, sample_idx],
|
138 |
outputs=[
|
139 |
image,
|
140 |
sample_id,
|
|
|
152 |
],
|
153 |
)
|
154 |
|
155 |
+
return dataset_split, sample_idx
|