JoaquinVanschoren commited on
Commit
355c69f
·
1 Parent(s): 146d64e
Files changed (1) hide show
  1. app.py +13 -63
app.py CHANGED
@@ -37,57 +37,6 @@ def process_file(file):
37
 
38
  return results, report
39
 
40
- def on_validate_stream(file):
41
- results = []
42
-
43
- def add_and_yield(name, passed, message, status, progress_message=None):
44
- results.append((name, passed, message, status))
45
- html = build_results_html(results)
46
- return (
47
- gr.update(value=html, visible=True),
48
- gr.update(value=f"<div class='progress-status'>{progress_message}</div>", visible=True) if progress_message else gr.update(),
49
- gr.update(visible=False),
50
- None,
51
- None
52
- )
53
-
54
- if file is None:
55
- yield gr.update(visible=False), gr.update(value="No file selected", visible=True), gr.update(visible=False), None, None
56
- return
57
-
58
- filename = file.name.split("/")[-1]
59
-
60
- yield gr.update(visible=False), gr.update(value="<div class='progress-status'>🔍 Starting validation...</div>", visible=True), gr.update(visible=False), None, None
61
-
62
- # Step 1
63
- json_valid, json_message, json_data = validate_json(file.name)
64
- yield add_and_yield("JSON Format Validation", json_valid, json_message, "pass" if json_valid else "error", "✅ JSON check done. Checking Croissant schema...")
65
- if not json_valid:
66
- return
67
-
68
- # Step 2
69
- croissant_valid, croissant_message = validate_croissant(json_data)
70
- yield add_and_yield("Croissant Schema Validation", croissant_valid, croissant_message, "pass" if croissant_valid else "error", "✅ Croissant schema check done. Testing record generation...")
71
- if not croissant_valid:
72
- return
73
-
74
- # Step 3
75
- records_valid, records_message, records_status = validate_records(json_data)
76
- yield add_and_yield("Records Generation Test", records_valid, records_message, records_status, "✅ Record test complete.")
77
-
78
- # Generate and save report
79
- report = generate_validation_report(filename, json_data, results)
80
- report_filename = f"report_croissant-validation_{json_data.get('name', 'unnamed')}.md"
81
- with open(report_filename, "w") as f:
82
- f.write(report)
83
-
84
- # Final state
85
- yield gr.update(value=build_results_html(results), visible=True), \
86
- gr.update(visible=False), \
87
- gr.update(visible=True), \
88
- report, \
89
- report_filename
90
-
91
  def create_ui():
92
  with gr.Blocks(theme=gr.themes.Soft()) as app:
93
  gr.HTML("<p align='center'><img src='https://upload.wikimedia.org/wikipedia/en/0/08/Logo_for_Conference_on_Neural_Information_Processing_Systems.svg' alt='NeurIPS Logo' width='400'/></p>")
@@ -549,7 +498,7 @@ def create_ui():
549
  report if report else None, # report_text
550
  report_filename if report else None # report_md
551
  ]
552
-
553
  # Connect UI events to functions with updated outputs
554
  tabs.select(
555
  on_tab_change,
@@ -578,6 +527,17 @@ def create_ui():
578
  None # report_md
579
  ]
580
 
 
 
 
 
 
 
 
 
 
 
 
581
  fetch_btn.click(
582
  fetch_from_url,
583
  inputs=url_input,
@@ -590,19 +550,9 @@ def create_ui():
590
  <p>Learn more about <a href="https://github.com/mlcommons/croissant" target="_blank">Croissant</a>.</p>
591
  </div>
592
  """)
593
-
594
- def setup_events():
595
- validate_btn.click(
596
- fn=on_validate_stream,
597
- inputs=[file_input],
598
- outputs=[validation_results, validation_progress, report_group, report_text, report_md],
599
- stream=True
600
- )
601
-
602
- app.load(fn=setup_events)
603
 
604
  return app
605
 
606
  if __name__ == "__main__":
607
  app = create_ui()
608
- app.queue().launch()
 
37
 
38
  return results, report
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  def create_ui():
41
  with gr.Blocks(theme=gr.themes.Soft()) as app:
42
  gr.HTML("<p align='center'><img src='https://upload.wikimedia.org/wikipedia/en/0/08/Logo_for_Conference_on_Neural_Information_Processing_Systems.svg' alt='NeurIPS Logo' width='400'/></p>")
 
498
  report if report else None, # report_text
499
  report_filename if report else None # report_md
500
  ]
501
+
502
  # Connect UI events to functions with updated outputs
503
  tabs.select(
504
  on_tab_change,
 
527
  None # report_md
528
  ]
529
 
530
+ validate_btn.click(
531
+ fn=show_progress,
532
+ inputs=None,
533
+ outputs=[validation_results, validation_progress, report_group, report_text, report_md],
534
+ queue=False
535
+ ).then(
536
+ fn=on_validate,
537
+ inputs=file_input,
538
+ outputs=[validation_results, validation_progress, report_group, report_text, report_md]
539
+ )
540
+
541
  fetch_btn.click(
542
  fetch_from_url,
543
  inputs=url_input,
 
550
  <p>Learn more about <a href="https://github.com/mlcommons/croissant" target="_blank">Croissant</a>.</p>
551
  </div>
552
  """)
 
 
 
 
 
 
 
 
 
 
553
 
554
  return app
555
 
556
  if __name__ == "__main__":
557
  app = create_ui()
558
+ app.launch()