Spaces:
Sleeping
Sleeping
small fixes for the ui cosmetics
Browse files
app.py
CHANGED
|
@@ -39,28 +39,29 @@ def create_ui():
|
|
| 39 |
3. If records can be generated within a reasonable time
|
| 40 |
""")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
with gr.Tabs() as tabs:
|
| 43 |
-
with gr.TabItem("Upload File"):
|
| 44 |
file_input = gr.File(label="Upload Croissant JSON-LD File", file_types=[".json", ".jsonld"])
|
|
|
|
| 45 |
|
| 46 |
-
with gr.TabItem("URL Input"):
|
| 47 |
url_input = gr.Textbox(
|
| 48 |
label="Enter Croissant JSON-LD URL",
|
| 49 |
-
placeholder="https://huggingface.co/api/datasets/facebook/natural_reasoning/croissant"
|
| 50 |
)
|
| 51 |
fetch_btn = gr.Button("Fetch and Validate", variant="primary")
|
| 52 |
|
| 53 |
-
|
| 54 |
-
"""<div class="progress-container">
|
| 55 |
-
<div class="progress-status">Ready for validation</div>
|
| 56 |
-
</div>""", visible=True)
|
| 57 |
-
|
| 58 |
-
validate_btn = gr.Button("Validate Uploaded File", variant="primary")
|
| 59 |
-
|
| 60 |
-
# Create containers for validation results
|
| 61 |
-
validation_results = gr.HTML(visible=False)
|
| 62 |
-
|
| 63 |
-
# Define CSS for the validation UI
|
| 64 |
gr.HTML("""
|
| 65 |
<style>
|
| 66 |
.gradio-container {
|
|
@@ -69,13 +70,13 @@ def create_ui():
|
|
| 69 |
}
|
| 70 |
.validation-step {
|
| 71 |
margin-bottom: 15px;
|
| 72 |
-
border: 1px solid #e0e0e0;
|
| 73 |
border-radius: 8px;
|
| 74 |
overflow: hidden;
|
| 75 |
}
|
| 76 |
.step-header {
|
| 77 |
padding: 10px 15px;
|
| 78 |
-
background-color: #f5f5f5;
|
| 79 |
display: flex;
|
| 80 |
align-items: center;
|
| 81 |
cursor: pointer;
|
|
@@ -115,9 +116,39 @@ def create_ui():
|
|
| 115 |
.status-waiting {
|
| 116 |
background-color: #9e9e9e;
|
| 117 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
</style>
|
| 119 |
""")
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
def on_file_upload(file):
|
| 122 |
if file is None:
|
| 123 |
return """<div class="progress-container">
|
|
@@ -137,9 +168,7 @@ def create_ui():
|
|
| 137 |
try:
|
| 138 |
# Fetch JSON from URL
|
| 139 |
response = requests.get(url, timeout=10)
|
| 140 |
-
response.raise_for_status()
|
| 141 |
-
|
| 142 |
-
# Try to parse as JSON
|
| 143 |
json_data = response.json()
|
| 144 |
|
| 145 |
# Show success message
|
|
@@ -149,18 +178,14 @@ def create_ui():
|
|
| 149 |
|
| 150 |
# Validate the fetched JSON
|
| 151 |
results = []
|
| 152 |
-
|
| 153 |
-
# Check 1: JSON validation (already done by parsing)
|
| 154 |
results.append(("JSON Format Validation", True, "✅ The URL returned valid JSON."))
|
| 155 |
|
| 156 |
-
# Check 2: Croissant validation
|
| 157 |
croissant_valid, croissant_message = validate_croissant(json_data)
|
| 158 |
results.append(("Croissant Schema Validation", croissant_valid, croissant_message))
|
| 159 |
|
| 160 |
if not croissant_valid:
|
| 161 |
return progress_html, build_results_html(results)
|
| 162 |
|
| 163 |
-
# Check 3: Records validation
|
| 164 |
records_valid, records_message = validate_records(json_data)
|
| 165 |
results.append(("Records Generation Test", records_valid, records_message))
|
| 166 |
|
|
@@ -183,7 +208,7 @@ def create_ui():
|
|
| 183 |
</div>""", gr.update(visible=False)
|
| 184 |
|
| 185 |
def build_results_html(results):
|
| 186 |
-
#
|
| 187 |
html = '<div class="validation-results">'
|
| 188 |
|
| 189 |
for i, (test_name, passed, message) in enumerate(results):
|
|
@@ -226,6 +251,7 @@ def create_ui():
|
|
| 226 |
return build_results_html(results)
|
| 227 |
|
| 228 |
# Connect UI events to functions
|
|
|
|
| 229 |
file_input.change(on_file_upload, inputs=file_input, outputs=[upload_progress, validation_results])
|
| 230 |
validate_btn.click(on_validate, inputs=file_input, outputs=validation_results)
|
| 231 |
fetch_btn.click(fetch_from_url, inputs=url_input, outputs=[upload_progress, validation_results])
|
|
@@ -233,7 +259,7 @@ def create_ui():
|
|
| 233 |
# Footer
|
| 234 |
gr.HTML("""
|
| 235 |
<div style="text-align: center; margin-top: 20px;">
|
| 236 |
-
<p>
|
| 237 |
</div>
|
| 238 |
""")
|
| 239 |
|
|
|
|
| 39 |
3. If records can be generated within a reasonable time
|
| 40 |
""")
|
| 41 |
|
| 42 |
+
# Create containers for validation results - moved up for cleaner flow
|
| 43 |
+
validation_results = gr.HTML(visible=False)
|
| 44 |
+
upload_progress = gr.HTML(
|
| 45 |
+
"""<div class="progress-container">
|
| 46 |
+
<div class="progress-status">Ready for validation</div>
|
| 47 |
+
</div>""", visible=True)
|
| 48 |
+
|
| 49 |
+
# Track the active tab for conditional UI updates
|
| 50 |
+
active_tab = gr.State("upload") # Default to upload tab
|
| 51 |
+
|
| 52 |
with gr.Tabs() as tabs:
|
| 53 |
+
with gr.TabItem("Upload File", id="upload_tab"):
|
| 54 |
file_input = gr.File(label="Upload Croissant JSON-LD File", file_types=[".json", ".jsonld"])
|
| 55 |
+
validate_btn = gr.Button("Validate Uploaded File", variant="primary")
|
| 56 |
|
| 57 |
+
with gr.TabItem("URL Input", id="url_tab"):
|
| 58 |
url_input = gr.Textbox(
|
| 59 |
label="Enter Croissant JSON-LD URL",
|
| 60 |
+
placeholder="e.g. https://huggingface.co/api/datasets/facebook/natural_reasoning/croissant"
|
| 61 |
)
|
| 62 |
fetch_btn = gr.Button("Fetch and Validate", variant="primary")
|
| 63 |
|
| 64 |
+
# Define CSS for the validation UI - improved for dark mode compatibility
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
gr.HTML("""
|
| 66 |
<style>
|
| 67 |
.gradio-container {
|
|
|
|
| 70 |
}
|
| 71 |
.validation-step {
|
| 72 |
margin-bottom: 15px;
|
| 73 |
+
border: 1px solid var(--border-color-primary, #e0e0e0);
|
| 74 |
border-radius: 8px;
|
| 75 |
overflow: hidden;
|
| 76 |
}
|
| 77 |
.step-header {
|
| 78 |
padding: 10px 15px;
|
| 79 |
+
background-color: var(--background-fill-secondary, #f5f5f5);
|
| 80 |
display: flex;
|
| 81 |
align-items: center;
|
| 82 |
cursor: pointer;
|
|
|
|
| 116 |
.status-waiting {
|
| 117 |
background-color: #9e9e9e;
|
| 118 |
}
|
| 119 |
+
/* Dark mode specific styles */
|
| 120 |
+
.dark .step-header {
|
| 121 |
+
background-color: var(--background-fill-secondary, #2e2e2e);
|
| 122 |
+
color: var(--body-text-color, #ffffff);
|
| 123 |
+
}
|
| 124 |
+
.dark .step-title {
|
| 125 |
+
color: var(--body-text-color, #ffffff);
|
| 126 |
+
}
|
| 127 |
+
.dark .step-details {
|
| 128 |
+
color: var(--body-text-color, #ffffff);
|
| 129 |
+
background-color: var(--background-fill-primary, #1f1f1f);
|
| 130 |
+
padding: 10px 15px;
|
| 131 |
+
}
|
| 132 |
+
/* Add this to ensure details are also styled for light mode */
|
| 133 |
+
.step-details {
|
| 134 |
+
padding: 10px 15px;
|
| 135 |
+
background-color: var(--background-fill-primary, #ffffff);
|
| 136 |
+
}
|
| 137 |
</style>
|
| 138 |
""")
|
| 139 |
|
| 140 |
+
# Update helper messages based on tab changes
|
| 141 |
+
def on_tab_change(evt: gr.SelectData):
|
| 142 |
+
tab_id = evt.value
|
| 143 |
+
if tab_id == "Upload File":
|
| 144 |
+
return "upload", """<div class="progress-container">
|
| 145 |
+
<div class="progress-status">Ready for upload</div>
|
| 146 |
+
</div>""", gr.update(visible=False)
|
| 147 |
+
else:
|
| 148 |
+
return "url", """<div class="progress-container">
|
| 149 |
+
<div class="progress-status">Enter a URL to fetch</div>
|
| 150 |
+
</div>""", gr.update(visible=False)
|
| 151 |
+
|
| 152 |
def on_file_upload(file):
|
| 153 |
if file is None:
|
| 154 |
return """<div class="progress-container">
|
|
|
|
| 168 |
try:
|
| 169 |
# Fetch JSON from URL
|
| 170 |
response = requests.get(url, timeout=10)
|
| 171 |
+
response.raise_for_status()
|
|
|
|
|
|
|
| 172 |
json_data = response.json()
|
| 173 |
|
| 174 |
# Show success message
|
|
|
|
| 178 |
|
| 179 |
# Validate the fetched JSON
|
| 180 |
results = []
|
|
|
|
|
|
|
| 181 |
results.append(("JSON Format Validation", True, "✅ The URL returned valid JSON."))
|
| 182 |
|
|
|
|
| 183 |
croissant_valid, croissant_message = validate_croissant(json_data)
|
| 184 |
results.append(("Croissant Schema Validation", croissant_valid, croissant_message))
|
| 185 |
|
| 186 |
if not croissant_valid:
|
| 187 |
return progress_html, build_results_html(results)
|
| 188 |
|
|
|
|
| 189 |
records_valid, records_message = validate_records(json_data)
|
| 190 |
results.append(("Records Generation Test", records_valid, records_message))
|
| 191 |
|
|
|
|
| 208 |
</div>""", gr.update(visible=False)
|
| 209 |
|
| 210 |
def build_results_html(results):
|
| 211 |
+
# Build validation results HTML
|
| 212 |
html = '<div class="validation-results">'
|
| 213 |
|
| 214 |
for i, (test_name, passed, message) in enumerate(results):
|
|
|
|
| 251 |
return build_results_html(results)
|
| 252 |
|
| 253 |
# Connect UI events to functions
|
| 254 |
+
tabs.select(on_tab_change, None, [active_tab, upload_progress, validation_results])
|
| 255 |
file_input.change(on_file_upload, inputs=file_input, outputs=[upload_progress, validation_results])
|
| 256 |
validate_btn.click(on_validate, inputs=file_input, outputs=validation_results)
|
| 257 |
fetch_btn.click(fetch_from_url, inputs=url_input, outputs=[upload_progress, validation_results])
|
|
|
|
| 259 |
# Footer
|
| 260 |
gr.HTML("""
|
| 261 |
<div style="text-align: center; margin-top: 20px;">
|
| 262 |
+
<p>Learn more about <a href="https://github.com/mlcommons/croissant" target="_blank">Croissant format</a>.</p>
|
| 263 |
</div>
|
| 264 |
""")
|
| 265 |
|