Spaces:
Paused
Paused
backup
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from huggingface_hub import CommitScheduler, HfApi
|
|
| 9 |
api = HfApi(token=os.environ["HF_TOKEN"])
|
| 10 |
|
| 11 |
scheduler = CommitScheduler(
|
| 12 |
-
repo_id="taesiri/
|
| 13 |
repo_type="dataset",
|
| 14 |
folder_path="./data",
|
| 15 |
path_in_repo="data",
|
|
@@ -18,27 +18,29 @@ scheduler = CommitScheduler(
|
|
| 18 |
|
| 19 |
|
| 20 |
def generate_json_files(
|
| 21 |
-
system_message,
|
| 22 |
-
# New fields
|
| 23 |
name,
|
| 24 |
email_address,
|
| 25 |
institution,
|
| 26 |
openreview_profile,
|
|
|
|
| 27 |
question_categories,
|
| 28 |
subquestion_1_text,
|
| 29 |
subquestion_1_answer,
|
| 30 |
subquestion_2_text,
|
| 31 |
subquestion_2_answer,
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
question,
|
| 34 |
final_answer,
|
| 35 |
rationale_text,
|
| 36 |
-
# Question images
|
| 37 |
image1,
|
| 38 |
image2,
|
| 39 |
image3,
|
| 40 |
image4,
|
| 41 |
-
# Rationale images
|
| 42 |
rationale_image1,
|
| 43 |
rationale_image2,
|
| 44 |
):
|
|
@@ -47,7 +49,7 @@ def generate_json_files(
|
|
| 47 |
1) Create a unique folder under ./data/
|
| 48 |
2) Copy uploaded images (question + rationale) into that folder
|
| 49 |
3) Produce two JSON files:
|
| 50 |
-
-
|
| 51 |
- request_base64.json (base64-encoded images in content)
|
| 52 |
4) Return paths to both files for Gradio to provide as download links
|
| 53 |
"""
|
|
@@ -61,10 +63,6 @@ def generate_json_files(
|
|
| 61 |
request_folder = os.path.join(parent_data_folder, request_id)
|
| 62 |
os.makedirs(request_folder)
|
| 63 |
|
| 64 |
-
# Handle defaults
|
| 65 |
-
if not system_message:
|
| 66 |
-
system_message = "You are a helpful assistant"
|
| 67 |
-
|
| 68 |
# Convert None strings
|
| 69 |
def safe_str(val):
|
| 70 |
return val if val is not None else ""
|
|
@@ -73,6 +71,7 @@ def generate_json_files(
|
|
| 73 |
email_address = safe_str(email_address)
|
| 74 |
institution = safe_str(institution)
|
| 75 |
openreview_profile = safe_str(openreview_profile)
|
|
|
|
| 76 |
# Convert question_categories to list
|
| 77 |
question_categories = (
|
| 78 |
[cat.strip() for cat in safe_str(question_categories).split(",")]
|
|
@@ -83,6 +82,12 @@ def generate_json_files(
|
|
| 83 |
subquestion_1_answer = safe_str(subquestion_1_answer)
|
| 84 |
subquestion_2_text = safe_str(subquestion_2_text)
|
| 85 |
subquestion_2_answer = safe_str(subquestion_2_answer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
question = safe_str(question)
|
| 87 |
final_answer = safe_str(final_answer)
|
| 88 |
rationale_text = safe_str(rationale_text)
|
|
@@ -117,6 +122,7 @@ def generate_json_files(
|
|
| 117 |
{"type": "field", "label": "email_address", "value": email_address},
|
| 118 |
{"type": "field", "label": "institution", "value": institution},
|
| 119 |
{"type": "field", "label": "openreview_profile", "value": openreview_profile},
|
|
|
|
| 120 |
{"type": "field", "label": "question_categories", "value": question_categories},
|
| 121 |
{"type": "field", "label": "subquestion_1_text", "value": subquestion_1_text},
|
| 122 |
{
|
|
@@ -130,27 +136,23 @@ def generate_json_files(
|
|
| 130 |
"label": "subquestion_2_answer",
|
| 131 |
"value": subquestion_2_answer,
|
| 132 |
},
|
| 133 |
-
{"type": "field", "label": "
|
| 134 |
-
{"type": "field", "label": "final_answer", "value": final_answer},
|
| 135 |
-
{"type": "field", "label": "rationale_text", "value": rationale_text},
|
| 136 |
-
]
|
| 137 |
-
content_list_base64 = [
|
| 138 |
-
{"type": "field", "label": "name", "value": name},
|
| 139 |
-
{"type": "field", "label": "email_address", "value": email_address},
|
| 140 |
-
{"type": "field", "label": "institution", "value": institution},
|
| 141 |
-
{"type": "field", "label": "openreview_profile", "value": openreview_profile},
|
| 142 |
-
{"type": "field", "label": "question_categories", "value": question_categories},
|
| 143 |
-
{"type": "field", "label": "subquestion_1_text", "value": subquestion_1_text},
|
| 144 |
{
|
| 145 |
"type": "field",
|
| 146 |
-
"label": "
|
| 147 |
-
"value":
|
| 148 |
},
|
| 149 |
-
{"type": "field", "label": "
|
| 150 |
{
|
| 151 |
"type": "field",
|
| 152 |
-
"label": "
|
| 153 |
-
"value":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
},
|
| 155 |
{"type": "field", "label": "question", "value": question},
|
| 156 |
{"type": "field", "label": "final_answer", "value": final_answer},
|
|
@@ -169,132 +171,56 @@ def generate_json_files(
|
|
| 169 |
}
|
| 170 |
)
|
| 171 |
|
| 172 |
-
# 2) Base64 version
|
| 173 |
-
with open(file_path, "rb") as f:
|
| 174 |
-
file_bytes = f.read()
|
| 175 |
-
img_b64_str = base64.b64encode(file_bytes).decode("utf-8")
|
| 176 |
-
content_list_base64.append(
|
| 177 |
-
{
|
| 178 |
-
"type": "image_url",
|
| 179 |
-
"label": img_label,
|
| 180 |
-
"image_url": {"url": {"data:image/png;base64": img_b64_str}},
|
| 181 |
-
}
|
| 182 |
-
)
|
| 183 |
-
|
| 184 |
# Build the final JSON structures for each approach
|
| 185 |
-
i = 1
|
| 186 |
-
|
| 187 |
-
assistant_content = [
|
| 188 |
-
{"type": "text", "text": rationale_text},
|
| 189 |
-
{"type": "text", "text": final_answer},
|
| 190 |
-
]
|
| 191 |
-
|
| 192 |
# A) URLs JSON
|
| 193 |
item_urls = {
|
| 194 |
-
"custom_id": f"
|
| 195 |
# Metadata at top level
|
| 196 |
-
"
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
"messages": [
|
| 203 |
-
{"role": "system", "content": system_message},
|
| 204 |
-
{
|
| 205 |
-
"role": "user",
|
| 206 |
-
"content": [
|
| 207 |
-
{"type": "text", "label": "question", "value": question}
|
| 208 |
-
]
|
| 209 |
-
+ [
|
| 210 |
-
item
|
| 211 |
-
for item in content_list_urls
|
| 212 |
-
if item.get("type") == "image_url"
|
| 213 |
-
and "question_image" in item.get("label", "")
|
| 214 |
-
],
|
| 215 |
-
},
|
| 216 |
-
],
|
| 217 |
-
},
|
| 218 |
-
"subquestions": [
|
| 219 |
-
{"text": subquestion_1_text, "answer": subquestion_1_answer},
|
| 220 |
-
{"text": subquestion_2_text, "answer": subquestion_2_answer},
|
| 221 |
-
],
|
| 222 |
-
"answer": {
|
| 223 |
-
"final_answer": final_answer,
|
| 224 |
-
"rationale_text": rationale_text,
|
| 225 |
-
"rationale_images": [
|
| 226 |
-
item
|
| 227 |
-
for item in content_list_urls
|
| 228 |
-
if item.get("type") == "image_url"
|
| 229 |
-
and "rationale_image" in item.get("label", "")
|
| 230 |
-
],
|
| 231 |
},
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
# B) Base64 JSON
|
| 235 |
-
item_base64 = {
|
| 236 |
-
"custom_id": f"request______{i}",
|
| 237 |
-
# Metadata at top level
|
| 238 |
-
"name": name,
|
| 239 |
-
"email_address": email_address,
|
| 240 |
-
"institution": institution,
|
| 241 |
-
"openreview_profile": openreview_profile,
|
| 242 |
-
# Question-related fields at top level
|
| 243 |
"question_categories": question_categories,
|
| 244 |
-
"
|
| 245 |
-
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
| 247 |
],
|
| 248 |
"final_answer": final_answer,
|
| 249 |
"rationale_text": rationale_text,
|
| 250 |
-
"
|
| 251 |
-
"
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
{
|
| 267 |
-
"role": "assistant",
|
| 268 |
-
"content": [
|
| 269 |
-
{"type": "text", "text": rationale_text},
|
| 270 |
-
{"type": "text", "text": final_answer},
|
| 271 |
-
*[
|
| 272 |
-
item
|
| 273 |
-
for item in content_list_base64
|
| 274 |
-
if item.get("type") == "image_url"
|
| 275 |
-
and "rationale_image" in item.get("label", "")
|
| 276 |
-
],
|
| 277 |
-
],
|
| 278 |
-
},
|
| 279 |
-
],
|
| 280 |
-
},
|
| 281 |
}
|
| 282 |
|
| 283 |
# Convert each to JSON line format
|
| 284 |
urls_json_line = json.dumps(item_urls, ensure_ascii=False)
|
| 285 |
-
base64_json_line = json.dumps(item_base64, ensure_ascii=False)
|
| 286 |
|
| 287 |
# 3) Write out two JSON files in request_folder
|
| 288 |
-
urls_jsonl_path = os.path.join(request_folder, "
|
| 289 |
-
base64_jsonl_path = os.path.join(request_folder, "request_base64.json")
|
| 290 |
|
| 291 |
with open(urls_jsonl_path, "w", encoding="utf-8") as f:
|
| 292 |
f.write(urls_json_line + "\n")
|
| 293 |
-
with open(base64_jsonl_path, "w", encoding="utf-8") as f:
|
| 294 |
-
f.write(base64_json_line + "\n")
|
| 295 |
|
| 296 |
-
|
| 297 |
-
return urls_jsonl_path, base64_jsonl_path
|
| 298 |
|
| 299 |
|
| 300 |
# Build the Gradio app
|
|
@@ -322,19 +248,29 @@ with gr.Blocks() as demo:
|
|
| 322 |
<li>At least <b>one question image</b></li>
|
| 323 |
<li>The <b>question text</b></li>
|
| 324 |
<li>The <b>final answer</b></li>
|
|
|
|
| 325 |
</ul>
|
| 326 |
</td>
|
| 327 |
<td style="vertical-align: top; padding: 8px; border: 1px solid #ddd;">
|
| 328 |
<ul style="margin: 0;">
|
| 329 |
-
<li>Up to
|
| 330 |
<li>Supporting images for your answer</li>
|
| 331 |
<li><b>Rationale text</b> to explain your reasoning</li>
|
| 332 |
-
<li><b>Sub-questions</b> with their answers</li>
|
| 333 |
</ul>
|
| 334 |
</td>
|
| 335 |
</tr>
|
| 336 |
</table>
|
| 337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
<p>While not all fields are mandatory, providing additional context through optional fields will help create a more comprehensive dataset. After submitting a question, you can clear up the form to submit another one.</p>
|
| 339 |
"""
|
| 340 |
)
|
|
@@ -353,6 +289,12 @@ with gr.Blocks() as demo:
|
|
| 353 |
placeholder="Your OpenReview username or profile name",
|
| 354 |
)
|
| 355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
gr.Markdown("## Question Information")
|
| 357 |
|
| 358 |
# Question Images - Individual Tabs
|
|
@@ -402,30 +344,73 @@ with gr.Blocks() as demo:
|
|
| 402 |
gr.Markdown("## Subquestions")
|
| 403 |
with gr.Row():
|
| 404 |
subquestion_1_text_input = gr.Textbox(
|
| 405 |
-
label="Subquestion 1 Text",
|
|
|
|
|
|
|
|
|
|
| 406 |
)
|
| 407 |
subquestion_1_answer_input = gr.Textbox(
|
| 408 |
label="Subquestion 1 Answer",
|
| 409 |
lines=2,
|
| 410 |
placeholder="Answer to sub-question 1...",
|
|
|
|
| 411 |
)
|
| 412 |
|
| 413 |
with gr.Row():
|
| 414 |
subquestion_2_text_input = gr.Textbox(
|
| 415 |
-
label="Subquestion 2 Text",
|
|
|
|
|
|
|
|
|
|
| 416 |
)
|
| 417 |
subquestion_2_answer_input = gr.Textbox(
|
| 418 |
label="Subquestion 2 Answer",
|
| 419 |
lines=2,
|
| 420 |
placeholder="Answer to sub-question 2...",
|
|
|
|
| 421 |
)
|
| 422 |
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
|
| 430 |
with gr.Row():
|
| 431 |
submit_button = gr.Button("Submit")
|
|
@@ -441,16 +426,22 @@ with gr.Blocks() as demo:
|
|
| 441 |
|
| 442 |
# On Submit, we call generate_json_files with all relevant fields
|
| 443 |
def validate_and_generate(
|
| 444 |
-
sys_msg,
|
| 445 |
nm,
|
| 446 |
em,
|
| 447 |
inst,
|
| 448 |
orp,
|
|
|
|
| 449 |
qcats,
|
| 450 |
sq1t,
|
| 451 |
sq1a,
|
| 452 |
sq2t,
|
| 453 |
sq2a,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
q,
|
| 455 |
fa,
|
| 456 |
rt,
|
|
@@ -475,6 +466,16 @@ with gr.Blocks() as demo:
|
|
| 475 |
missing_fields.append("Final Answer")
|
| 476 |
if not i1:
|
| 477 |
missing_fields.append("First Question Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
|
| 479 |
# If any required fields are missing, return a warning and keep all fields as is
|
| 480 |
if missing_fields:
|
|
@@ -485,16 +486,22 @@ with gr.Blocks() as demo:
|
|
| 485 |
|
| 486 |
# Only after successful validation, generate files but keep all fields
|
| 487 |
results = generate_json_files(
|
| 488 |
-
sys_msg,
|
| 489 |
nm,
|
| 490 |
em,
|
| 491 |
inst,
|
| 492 |
orp,
|
|
|
|
| 493 |
qcats,
|
| 494 |
sq1t,
|
| 495 |
sq1a,
|
| 496 |
sq2t,
|
| 497 |
sq2a,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
q,
|
| 499 |
fa,
|
| 500 |
rt,
|
|
@@ -515,16 +522,22 @@ with gr.Blocks() as demo:
|
|
| 515 |
submit_button.click(
|
| 516 |
fn=validate_and_generate,
|
| 517 |
inputs=[
|
| 518 |
-
system_message_input,
|
| 519 |
name_input,
|
| 520 |
email_address_input,
|
| 521 |
institution_input,
|
| 522 |
openreview_profile_input,
|
|
|
|
| 523 |
question_categories_input,
|
| 524 |
subquestion_1_text_input,
|
| 525 |
subquestion_1_answer_input,
|
| 526 |
subquestion_2_text_input,
|
| 527 |
subquestion_2_answer_input,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
question_input,
|
| 529 |
final_answer_input,
|
| 530 |
rationale_text_input,
|
|
@@ -539,22 +552,29 @@ with gr.Blocks() as demo:
|
|
| 539 |
)
|
| 540 |
|
| 541 |
# Clear button functionality
|
| 542 |
-
def clear_form_fields(
|
| 543 |
-
# Preserve personal info fields
|
|
|
|
| 544 |
return [
|
| 545 |
-
"You are a helpful assistant", # Reset system message to default
|
| 546 |
name, # Preserve name
|
| 547 |
email, # Preserve email
|
| 548 |
inst, # Preserve institution
|
| 549 |
-
openreview, # Preserve
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
None, # Clear image1
|
| 559 |
None, # Clear image2
|
| 560 |
None, # Clear image3
|
|
@@ -562,30 +582,35 @@ with gr.Blocks() as demo:
|
|
| 562 |
None, # Clear rationale image1
|
| 563 |
None, # Clear rationale image2
|
| 564 |
None, # Clear output file urls
|
| 565 |
-
|
| 566 |
-
gr.update(interactive=True), # Re-enable submit button
|
| 567 |
]
|
| 568 |
|
| 569 |
clear_button.click(
|
| 570 |
fn=clear_form_fields,
|
| 571 |
inputs=[
|
| 572 |
-
system_message_input,
|
| 573 |
name_input,
|
| 574 |
email_address_input,
|
| 575 |
institution_input,
|
| 576 |
openreview_profile_input,
|
|
|
|
| 577 |
],
|
| 578 |
outputs=[
|
| 579 |
-
system_message_input,
|
| 580 |
name_input,
|
| 581 |
email_address_input,
|
| 582 |
institution_input,
|
| 583 |
openreview_profile_input,
|
|
|
|
| 584 |
question_categories_input,
|
| 585 |
subquestion_1_text_input,
|
| 586 |
subquestion_1_answer_input,
|
| 587 |
subquestion_2_text_input,
|
| 588 |
subquestion_2_answer_input,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 589 |
question_input,
|
| 590 |
final_answer_input,
|
| 591 |
rationale_text_input,
|
|
@@ -596,7 +621,6 @@ with gr.Blocks() as demo:
|
|
| 596 |
rationale_image1,
|
| 597 |
rationale_image2,
|
| 598 |
output_file_urls,
|
| 599 |
-
output_file_base64,
|
| 600 |
submit_button,
|
| 601 |
],
|
| 602 |
)
|
|
|
|
| 9 |
api = HfApi(token=os.environ["HF_TOKEN"])
|
| 10 |
|
| 11 |
scheduler = CommitScheduler(
|
| 12 |
+
repo_id="taesiri/zb_dataset_storage",
|
| 13 |
repo_type="dataset",
|
| 14 |
folder_path="./data",
|
| 15 |
path_in_repo="data",
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
def generate_json_files(
|
|
|
|
|
|
|
| 21 |
name,
|
| 22 |
email_address,
|
| 23 |
institution,
|
| 24 |
openreview_profile,
|
| 25 |
+
authorship_interest,
|
| 26 |
question_categories,
|
| 27 |
subquestion_1_text,
|
| 28 |
subquestion_1_answer,
|
| 29 |
subquestion_2_text,
|
| 30 |
subquestion_2_answer,
|
| 31 |
+
subquestion_3_text,
|
| 32 |
+
subquestion_3_answer,
|
| 33 |
+
subquestion_4_text,
|
| 34 |
+
subquestion_4_answer,
|
| 35 |
+
subquestion_5_text,
|
| 36 |
+
subquestion_5_answer,
|
| 37 |
question,
|
| 38 |
final_answer,
|
| 39 |
rationale_text,
|
|
|
|
| 40 |
image1,
|
| 41 |
image2,
|
| 42 |
image3,
|
| 43 |
image4,
|
|
|
|
| 44 |
rationale_image1,
|
| 45 |
rationale_image2,
|
| 46 |
):
|
|
|
|
| 49 |
1) Create a unique folder under ./data/
|
| 50 |
2) Copy uploaded images (question + rationale) into that folder
|
| 51 |
3) Produce two JSON files:
|
| 52 |
+
- question.json (local file paths in content)
|
| 53 |
- request_base64.json (base64-encoded images in content)
|
| 54 |
4) Return paths to both files for Gradio to provide as download links
|
| 55 |
"""
|
|
|
|
| 63 |
request_folder = os.path.join(parent_data_folder, request_id)
|
| 64 |
os.makedirs(request_folder)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
# Convert None strings
|
| 67 |
def safe_str(val):
|
| 68 |
return val if val is not None else ""
|
|
|
|
| 71 |
email_address = safe_str(email_address)
|
| 72 |
institution = safe_str(institution)
|
| 73 |
openreview_profile = safe_str(openreview_profile)
|
| 74 |
+
authorship_interest = safe_str(authorship_interest)
|
| 75 |
# Convert question_categories to list
|
| 76 |
question_categories = (
|
| 77 |
[cat.strip() for cat in safe_str(question_categories).split(",")]
|
|
|
|
| 82 |
subquestion_1_answer = safe_str(subquestion_1_answer)
|
| 83 |
subquestion_2_text = safe_str(subquestion_2_text)
|
| 84 |
subquestion_2_answer = safe_str(subquestion_2_answer)
|
| 85 |
+
subquestion_3_text = safe_str(subquestion_3_text)
|
| 86 |
+
subquestion_3_answer = safe_str(subquestion_3_answer)
|
| 87 |
+
subquestion_4_text = safe_str(subquestion_4_text)
|
| 88 |
+
subquestion_4_answer = safe_str(subquestion_4_answer)
|
| 89 |
+
subquestion_5_text = safe_str(subquestion_5_text)
|
| 90 |
+
subquestion_5_answer = safe_str(subquestion_5_answer)
|
| 91 |
question = safe_str(question)
|
| 92 |
final_answer = safe_str(final_answer)
|
| 93 |
rationale_text = safe_str(rationale_text)
|
|
|
|
| 122 |
{"type": "field", "label": "email_address", "value": email_address},
|
| 123 |
{"type": "field", "label": "institution", "value": institution},
|
| 124 |
{"type": "field", "label": "openreview_profile", "value": openreview_profile},
|
| 125 |
+
{"type": "field", "label": "authorship_interest", "value": authorship_interest},
|
| 126 |
{"type": "field", "label": "question_categories", "value": question_categories},
|
| 127 |
{"type": "field", "label": "subquestion_1_text", "value": subquestion_1_text},
|
| 128 |
{
|
|
|
|
| 136 |
"label": "subquestion_2_answer",
|
| 137 |
"value": subquestion_2_answer,
|
| 138 |
},
|
| 139 |
+
{"type": "field", "label": "subquestion_3_text", "value": subquestion_3_text},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
{
|
| 141 |
"type": "field",
|
| 142 |
+
"label": "subquestion_3_answer",
|
| 143 |
+
"value": subquestion_3_answer,
|
| 144 |
},
|
| 145 |
+
{"type": "field", "label": "subquestion_4_text", "value": subquestion_4_text},
|
| 146 |
{
|
| 147 |
"type": "field",
|
| 148 |
+
"label": "subquestion_4_answer",
|
| 149 |
+
"value": subquestion_4_answer,
|
| 150 |
+
},
|
| 151 |
+
{"type": "field", "label": "subquestion_5_text", "value": subquestion_5_text},
|
| 152 |
+
{
|
| 153 |
+
"type": "field",
|
| 154 |
+
"label": "subquestion_5_answer",
|
| 155 |
+
"value": subquestion_5_answer,
|
| 156 |
},
|
| 157 |
{"type": "field", "label": "question", "value": question},
|
| 158 |
{"type": "field", "label": "final_answer", "value": final_answer},
|
|
|
|
| 171 |
}
|
| 172 |
)
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
# Build the final JSON structures for each approach
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
# A) URLs JSON
|
| 176 |
item_urls = {
|
| 177 |
+
"custom_id": f"question___{request_id}",
|
| 178 |
# Metadata at top level
|
| 179 |
+
"author_info": {
|
| 180 |
+
"name": name,
|
| 181 |
+
"email_address": email_address,
|
| 182 |
+
"institution": institution,
|
| 183 |
+
"openreview_profile": openreview_profile,
|
| 184 |
+
"authorship_interest": authorship_interest,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
"question_categories": question_categories,
|
| 187 |
+
"question": question,
|
| 188 |
+
"question_images": [
|
| 189 |
+
item["image_url"]["url"]["data:image/png;path"]
|
| 190 |
+
for item in content_list_urls
|
| 191 |
+
if item.get("type") == "image_url"
|
| 192 |
+
and "question_image" in item.get("label", "")
|
| 193 |
],
|
| 194 |
"final_answer": final_answer,
|
| 195 |
"rationale_text": rationale_text,
|
| 196 |
+
"rationale_images": [
|
| 197 |
+
item["image_url"]["url"]["data:image/png;path"]
|
| 198 |
+
for item in content_list_urls
|
| 199 |
+
if item.get("type") == "image_url"
|
| 200 |
+
and "rationale_image" in item.get("label", "")
|
| 201 |
+
],
|
| 202 |
+
"subquestions_1_text": subquestion_1_text,
|
| 203 |
+
"subquestions_1_answer": subquestion_1_answer,
|
| 204 |
+
"subquestions_2_text": subquestion_2_text,
|
| 205 |
+
"subquestions_2_answer": subquestion_2_answer,
|
| 206 |
+
"subquestions_3_text": subquestion_3_text,
|
| 207 |
+
"subquestions_3_answer": subquestion_3_answer,
|
| 208 |
+
"subquestions_4_text": subquestion_4_text,
|
| 209 |
+
"subquestions_4_answer": subquestion_4_answer,
|
| 210 |
+
"subquestions_5_text": subquestion_5_text,
|
| 211 |
+
"subquestions_5_answer": subquestion_5_answer,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
}
|
| 213 |
|
| 214 |
# Convert each to JSON line format
|
| 215 |
urls_json_line = json.dumps(item_urls, ensure_ascii=False)
|
|
|
|
| 216 |
|
| 217 |
# 3) Write out two JSON files in request_folder
|
| 218 |
+
urls_jsonl_path = os.path.join(request_folder, "question.json")
|
|
|
|
| 219 |
|
| 220 |
with open(urls_jsonl_path, "w", encoding="utf-8") as f:
|
| 221 |
f.write(urls_json_line + "\n")
|
|
|
|
|
|
|
| 222 |
|
| 223 |
+
return urls_jsonl_path
|
|
|
|
| 224 |
|
| 225 |
|
| 226 |
# Build the Gradio app
|
|
|
|
| 248 |
<li>At least <b>one question image</b></li>
|
| 249 |
<li>The <b>question text</b></li>
|
| 250 |
<li>The <b>final answer</b></li>
|
| 251 |
+
<li><b>Sub-questions</b> with their answers (write 'N/A' if breaking into steps is not reasonable - please use sparingly)</li>
|
| 252 |
</ul>
|
| 253 |
</td>
|
| 254 |
<td style="vertical-align: top; padding: 8px; border: 1px solid #ddd;">
|
| 255 |
<ul style="margin: 0;">
|
| 256 |
+
<li>Up to three additional question images</li>
|
| 257 |
<li>Supporting images for your answer</li>
|
| 258 |
<li><b>Rationale text</b> to explain your reasoning</li>
|
|
|
|
| 259 |
</ul>
|
| 260 |
</td>
|
| 261 |
</tr>
|
| 262 |
</table>
|
| 263 |
|
| 264 |
+
<h3>Question Criteria:</h3>
|
| 265 |
+
<ul>
|
| 266 |
+
<li>Make questions as challenging as possible. At a minimum, obtaining the correct answer needs to be beyond the capabilities of state-of-the-art large multimodal models.</li>
|
| 267 |
+
<li>Structure your questions to require multiple steps/sub-questions to reach the final answer (e.g., identifying/counting specific objects in the image or requiring a particular piece of knowledge) — this will likely enable better differentiation of model performance.</li>
|
| 268 |
+
<li>Include images/questions that are not copyright-restricted.</li>
|
| 269 |
+
</ul>
|
| 270 |
+
|
| 271 |
+
<h3>Authorship Opportunity:</h3>
|
| 272 |
+
<p>Would you like to be included as an author on our paper? Authorship is offered to anyone submitting 5 or more difficult questions!</p>
|
| 273 |
+
|
| 274 |
<p>While not all fields are mandatory, providing additional context through optional fields will help create a more comprehensive dataset. After submitting a question, you can clear up the form to submit another one.</p>
|
| 275 |
"""
|
| 276 |
)
|
|
|
|
| 289 |
placeholder="Your OpenReview username or profile name",
|
| 290 |
)
|
| 291 |
|
| 292 |
+
# Add authorship checkbox
|
| 293 |
+
authorship_input = gr.Checkbox(
|
| 294 |
+
label="Would you like to be considered for authorship? (Requires submitting 5+ difficult questions)",
|
| 295 |
+
value=False,
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
gr.Markdown("## Question Information")
|
| 299 |
|
| 300 |
# Question Images - Individual Tabs
|
|
|
|
| 344 |
gr.Markdown("## Subquestions")
|
| 345 |
with gr.Row():
|
| 346 |
subquestion_1_text_input = gr.Textbox(
|
| 347 |
+
label="Subquestion 1 Text",
|
| 348 |
+
lines=2,
|
| 349 |
+
placeholder="First sub-question...",
|
| 350 |
+
value="N/A",
|
| 351 |
)
|
| 352 |
subquestion_1_answer_input = gr.Textbox(
|
| 353 |
label="Subquestion 1 Answer",
|
| 354 |
lines=2,
|
| 355 |
placeholder="Answer to sub-question 1...",
|
| 356 |
+
value="N/A",
|
| 357 |
)
|
| 358 |
|
| 359 |
with gr.Row():
|
| 360 |
subquestion_2_text_input = gr.Textbox(
|
| 361 |
+
label="Subquestion 2 Text",
|
| 362 |
+
lines=2,
|
| 363 |
+
placeholder="Second sub-question...",
|
| 364 |
+
value="N/A",
|
| 365 |
)
|
| 366 |
subquestion_2_answer_input = gr.Textbox(
|
| 367 |
label="Subquestion 2 Answer",
|
| 368 |
lines=2,
|
| 369 |
placeholder="Answer to sub-question 2...",
|
| 370 |
+
value="N/A",
|
| 371 |
)
|
| 372 |
|
| 373 |
+
with gr.Row():
|
| 374 |
+
subquestion_3_text_input = gr.Textbox(
|
| 375 |
+
label="Subquestion 3 Text",
|
| 376 |
+
lines=2,
|
| 377 |
+
placeholder="Third sub-question...",
|
| 378 |
+
value="N/A",
|
| 379 |
+
)
|
| 380 |
+
subquestion_3_answer_input = gr.Textbox(
|
| 381 |
+
label="Subquestion 3 Answer",
|
| 382 |
+
lines=2,
|
| 383 |
+
placeholder="Answer to sub-question 3...",
|
| 384 |
+
value="N/A",
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
with gr.Row():
|
| 388 |
+
subquestion_4_text_input = gr.Textbox(
|
| 389 |
+
label="Subquestion 4 Text",
|
| 390 |
+
lines=2,
|
| 391 |
+
placeholder="Fourth sub-question...",
|
| 392 |
+
value="N/A",
|
| 393 |
+
)
|
| 394 |
+
subquestion_4_answer_input = gr.Textbox(
|
| 395 |
+
label="Subquestion 4 Answer",
|
| 396 |
+
lines=2,
|
| 397 |
+
placeholder="Answer to sub-question 4...",
|
| 398 |
+
value="N/A",
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
with gr.Row():
|
| 402 |
+
subquestion_5_text_input = gr.Textbox(
|
| 403 |
+
label="Subquestion 5 Text",
|
| 404 |
+
lines=2,
|
| 405 |
+
placeholder="Fifth sub-question...",
|
| 406 |
+
value="N/A",
|
| 407 |
+
)
|
| 408 |
+
subquestion_5_answer_input = gr.Textbox(
|
| 409 |
+
label="Subquestion 5 Answer",
|
| 410 |
+
lines=2,
|
| 411 |
+
placeholder="Answer to sub-question 5...",
|
| 412 |
+
value="N/A",
|
| 413 |
+
)
|
| 414 |
|
| 415 |
with gr.Row():
|
| 416 |
submit_button = gr.Button("Submit")
|
|
|
|
| 426 |
|
| 427 |
# On Submit, we call generate_json_files with all relevant fields
|
| 428 |
def validate_and_generate(
|
|
|
|
| 429 |
nm,
|
| 430 |
em,
|
| 431 |
inst,
|
| 432 |
orp,
|
| 433 |
+
auth,
|
| 434 |
qcats,
|
| 435 |
sq1t,
|
| 436 |
sq1a,
|
| 437 |
sq2t,
|
| 438 |
sq2a,
|
| 439 |
+
sq3t,
|
| 440 |
+
sq3a,
|
| 441 |
+
sq4t,
|
| 442 |
+
sq4a,
|
| 443 |
+
sq5t,
|
| 444 |
+
sq5a,
|
| 445 |
q,
|
| 446 |
fa,
|
| 447 |
rt,
|
|
|
|
| 466 |
missing_fields.append("Final Answer")
|
| 467 |
if not i1:
|
| 468 |
missing_fields.append("First Question Image")
|
| 469 |
+
if not sq1t or not sq1t.strip() or not sq1a or not sq1a.strip():
|
| 470 |
+
missing_fields.append("First Sub-question and Answer")
|
| 471 |
+
if not sq2t or not sq2t.strip() or not sq2a or not sq2a.strip():
|
| 472 |
+
missing_fields.append("Second Sub-question and Answer")
|
| 473 |
+
if not sq3t or not sq3t.strip() or not sq3a or not sq3a.strip():
|
| 474 |
+
missing_fields.append("Third Sub-question and Answer")
|
| 475 |
+
if not sq4t or not sq4t.strip() or not sq4a or not sq4a.strip():
|
| 476 |
+
missing_fields.append("Fourth Sub-question and Answer")
|
| 477 |
+
if not sq5t or not sq5t.strip() or not sq5a or not sq5a.strip():
|
| 478 |
+
missing_fields.append("Fifth Sub-question and Answer")
|
| 479 |
|
| 480 |
# If any required fields are missing, return a warning and keep all fields as is
|
| 481 |
if missing_fields:
|
|
|
|
| 486 |
|
| 487 |
# Only after successful validation, generate files but keep all fields
|
| 488 |
results = generate_json_files(
|
|
|
|
| 489 |
nm,
|
| 490 |
em,
|
| 491 |
inst,
|
| 492 |
orp,
|
| 493 |
+
auth,
|
| 494 |
qcats,
|
| 495 |
sq1t,
|
| 496 |
sq1a,
|
| 497 |
sq2t,
|
| 498 |
sq2a,
|
| 499 |
+
sq3t,
|
| 500 |
+
sq3a,
|
| 501 |
+
sq4t,
|
| 502 |
+
sq4a,
|
| 503 |
+
sq5t,
|
| 504 |
+
sq5a,
|
| 505 |
q,
|
| 506 |
fa,
|
| 507 |
rt,
|
|
|
|
| 522 |
submit_button.click(
|
| 523 |
fn=validate_and_generate,
|
| 524 |
inputs=[
|
|
|
|
| 525 |
name_input,
|
| 526 |
email_address_input,
|
| 527 |
institution_input,
|
| 528 |
openreview_profile_input,
|
| 529 |
+
authorship_input,
|
| 530 |
question_categories_input,
|
| 531 |
subquestion_1_text_input,
|
| 532 |
subquestion_1_answer_input,
|
| 533 |
subquestion_2_text_input,
|
| 534 |
subquestion_2_answer_input,
|
| 535 |
+
subquestion_3_text_input,
|
| 536 |
+
subquestion_3_answer_input,
|
| 537 |
+
subquestion_4_text_input,
|
| 538 |
+
subquestion_4_answer_input,
|
| 539 |
+
subquestion_5_text_input,
|
| 540 |
+
subquestion_5_answer_input,
|
| 541 |
question_input,
|
| 542 |
final_answer_input,
|
| 543 |
rationale_text_input,
|
|
|
|
| 552 |
)
|
| 553 |
|
| 554 |
# Clear button functionality
|
| 555 |
+
def clear_form_fields(name, email, inst, openreview, authorship, *args):
|
| 556 |
+
# Preserve personal info fields and re-enable submit button
|
| 557 |
+
gr.Info("Form cleared! Ready for new submission 🔄")
|
| 558 |
return [
|
|
|
|
| 559 |
name, # Preserve name
|
| 560 |
email, # Preserve email
|
| 561 |
inst, # Preserve institution
|
| 562 |
+
openreview, # Preserve openreview
|
| 563 |
+
authorship, # Preserve authorship interest
|
| 564 |
+
gr.update(value=""), # Clear question categories
|
| 565 |
+
gr.update(value="N/A"), # Reset subquestion 1 text to N/A
|
| 566 |
+
gr.update(value="N/A"), # Reset subquestion 1 answer to N/A
|
| 567 |
+
gr.update(value="N/A"), # Reset subquestion 2 text to N/A
|
| 568 |
+
gr.update(value="N/A"), # Reset subquestion 2 answer to N/A
|
| 569 |
+
gr.update(value="N/A"), # Reset subquestion 3 text to N/A
|
| 570 |
+
gr.update(value="N/A"), # Reset subquestion 3 answer to N/A
|
| 571 |
+
gr.update(value="N/A"), # Reset subquestion 4 text to N/A
|
| 572 |
+
gr.update(value="N/A"), # Reset subquestion 4 answer to N/A
|
| 573 |
+
gr.update(value="N/A"), # Reset subquestion 5 text to N/A
|
| 574 |
+
gr.update(value="N/A"), # Reset subquestion 5 answer to N/A
|
| 575 |
+
gr.update(value=""), # Clear question
|
| 576 |
+
gr.update(value=""), # Clear final answer
|
| 577 |
+
gr.update(value=""), # Clear rationale text
|
| 578 |
None, # Clear image1
|
| 579 |
None, # Clear image2
|
| 580 |
None, # Clear image3
|
|
|
|
| 582 |
None, # Clear rationale image1
|
| 583 |
None, # Clear rationale image2
|
| 584 |
None, # Clear output file urls
|
| 585 |
+
gr.Button(interactive=True), # Re-enable submit button
|
|
|
|
| 586 |
]
|
| 587 |
|
| 588 |
clear_button.click(
|
| 589 |
fn=clear_form_fields,
|
| 590 |
inputs=[
|
|
|
|
| 591 |
name_input,
|
| 592 |
email_address_input,
|
| 593 |
institution_input,
|
| 594 |
openreview_profile_input,
|
| 595 |
+
authorship_input,
|
| 596 |
],
|
| 597 |
outputs=[
|
|
|
|
| 598 |
name_input,
|
| 599 |
email_address_input,
|
| 600 |
institution_input,
|
| 601 |
openreview_profile_input,
|
| 602 |
+
authorship_input,
|
| 603 |
question_categories_input,
|
| 604 |
subquestion_1_text_input,
|
| 605 |
subquestion_1_answer_input,
|
| 606 |
subquestion_2_text_input,
|
| 607 |
subquestion_2_answer_input,
|
| 608 |
+
subquestion_3_text_input,
|
| 609 |
+
subquestion_3_answer_input,
|
| 610 |
+
subquestion_4_text_input,
|
| 611 |
+
subquestion_4_answer_input,
|
| 612 |
+
subquestion_5_text_input,
|
| 613 |
+
subquestion_5_answer_input,
|
| 614 |
question_input,
|
| 615 |
final_answer_input,
|
| 616 |
rationale_text_input,
|
|
|
|
| 621 |
rationale_image1,
|
| 622 |
rationale_image2,
|
| 623 |
output_file_urls,
|
|
|
|
| 624 |
submit_button,
|
| 625 |
],
|
| 626 |
)
|