Spaces:
Sleeping
Sleeping
Update challenges/vqa/validate.py
Browse files- challenges/vqa/validate.py +24 -0
challenges/vqa/validate.py
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Tuple
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def validate_submission(obj: Any) -> Tuple[bool, str]:
|
| 5 |
+
"""Validate VQA Answer Therapy submission format."""
|
| 6 |
+
if not isinstance(obj, list):
|
| 7 |
+
return False, "Submission must be a JSON list of result objects."
|
| 8 |
+
if len(obj) == 0:
|
| 9 |
+
return False, "Submission list is empty."
|
| 10 |
+
for i, item in enumerate(obj):
|
| 11 |
+
if not isinstance(item, dict):
|
| 12 |
+
return False, f"Entry at index {i} must be a JSON object."
|
| 13 |
+
if "image" not in item:
|
| 14 |
+
return False, f"Entry at index {i} missing 'image'."
|
| 15 |
+
if "answer" not in item:
|
| 16 |
+
return False, f"Entry at index {i} missing 'answer'."
|
| 17 |
+
# if not isinstance(item["question_id"], str):
|
| 18 |
+
# return False, f"'question_id' at index {i} must be a string."
|
| 19 |
+
# sg = item["single_grounding"]
|
| 20 |
+
# if not isinstance(sg, (int, float)):
|
| 21 |
+
# return False, f"'single_grounding' at index {i} must be a float (0=multiple, 1=single)."
|
| 22 |
+
# if not (0.0 <= float(sg) <= 1.0):
|
| 23 |
+
# return False, f"'single_grounding' at index {i} must be between 0.0 and 1.0."
|
| 24 |
+
return True, "OK"
|