Spaces:
Runtime error
Runtime error
feat: UI upgrades
Browse files
app.py
CHANGED
|
@@ -69,7 +69,13 @@ def evaluate(
|
|
| 69 |
def reset_all():
|
| 70 |
return (
|
| 71 |
[], "", "", [], "", "", # Existing resets for inputs and rubrics
|
| 72 |
-
"", "", "", "", "" # New resets for additional fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
)
|
| 74 |
|
| 75 |
# Define presets
|
|
@@ -116,8 +122,23 @@ with gr.Blocks() as demo:
|
|
| 116 |
gr.Markdown("*<span style='color: gray;'>Define the input names and values. Inputs are optional if evaluation depends on the output only.</span>*")
|
| 117 |
with gr.Group():
|
| 118 |
inputs_task = gr.State([])
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
def add_input(inputs_task, new_input_name, new_input_value):
|
| 123 |
return inputs_task + [{"name": new_input_name, "value": new_input_value}], "", ""
|
|
@@ -139,11 +160,13 @@ with gr.Blocks() as demo:
|
|
| 139 |
return inputs_list
|
| 140 |
delete_btn.click(delete, None, [inputs_task]) # This is the state variable
|
| 141 |
|
| 142 |
-
gr.
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
| 147 |
|
| 148 |
with gr.Column(scale=1):
|
| 149 |
gr.Markdown("## **Evaluation task output**")
|
|
@@ -162,10 +185,28 @@ with gr.Blocks() as demo:
|
|
| 162 |
|
| 163 |
with gr.Row():
|
| 164 |
with gr.Column(scale=1):
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
def add_rubric_item(rubric_items, new_rubric_name, new_rubric_value):
|
| 170 |
return rubric_items + [{"name": new_rubric_name, "value": new_rubric_value}], "", ""
|
| 171 |
|
|
@@ -175,10 +216,20 @@ with gr.Blocks() as demo:
|
|
| 175 |
for rubric_item in rubric_items_list:
|
| 176 |
with gr.Group():
|
| 177 |
with gr.Row(equal_height=True):
|
| 178 |
-
with gr.Column(min_width=
|
| 179 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
with gr.Column(scale=8):
|
| 181 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
with gr.Column(min_width=15, scale=1):
|
| 183 |
delete_btn = gr.Button("X", size="lg", variant="secondary")
|
| 184 |
def delete(rubric_item=rubric_item):
|
|
@@ -186,11 +237,13 @@ with gr.Blocks() as demo:
|
|
| 186 |
return rubric_items_list
|
| 187 |
delete_btn.click(delete, None, [rubric_items]) # This is the state variable
|
| 188 |
|
| 189 |
-
gr.
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
|
|
|
|
|
|
| 194 |
with gr.Column(scale=1):
|
| 195 |
evaluation_criteria = gr.Textbox(label="Evaluation criteria")
|
| 196 |
|
|
@@ -199,9 +252,9 @@ with gr.Blocks() as demo:
|
|
| 199 |
gr.Markdown("# **Evaluation**")
|
| 200 |
with gr.Group():
|
| 201 |
with gr.Row(equal_height=True):
|
| 202 |
-
with gr.Column(min_width=
|
| 203 |
score = gr.Textbox(label="Score", interactive=False, autoscroll=False, max_lines=1)
|
| 204 |
-
with gr.Column(scale=
|
| 205 |
feedback = gr.Textbox(label="Feedback", interactive=False, autoscroll=False, max_lines=6)
|
| 206 |
with gr.Column(min_width=15, scale=1):
|
| 207 |
evaluate_btn = gr.Button("Evaluate", variant="primary")
|
|
@@ -217,11 +270,17 @@ with gr.Blocks() as demo:
|
|
| 217 |
rubric_items,
|
| 218 |
new_rubric_name,
|
| 219 |
new_rubric_value,
|
| 220 |
-
evaluation_criteria,
|
| 221 |
-
output_name,
|
| 222 |
-
output_value,
|
| 223 |
-
feedback,
|
| 224 |
-
score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
]
|
| 226 |
)
|
| 227 |
|
|
@@ -234,18 +293,24 @@ with gr.Blocks() as demo:
|
|
| 234 |
for i, button in enumerate(preset_buttons):
|
| 235 |
def populate_preset(ex_i=i):
|
| 236 |
return populate_fields(ex_i)
|
| 237 |
-
|
| 238 |
button.click(
|
| 239 |
-
populate_preset,
|
| 240 |
-
inputs=[],
|
| 241 |
outputs=[
|
| 242 |
inputs_task,
|
| 243 |
output_name,
|
| 244 |
output_value,
|
| 245 |
evaluation_criteria,
|
| 246 |
rubric_items,
|
| 247 |
-
feedback,
|
| 248 |
-
score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
]
|
| 250 |
)
|
| 251 |
|
|
@@ -258,7 +323,13 @@ def populate_fields(example_index: int):
|
|
| 258 |
example["evaluation_criteria"],
|
| 259 |
example["rubric"],
|
| 260 |
"", # Reset feedback
|
| 261 |
-
"" # Reset score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
)
|
| 263 |
|
| 264 |
-
demo.launch(debug=True)
|
|
|
|
| 69 |
def reset_all():
|
| 70 |
return (
|
| 71 |
[], "", "", [], "", "", # Existing resets for inputs and rubrics
|
| 72 |
+
"", "", "", "", "", # New resets for additional fields
|
| 73 |
+
gr.update(visible=True), # Show new_input_name
|
| 74 |
+
gr.update(visible=True), # Show new_input_value
|
| 75 |
+
gr.update(visible=True), # Show new_rubric_name
|
| 76 |
+
gr.update(visible=True), # Show new_rubric_value
|
| 77 |
+
gr.update(visible=True), # Show Add Input button
|
| 78 |
+
gr.update(visible=True), # Show Add Rubric Item button
|
| 79 |
)
|
| 80 |
|
| 81 |
# Define presets
|
|
|
|
| 122 |
gr.Markdown("*<span style='color: gray;'>Define the input names and values. Inputs are optional if evaluation depends on the output only.</span>*")
|
| 123 |
with gr.Group():
|
| 124 |
inputs_task = gr.State([])
|
| 125 |
+
with gr.Row(equal_height=True):
|
| 126 |
+
with gr.Column(min_width=60, scale=2):
|
| 127 |
+
new_input_name = gr.Textbox(
|
| 128 |
+
label="Name",
|
| 129 |
+
show_label=True,
|
| 130 |
+
autoscroll=False,
|
| 131 |
+
max_lines=1,
|
| 132 |
+
visible=True # Initially visible
|
| 133 |
+
)
|
| 134 |
+
with gr.Column(scale=9):
|
| 135 |
+
new_input_value = gr.Textbox(
|
| 136 |
+
label="Value",
|
| 137 |
+
show_label=True,
|
| 138 |
+
autoscroll=False,
|
| 139 |
+
max_lines=3,
|
| 140 |
+
visible=True # Initially visible
|
| 141 |
+
)
|
| 142 |
|
| 143 |
def add_input(inputs_task, new_input_name, new_input_value):
|
| 144 |
return inputs_task + [{"name": new_input_name, "value": new_input_value}], "", ""
|
|
|
|
| 160 |
return inputs_list
|
| 161 |
delete_btn.click(delete, None, [inputs_task]) # This is the state variable
|
| 162 |
|
| 163 |
+
with gr.Group():
|
| 164 |
+
add_input_btn = gr.Button("Add Input") # Assign to variable
|
| 165 |
+
add_input_btn.click(
|
| 166 |
+
add_input,
|
| 167 |
+
[inputs_task, new_input_name, new_input_value],
|
| 168 |
+
[inputs_task, new_input_name, new_input_value]
|
| 169 |
+
)
|
| 170 |
|
| 171 |
with gr.Column(scale=1):
|
| 172 |
gr.Markdown("## **Evaluation task output**")
|
|
|
|
| 185 |
|
| 186 |
with gr.Row():
|
| 187 |
with gr.Column(scale=1):
|
| 188 |
+
with gr.Group():
|
| 189 |
+
rubric_items = gr.State([])
|
| 190 |
+
with gr.Row(equal_height=True):
|
| 191 |
+
with gr.Column(min_width=60, scale=2):
|
| 192 |
+
new_rubric_name = gr.Textbox(
|
| 193 |
+
label="Score",
|
| 194 |
+
show_label=True,
|
| 195 |
+
interactive=True,
|
| 196 |
+
autoscroll=False,
|
| 197 |
+
max_lines=1,
|
| 198 |
+
visible=True # Initially visible
|
| 199 |
+
)
|
| 200 |
+
with gr.Column(scale=9):
|
| 201 |
+
new_rubric_value = gr.Textbox(
|
| 202 |
+
label="Description",
|
| 203 |
+
show_label=True,
|
| 204 |
+
interactive=True,
|
| 205 |
+
autoscroll=False,
|
| 206 |
+
max_lines=3,
|
| 207 |
+
visible=True # Initially visible
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
def add_rubric_item(rubric_items, new_rubric_name, new_rubric_value):
|
| 211 |
return rubric_items + [{"name": new_rubric_name, "value": new_rubric_value}], "", ""
|
| 212 |
|
|
|
|
| 216 |
for rubric_item in rubric_items_list:
|
| 217 |
with gr.Group():
|
| 218 |
with gr.Row(equal_height=True):
|
| 219 |
+
with gr.Column(min_width=60, scale=2):
|
| 220 |
+
gr.Textbox(
|
| 221 |
+
rubric_item['name'],
|
| 222 |
+
label="Score",
|
| 223 |
+
show_label=True,
|
| 224 |
+
interactive=False
|
| 225 |
+
)
|
| 226 |
with gr.Column(scale=8):
|
| 227 |
+
gr.Textbox(
|
| 228 |
+
rubric_item['value'],
|
| 229 |
+
label="Description",
|
| 230 |
+
show_label=True,
|
| 231 |
+
interactive=False
|
| 232 |
+
)
|
| 233 |
with gr.Column(min_width=15, scale=1):
|
| 234 |
delete_btn = gr.Button("X", size="lg", variant="secondary")
|
| 235 |
def delete(rubric_item=rubric_item):
|
|
|
|
| 237 |
return rubric_items_list
|
| 238 |
delete_btn.click(delete, None, [rubric_items]) # This is the state variable
|
| 239 |
|
| 240 |
+
with gr.Group():
|
| 241 |
+
add_rubric_btn = gr.Button("Add Rubric Item") # Assign to variable
|
| 242 |
+
add_rubric_btn.click(
|
| 243 |
+
add_rubric_item,
|
| 244 |
+
[rubric_items, new_rubric_name, new_rubric_value],
|
| 245 |
+
[rubric_items, new_rubric_name, new_rubric_value]
|
| 246 |
+
)
|
| 247 |
with gr.Column(scale=1):
|
| 248 |
evaluation_criteria = gr.Textbox(label="Evaluation criteria")
|
| 249 |
|
|
|
|
| 252 |
gr.Markdown("# **Evaluation**")
|
| 253 |
with gr.Group():
|
| 254 |
with gr.Row(equal_height=True):
|
| 255 |
+
with gr.Column(min_width=60, scale=1):
|
| 256 |
score = gr.Textbox(label="Score", interactive=False, autoscroll=False, max_lines=1)
|
| 257 |
+
with gr.Column(scale=9):
|
| 258 |
feedback = gr.Textbox(label="Feedback", interactive=False, autoscroll=False, max_lines=6)
|
| 259 |
with gr.Column(min_width=15, scale=1):
|
| 260 |
evaluate_btn = gr.Button("Evaluate", variant="primary")
|
|
|
|
| 270 |
rubric_items,
|
| 271 |
new_rubric_name,
|
| 272 |
new_rubric_value,
|
| 273 |
+
evaluation_criteria,
|
| 274 |
+
output_name,
|
| 275 |
+
output_value,
|
| 276 |
+
feedback,
|
| 277 |
+
score,
|
| 278 |
+
new_input_name, # Visibility for new_input_name
|
| 279 |
+
new_input_value, # Visibility for new_input_value
|
| 280 |
+
new_rubric_name, # Visibility for new_rubric_name
|
| 281 |
+
new_rubric_value, # Visibility for new_rubric_value
|
| 282 |
+
add_input_btn, # Visibility for Add Input button
|
| 283 |
+
add_rubric_btn, # Visibility for Add Rubric Item button
|
| 284 |
]
|
| 285 |
)
|
| 286 |
|
|
|
|
| 293 |
for i, button in enumerate(preset_buttons):
|
| 294 |
def populate_preset(ex_i=i):
|
| 295 |
return populate_fields(ex_i)
|
| 296 |
+
|
| 297 |
button.click(
|
| 298 |
+
populate_preset,
|
| 299 |
+
inputs=[],
|
| 300 |
outputs=[
|
| 301 |
inputs_task,
|
| 302 |
output_name,
|
| 303 |
output_value,
|
| 304 |
evaluation_criteria,
|
| 305 |
rubric_items,
|
| 306 |
+
feedback,
|
| 307 |
+
score,
|
| 308 |
+
new_input_name, # Visibility for new_input_name
|
| 309 |
+
new_input_value, # Visibility for new_input_value
|
| 310 |
+
new_rubric_name, # Visibility for new_rubric_name
|
| 311 |
+
new_rubric_value, # Visibility for new_rubric_value
|
| 312 |
+
add_input_btn, # Visibility for Add Input button
|
| 313 |
+
add_rubric_btn, # Visibility for Add Rubric Item button
|
| 314 |
]
|
| 315 |
)
|
| 316 |
|
|
|
|
| 323 |
example["evaluation_criteria"],
|
| 324 |
example["rubric"],
|
| 325 |
"", # Reset feedback
|
| 326 |
+
"", # Reset score
|
| 327 |
+
gr.update(visible=False), # Hide new_input_name
|
| 328 |
+
gr.update(visible=False), # Hide new_input_value
|
| 329 |
+
gr.update(visible=False), # Hide new_rubric_name
|
| 330 |
+
gr.update(visible=False), # Hide new_rubric_value
|
| 331 |
+
gr.update(visible=False), # Hide Add Input button
|
| 332 |
+
gr.update(visible=False), # Hide Add Rubric Item button
|
| 333 |
)
|
| 334 |
|
| 335 |
+
demo.launch(debug=True)
|