Spaces:
Running
Running
report
Browse files
app.py
CHANGED
@@ -70,19 +70,23 @@ def create_ui():
|
|
70 |
with gr.Group():
|
71 |
# Validation results
|
72 |
validation_results = gr.HTML(visible=False)
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
86 |
# Define CSS for the validation UI
|
87 |
gr.HTML("""
|
88 |
<style>
|
@@ -180,6 +184,32 @@ def create_ui():
|
|
180 |
.arrow-down {
|
181 |
transform: rotate(90deg);
|
182 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
</style>
|
184 |
""")
|
185 |
|
@@ -281,32 +311,73 @@ def create_ui():
|
|
281 |
|
282 |
def on_validate(file):
|
283 |
if file is None:
|
284 |
-
return [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
|
286 |
# Process the file and get results
|
287 |
results, report = process_file(file)
|
288 |
|
289 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
if report:
|
291 |
-
|
292 |
-
with open(report_path, "w") as f:
|
293 |
f.write(report)
|
294 |
|
|
|
295 |
return [
|
296 |
-
build_results_html(results),
|
297 |
-
gr.update(visible=
|
298 |
-
gr.update(visible=True
|
|
|
|
|
299 |
]
|
300 |
|
301 |
# Connect UI events to functions
|
302 |
tabs.select(on_tab_change, None, [active_tab, upload_progress, validation_results])
|
303 |
-
file_input.change(
|
|
|
|
|
|
|
|
|
304 |
validate_btn.click(
|
305 |
on_validate,
|
306 |
inputs=file_input,
|
307 |
-
outputs=[validation_results, report_text, report_md]
|
|
|
|
|
|
|
|
|
|
|
308 |
)
|
309 |
-
fetch_btn.click(fetch_from_url, inputs=url_input, outputs=[upload_progress, validation_results])
|
310 |
|
311 |
# Footer
|
312 |
gr.HTML("""
|
|
|
70 |
with gr.Group():
|
71 |
# Validation results
|
72 |
validation_results = gr.HTML(visible=False)
|
73 |
+
validation_progress = gr.HTML(visible=False)
|
74 |
+
|
75 |
+
# Collapsible report section
|
76 |
+
with gr.Accordion("Full validation report as markdown file", visible=False) as report_group:
|
77 |
+
with gr.Column():
|
78 |
+
report_md = gr.File(
|
79 |
+
label="Download Report",
|
80 |
+
visible=True,
|
81 |
+
file_types=[".md"]
|
82 |
+
)
|
83 |
+
report_text = gr.Textbox(
|
84 |
+
label="Report Content",
|
85 |
+
visible=True,
|
86 |
+
show_copy_button=True,
|
87 |
+
lines=10
|
88 |
+
)
|
89 |
+
|
90 |
# Define CSS for the validation UI
|
91 |
gr.HTML("""
|
92 |
<style>
|
|
|
184 |
.arrow-down {
|
185 |
transform: rotate(90deg);
|
186 |
}
|
187 |
+
|
188 |
+
/* Loading animation */
|
189 |
+
.loading-spinner {
|
190 |
+
display: inline-block;
|
191 |
+
width: 20px;
|
192 |
+
height: 20px;
|
193 |
+
border: 3px solid rgba(0, 0, 0, 0.1);
|
194 |
+
border-radius: 50%;
|
195 |
+
border-top-color: var(--primary-500);
|
196 |
+
animation: spin 1s ease-in-out infinite;
|
197 |
+
margin-right: 10px;
|
198 |
+
}
|
199 |
+
|
200 |
+
@keyframes spin {
|
201 |
+
to { transform: rotate(360deg); }
|
202 |
+
}
|
203 |
+
|
204 |
+
.validation-progress {
|
205 |
+
display: flex;
|
206 |
+
align-items: center;
|
207 |
+
justify-content: center;
|
208 |
+
padding: 10px;
|
209 |
+
margin: 10px 0;
|
210 |
+
background-color: var(--background-fill-secondary);
|
211 |
+
border-radius: 8px;
|
212 |
+
}
|
213 |
</style>
|
214 |
""")
|
215 |
|
|
|
311 |
|
312 |
def on_validate(file):
|
313 |
if file is None:
|
314 |
+
return [
|
315 |
+
gr.update(visible=False), # validation_results
|
316 |
+
gr.update(visible=False), # validation_progress
|
317 |
+
gr.update(visible=False), # report_group
|
318 |
+
None, # report_text
|
319 |
+
None # report_md
|
320 |
+
]
|
321 |
+
|
322 |
+
# Show progress indicator
|
323 |
+
progress_html = """
|
324 |
+
<div class="validation-progress">
|
325 |
+
<div class="loading-spinner"></div>
|
326 |
+
<span>Validating file...</span>
|
327 |
+
</div>
|
328 |
+
"""
|
329 |
+
|
330 |
+
yield [
|
331 |
+
gr.update(visible=False), # validation_results
|
332 |
+
gr.update(visible=True, value=progress_html), # validation_progress
|
333 |
+
gr.update(visible=False), # report_group
|
334 |
+
None, # report_text
|
335 |
+
None # report_md
|
336 |
+
]
|
337 |
|
338 |
# Process the file and get results
|
339 |
results, report = process_file(file)
|
340 |
|
341 |
+
# Extract dataset name from the JSON for the report filename
|
342 |
+
try:
|
343 |
+
with open(file.name, 'r') as f:
|
344 |
+
json_data = json.load(f)
|
345 |
+
dataset_name = json_data.get('name', 'unnamed')
|
346 |
+
except:
|
347 |
+
dataset_name = 'unnamed'
|
348 |
+
|
349 |
+
# Save report to file with new naming convention
|
350 |
+
report_filename = f"report_croissant-validation_{dataset_name}.md"
|
351 |
if report:
|
352 |
+
with open(report_filename, "w") as f:
|
|
|
353 |
f.write(report)
|
354 |
|
355 |
+
# Return final state
|
356 |
return [
|
357 |
+
build_results_html(results), # validation_results
|
358 |
+
gr.update(visible=False), # validation_progress
|
359 |
+
gr.update(visible=True) if report else gr.update(visible=False), # report_group
|
360 |
+
report if report else None, # report_text
|
361 |
+
report_filename if report else None # report_md
|
362 |
]
|
363 |
|
364 |
# Connect UI events to functions
|
365 |
tabs.select(on_tab_change, None, [active_tab, upload_progress, validation_results])
|
366 |
+
file_input.change(
|
367 |
+
on_file_upload,
|
368 |
+
inputs=file_input,
|
369 |
+
outputs=[upload_progress, validation_results]
|
370 |
+
)
|
371 |
validate_btn.click(
|
372 |
on_validate,
|
373 |
inputs=file_input,
|
374 |
+
outputs=[validation_results, validation_progress, report_group, report_text, report_md]
|
375 |
+
)
|
376 |
+
fetch_btn.click(
|
377 |
+
fetch_from_url,
|
378 |
+
inputs=url_input,
|
379 |
+
outputs=[upload_progress, validation_results]
|
380 |
)
|
|
|
381 |
|
382 |
# Footer
|
383 |
gr.HTML("""
|