Spaces:
Running
Running
download results
Browse files- app.py +39 -8
- validation.py +52 -1
app.py
CHANGED
@@ -7,30 +7,34 @@ import requests
|
|
7 |
|
8 |
def process_file(file):
|
9 |
results = []
|
|
|
10 |
|
11 |
# Check 1: JSON validation
|
12 |
json_valid, json_message, json_data = validate_json(file.name)
|
13 |
results.append(("JSON Format Validation", json_valid, json_message))
|
14 |
|
15 |
if not json_valid:
|
16 |
-
return results
|
17 |
|
18 |
# Check 2: Croissant validation
|
19 |
croissant_valid, croissant_message = validate_croissant(json_data)
|
20 |
results.append(("Croissant Schema Validation", croissant_valid, croissant_message))
|
21 |
|
22 |
if not croissant_valid:
|
23 |
-
return results
|
24 |
|
25 |
# Check 3: Records validation
|
26 |
records_valid, records_message = validate_records(json_data)
|
27 |
results.append(("Records Generation Test", records_valid, records_message))
|
28 |
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
def create_ui():
|
32 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
33 |
-
gr.Markdown("# ππ₯ Croissant
|
34 |
gr.Markdown("""
|
35 |
Upload your Croissant JSON-LD file or enter a URL to validate if it meets the requirements for NeurIPS submission.
|
36 |
The validator will check:
|
@@ -66,6 +70,18 @@ def create_ui():
|
|
66 |
with gr.Group():
|
67 |
# Validation results
|
68 |
validation_results = gr.HTML(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
# Define CSS for the validation UI
|
71 |
gr.HTML("""
|
@@ -256,16 +272,31 @@ def create_ui():
|
|
256 |
|
257 |
def on_validate(file):
|
258 |
if file is None:
|
259 |
-
return gr.update(visible=False)
|
260 |
|
261 |
# Process the file and get results
|
262 |
-
results = process_file(file)
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
# Connect UI events to functions
|
266 |
tabs.select(on_tab_change, None, [active_tab, upload_progress, validation_results])
|
267 |
file_input.change(on_file_upload, inputs=file_input, outputs=[upload_progress, validation_results])
|
268 |
-
validate_btn.click(
|
|
|
|
|
|
|
|
|
269 |
fetch_btn.click(fetch_from_url, inputs=url_input, outputs=[upload_progress, validation_results])
|
270 |
|
271 |
# Footer
|
|
|
7 |
|
8 |
def process_file(file):
|
9 |
results = []
|
10 |
+
json_data = None
|
11 |
|
12 |
# Check 1: JSON validation
|
13 |
json_valid, json_message, json_data = validate_json(file.name)
|
14 |
results.append(("JSON Format Validation", json_valid, json_message))
|
15 |
|
16 |
if not json_valid:
|
17 |
+
return results, None
|
18 |
|
19 |
# Check 2: Croissant validation
|
20 |
croissant_valid, croissant_message = validate_croissant(json_data)
|
21 |
results.append(("Croissant Schema Validation", croissant_valid, croissant_message))
|
22 |
|
23 |
if not croissant_valid:
|
24 |
+
return results, None
|
25 |
|
26 |
# Check 3: Records validation
|
27 |
records_valid, records_message = validate_records(json_data)
|
28 |
results.append(("Records Generation Test", records_valid, records_message))
|
29 |
|
30 |
+
# Generate detailed report
|
31 |
+
report = generate_validation_report(file.name, json_data, results)
|
32 |
+
|
33 |
+
return results, report
|
34 |
|
35 |
def create_ui():
|
36 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
37 |
+
gr.Markdown("# ππ₯ Croissant Validator for NeurIPS D&B")
|
38 |
gr.Markdown("""
|
39 |
Upload your Croissant JSON-LD file or enter a URL to validate if it meets the requirements for NeurIPS submission.
|
40 |
The validator will check:
|
|
|
70 |
with gr.Group():
|
71 |
# Validation results
|
72 |
validation_results = gr.HTML(visible=False)
|
73 |
+
with gr.Row():
|
74 |
+
report_text = gr.Textbox(
|
75 |
+
label="Detailed Report",
|
76 |
+
visible=False,
|
77 |
+
show_copy_button=True,
|
78 |
+
lines=10
|
79 |
+
)
|
80 |
+
report_md = gr.File(
|
81 |
+
label="Download Report",
|
82 |
+
visible=False,
|
83 |
+
file_types=[".md"]
|
84 |
+
)
|
85 |
|
86 |
# Define CSS for the validation UI
|
87 |
gr.HTML("""
|
|
|
272 |
|
273 |
def on_validate(file):
|
274 |
if file is None:
|
275 |
+
return [gr.update(visible=False)] * 3
|
276 |
|
277 |
# Process the file and get results
|
278 |
+
results, report = process_file(file)
|
279 |
+
|
280 |
+
# Save report to file
|
281 |
+
if report:
|
282 |
+
report_path = "validation_report.md"
|
283 |
+
with open(report_path, "w") as f:
|
284 |
+
f.write(report)
|
285 |
+
|
286 |
+
return [
|
287 |
+
build_results_html(results),
|
288 |
+
gr.update(visible=True, value=report) if report else gr.update(visible=False),
|
289 |
+
gr.update(visible=True, value="validation_report.md") if report else gr.update(visible=False)
|
290 |
+
]
|
291 |
|
292 |
# Connect UI events to functions
|
293 |
tabs.select(on_tab_change, None, [active_tab, upload_progress, validation_results])
|
294 |
file_input.change(on_file_upload, inputs=file_input, outputs=[upload_progress, validation_results])
|
295 |
+
validate_btn.click(
|
296 |
+
on_validate,
|
297 |
+
inputs=file_input,
|
298 |
+
outputs=[validation_results, report_text, report_md]
|
299 |
+
)
|
300 |
fetch_btn.click(fetch_from_url, inputs=url_input, outputs=[upload_progress, validation_results])
|
301 |
|
302 |
# Footer
|
validation.py
CHANGED
@@ -61,4 +61,55 @@ def validate_records(json_data):
|
|
61 |
except Exception as e:
|
62 |
error_details = traceback.format_exc()
|
63 |
error_message = f"β Unexpected error during records validation: {str(e)}\n\n{error_details}"
|
64 |
-
return False, error_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
except Exception as e:
|
62 |
error_details = traceback.format_exc()
|
63 |
error_message = f"β Unexpected error during records validation: {str(e)}\n\n{error_details}"
|
64 |
+
return False, error_message
|
65 |
+
|
66 |
+
def generate_validation_report(file_path, json_data, validation_results):
|
67 |
+
"""Generate a detailed markdown report of the validation results."""
|
68 |
+
report = []
|
69 |
+
|
70 |
+
# Header
|
71 |
+
report.append("# CROISSANT VALIDATION REPORT")
|
72 |
+
report.append("=" * 80)
|
73 |
+
report.append("")
|
74 |
+
|
75 |
+
# Validation Results Section
|
76 |
+
report.append("## VALIDATION RESULTS")
|
77 |
+
report.append("-" * 80)
|
78 |
+
report.append(f"Starting validation for file: {file_path}")
|
79 |
+
|
80 |
+
# Process each validation step
|
81 |
+
for step_name, passed, message in validation_results:
|
82 |
+
report.append("")
|
83 |
+
report.append(f"### {step_name}")
|
84 |
+
report.append("β" if passed else "β")
|
85 |
+
report.append(message.replace("β
", "β").replace("β", "β"))
|
86 |
+
|
87 |
+
# Add extra details for record sets if available
|
88 |
+
if step_name == "Records Generation Test" and json_data:
|
89 |
+
try:
|
90 |
+
dataset = mlc.Dataset(jsonld=json_data)
|
91 |
+
for record_set in dataset.metadata.record_sets:
|
92 |
+
report.append("")
|
93 |
+
report.append(f"#### Record Set: {record_set.uuid}")
|
94 |
+
report.append(f"Description: {record_set.description}")
|
95 |
+
if record_set.data_types:
|
96 |
+
report.append(f"Data Types: {record_set.data_types}")
|
97 |
+
report.append("")
|
98 |
+
report.append("Fields:")
|
99 |
+
for field in record_set.fields:
|
100 |
+
report.append(f"- {field.name} ({field.data_type})")
|
101 |
+
if field.description:
|
102 |
+
report.append(f" Description: {field.description}")
|
103 |
+
except Exception as e:
|
104 |
+
report.append(f"Error getting record set details: {str(e)}")
|
105 |
+
|
106 |
+
# JSON-LD Reference Section
|
107 |
+
report.append("")
|
108 |
+
report.append("## JSON-LD REFERENCE")
|
109 |
+
report.append("=" * 80)
|
110 |
+
report.append("")
|
111 |
+
report.append("```json")
|
112 |
+
report.append(json.dumps(json_data, indent=2))
|
113 |
+
report.append("```")
|
114 |
+
|
115 |
+
return "\n".join(report)
|