Spaces:
Sleeping
Sleeping
Results-site look and a dataset picker (leCop 36a2709)
Browse files- README.md +4 -2
- app.py +150 -25
- lecop_space.py +84 -20
README.md
CHANGED
|
@@ -13,8 +13,10 @@ short_description: Fast health checks for LeRobot datasets on the Hub
|
|
| 13 |
|
| 14 |
# leCop on a Hub dataset
|
| 15 |
|
| 16 |
-
|
| 17 |
-
[
|
|
|
|
|
|
|
| 18 |
|
| 19 |
- The Space downloads `meta/` and `data/` only, so the video checks are skipped. Run `lecop validate` locally on a
|
| 20 |
full download to check the videos too.
|
|
|
|
| 13 |
|
| 14 |
# leCop on a Hub dataset
|
| 15 |
|
| 16 |
+
Pick a public LeRobot dataset on the Hub and get [leCop](https://github.com/michele-xilo/lecop)'s report, grouped by
|
| 17 |
+
issue code in the look of the [results site](https://michele-xilo.github.io/leCop/). The dataset box filters the 2,000
|
| 18 |
+
most downloaded datasets the Hub tags LeRobot (gated ones left out) plus those on the results site; any other
|
| 19 |
+
`owner/name`, `owner/name@revision` or Hub URL can be typed in full.
|
| 20 |
|
| 21 |
- The Space downloads `meta/` and `data/` only, so the video checks are skipped. Run `lecop validate` locally on a
|
| 22 |
full download to check the videos too.
|
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""A Hugging Face Space:
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
@@ -6,17 +6,34 @@ import json
|
|
| 6 |
import os
|
| 7 |
import subprocess
|
| 8 |
import tempfile
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
import gradio as gr
|
| 12 |
from huggingface_hub import HfApi, snapshot_download
|
| 13 |
from huggingface_hub.utils import GatedRepoError, HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
|
| 14 |
|
| 15 |
import lecop
|
| 16 |
-
from lecop_space import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
CAP_BYTES = int(os.environ.get("LECOP_SPACE_MAX_BYTES", 2_000_000_000))
|
| 19 |
VALIDATE_TIMEOUT_S = int(os.environ.get("LECOP_SPACE_TIMEOUT_S", 300))
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Without a token the Space reads only what an anonymous visitor can; a token set on the Space must not leak into
|
| 22 |
# downloads of gated or private repos.
|
|
@@ -28,11 +45,38 @@ def lecop_version() -> str:
|
|
| 28 |
return run.stdout.strip().split()[-1] if run.returncode == 0 else "?"
|
| 29 |
|
| 30 |
|
| 31 |
-
def
|
| 32 |
-
"""
|
| 33 |
try:
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
try:
|
| 37 |
info = api.dataset_info(repo, revision=revision, files_metadata=True)
|
| 38 |
except GatedRepoError:
|
|
@@ -42,11 +86,13 @@ def check(text: str, revision_text: str = "") -> Tuple[str, Optional[dict]]:
|
|
| 42 |
except RepositoryNotFoundError:
|
| 43 |
raise Refused(f"No public dataset `{repo}` on the Hub (it may be private).")
|
| 44 |
refuse_access(info.private, info.gated)
|
| 45 |
-
files,
|
|
|
|
| 46 |
with tempfile.TemporaryDirectory() as root:
|
| 47 |
snapshot_download(
|
| 48 |
repo, repo_type="dataset", revision=info.sha, local_dir=root, allow_patterns=files, token=False
|
| 49 |
)
|
|
|
|
| 50 |
run = subprocess.run(
|
| 51 |
[lecop._binary(), "validate", "--format", "json", "--isolated", "--ignore", ",".join(VIDEO_CODES), root],
|
| 52 |
capture_output=True,
|
|
@@ -56,32 +102,111 @@ def check(text: str, revision_text: str = "") -> Tuple[str, Optional[dict]]:
|
|
| 56 |
if not run.stdout.strip():
|
| 57 |
raise Refused(f"leCop gave no report: {run.stderr.strip() or f'exit code {run.returncode}'}")
|
| 58 |
report = json.loads(run.stdout)
|
| 59 |
-
return
|
| 60 |
except Refused as e:
|
| 61 |
-
return
|
| 62 |
except subprocess.TimeoutExpired:
|
| 63 |
-
return f"
|
| 64 |
except HfHubHTTPError as e:
|
| 65 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
with gr.Blocks(title="leCop: check a LeRobot dataset") as demo:
|
| 69 |
-
gr.
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
| 78 |
button = gr.Button("Check", variant="primary")
|
| 79 |
-
|
|
|
|
| 80 |
with gr.Accordion("JSON report", open=False):
|
| 81 |
raw = gr.JSON()
|
| 82 |
-
gr.
|
| 83 |
button.click(check, inputs=[repo_box, rev_box], outputs=[page, raw], concurrency_limit=2)
|
| 84 |
-
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
-
demo.launch()
|
|
|
|
| 1 |
+
"""A Hugging Face Space: pick a public Hub dataset and get leCop's report on its metadata and data."""
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
| 6 |
import os
|
| 7 |
import subprocess
|
| 8 |
import tempfile
|
| 9 |
+
import urllib.request
|
| 10 |
+
from typing import List, Optional, Tuple
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
from huggingface_hub import HfApi, snapshot_download
|
| 14 |
from huggingface_hub.utils import GatedRepoError, HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
|
| 15 |
|
| 16 |
import lecop
|
| 17 |
+
from lecop_space import (
|
| 18 |
+
CHECKS_URL,
|
| 19 |
+
SITE_URL,
|
| 20 |
+
VIDEO_CODES,
|
| 21 |
+
Refused,
|
| 22 |
+
human_size,
|
| 23 |
+
notice_html,
|
| 24 |
+
parse_repo,
|
| 25 |
+
plan_download,
|
| 26 |
+
refuse_access,
|
| 27 |
+
dataset_choices,
|
| 28 |
+
render_html,
|
| 29 |
+
site_page,
|
| 30 |
+
)
|
| 31 |
|
| 32 |
CAP_BYTES = int(os.environ.get("LECOP_SPACE_MAX_BYTES", 2_000_000_000))
|
| 33 |
VALIDATE_TIMEOUT_S = int(os.environ.get("LECOP_SPACE_TIMEOUT_S", 300))
|
| 34 |
+
REPO_URL = "https://github.com/michele-xilo/lecop"
|
| 35 |
+
LOGO_URL = "https://raw.githubusercontent.com/michele-xilo/leCop/main/assets/logo.png"
|
| 36 |
+
EXAMPLES = ["lerobot/pusht", "lerobot/aloha_sim_insertion_human", "lerobot/svla_so100_pickplace"]
|
| 37 |
|
| 38 |
# Without a token the Space reads only what an anonymous visitor can; a token set on the Space must not leak into
|
| 39 |
# downloads of gated or private repos.
|
|
|
|
| 45 |
return run.stdout.strip().split()[-1] if run.returncode == 0 else "?"
|
| 46 |
|
| 47 |
|
| 48 |
+
def site_index() -> list:
|
| 49 |
+
"""The results site's list of datasets, or an empty list when the site cannot be reached."""
|
| 50 |
try:
|
| 51 |
+
with urllib.request.urlopen(f"{SITE_URL}/index.json", timeout=5) as r:
|
| 52 |
+
return json.load(r)
|
| 53 |
+
except (OSError, ValueError):
|
| 54 |
+
return []
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def lerobot_datasets(limit: int) -> List[str]:
|
| 58 |
+
"""Public, ungated datasets the Hub tags as LeRobot, most downloaded first."""
|
| 59 |
+
try:
|
| 60 |
+
found = api.list_datasets(filter="LeRobot", sort="downloads", limit=limit)
|
| 61 |
+
return [d.id for d in found if not d.private and not d.gated]
|
| 62 |
+
except HfHubHTTPError:
|
| 63 |
+
return []
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
VERSION = lecop_version()
|
| 67 |
+
SITE_INDEX = site_index()
|
| 68 |
+
# The dropdown filters its choices in the browser as you type, so it gets one list loaded at startup rather than a
|
| 69 |
+
# Hub search per keystroke (which Gradio shows a keystroke late). 2,000 names load in about 1.5 s; any other dataset
|
| 70 |
+
# can still be typed in full.
|
| 71 |
+
CHOICES = dataset_choices(lerobot_datasets(2000), SITE_INDEX)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def check(text: Optional[str], revision_text: str = "", progress=gr.Progress()) -> Tuple[str, Optional[dict]]:
|
| 75 |
+
"""Validate a Hub dataset; return the report page and the raw report (None when there is none)."""
|
| 76 |
+
try:
|
| 77 |
+
repo, revision = parse_repo(text or "")
|
| 78 |
+
revision = (revision_text or "").strip() or revision or "main"
|
| 79 |
+
progress(0, desc="Reading the file list from the Hub")
|
| 80 |
try:
|
| 81 |
info = api.dataset_info(repo, revision=revision, files_metadata=True)
|
| 82 |
except GatedRepoError:
|
|
|
|
| 86 |
except RepositoryNotFoundError:
|
| 87 |
raise Refused(f"No public dataset `{repo}` on the Hub (it may be private).")
|
| 88 |
refuse_access(info.private, info.gated)
|
| 89 |
+
files, total = plan_download(((s.rfilename, s.size) for s in info.siblings or []), CAP_BYTES)
|
| 90 |
+
progress(0.2, desc=f"Downloading meta/ and data/: {len(files):,} files, {human_size(total)}")
|
| 91 |
with tempfile.TemporaryDirectory() as root:
|
| 92 |
snapshot_download(
|
| 93 |
repo, repo_type="dataset", revision=info.sha, local_dir=root, allow_patterns=files, token=False
|
| 94 |
)
|
| 95 |
+
progress(0.9, desc="Running leCop")
|
| 96 |
run = subprocess.run(
|
| 97 |
[lecop._binary(), "validate", "--format", "json", "--isolated", "--ignore", ",".join(VIDEO_CODES), root],
|
| 98 |
capture_output=True,
|
|
|
|
| 102 |
if not run.stdout.strip():
|
| 103 |
raise Refused(f"leCop gave no report: {run.stderr.strip() or f'exit code {run.returncode}'}")
|
| 104 |
report = json.loads(run.stdout)
|
| 105 |
+
return render_html(repo, info.sha, report, VERSION, site_page(repo, SITE_INDEX)), report
|
| 106 |
except Refused as e:
|
| 107 |
+
return notice_html(str(e)), None
|
| 108 |
except subprocess.TimeoutExpired:
|
| 109 |
+
return notice_html(f"leCop took longer than {VALIDATE_TIMEOUT_S} s on this dataset; run it locally."), None
|
| 110 |
except HfHubHTTPError as e:
|
| 111 |
+
return notice_html(f"The Hub answered with an error: {e}"), None
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
GITHUB_MARK = (
|
| 115 |
+
'<svg width="20" height="20" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 '
|
| 116 |
+
"3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28"
|
| 117 |
+
"-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87"
|
| 118 |
+
".31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 4 0c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08"
|
| 119 |
+
" 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01"
|
| 120 |
+
' 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>'
|
| 121 |
+
)
|
| 122 |
+
HEADER = (
|
| 123 |
+
f'<div class="lc-top"><a class="lc-brand" href="{REPO_URL}" target="_blank"><img src="{LOGO_URL}" alt="">leCop</a>'
|
| 124 |
+
f'<span class="lc-grow"></span><a href="{SITE_URL}/" target="_blank">Results</a>'
|
| 125 |
+
f'<a href="{CHECKS_URL}" target="_blank">Checks</a>'
|
| 126 |
+
f'<a href="{REPO_URL}" target="_blank" aria-label="GitHub">{GITHUB_MARK}</a></div>'
|
| 127 |
+
'<p class="lc-lede">Find the broken episodes in a <a class="lc-link" href="https://github.com/huggingface/lerobot" '
|
| 128 |
+
'target="_blank">LeRobot</a> dataset before they cost you a training run. Pick a public dataset on the Hub: the Space '
|
| 129 |
+
"downloads its <code>meta/</code> and <code>data/</code> folders (no videos) and runs <code>lecop validate</code>.</p>"
|
| 130 |
+
)
|
| 131 |
+
FOOTER = (
|
| 132 |
+
'<p class="lc-fine">On your own machine, with the video checks: <code>uvx lecop path/to/dataset</code>. '
|
| 133 |
+
"Public, ungated datasets only, up to "
|
| 134 |
+
f"{human_size(CAP_BYTES)} of <code>meta/</code> and <code>data/</code>. leCop is unofficial and not affiliated with "
|
| 135 |
+
f'Hugging Face or LeRobot. <a class="lc-link" href="{REPO_URL}/issues/new?template=wrong-finding.yml" '
|
| 136 |
+
'target="_blank">Report a wrong finding</a></p>'
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
# The results site's palette (GitHub's), with the logo's orange as the accent.
|
| 140 |
+
CSS = """
|
| 141 |
+
:root{--lc-ok:#1a7f37;--lc-warn:#9a6700;--lc-err:#cf222e;--lc-link:#0969da;--lc-accent:#b64605}
|
| 142 |
+
.dark{--lc-ok:#3fb950;--lc-warn:#d29922;--lc-err:#f85149;--lc-link:#4493f8}
|
| 143 |
+
.gradio-container{max-width:880px!important;margin:0 auto!important}
|
| 144 |
+
.lc-top{display:flex;align-items:center;gap:16px;padding:4px 0 12px;border-bottom:1px solid var(--border-color-primary)}
|
| 145 |
+
.lc-top a{color:var(--body-text-color-subdued);text-decoration:none;display:flex;align-items:center}
|
| 146 |
+
.lc-top a:hover{color:var(--body-text-color)}
|
| 147 |
+
.lc-top .lc-brand{gap:10px;font-size:18px;font-weight:600;color:var(--body-text-color)}
|
| 148 |
+
.lc-top img{width:32px;height:32px;border-radius:50%}
|
| 149 |
+
.lc-grow{flex-grow:1}
|
| 150 |
+
.lc-lede{margin:16px 0 4px;color:var(--body-text-color-subdued)}
|
| 151 |
+
.lc-link,.lc-report a{color:var(--lc-link)!important;text-decoration:none;padding:0!important}
|
| 152 |
+
.lc-mono,.lc-find{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
|
| 153 |
+
.lc-muted{color:var(--body-text-color-subdued)}
|
| 154 |
+
.lc-small{font-size:12px}
|
| 155 |
+
.lc-title{margin:8px 0 4px!important;font-size:22px;font-weight:600;overflow-wrap:anywhere}
|
| 156 |
+
.lc-report .lc-mono.lc-muted{font-size:12px;overflow-wrap:anywhere}
|
| 157 |
+
.lc-strip{display:flex;gap:16px;margin:16px 0 0;padding:12px 0;border-top:1px solid var(--border-color-primary);border-bottom:1px solid var(--border-color-primary)}
|
| 158 |
+
.lc-big{font-size:18px;font-weight:600;display:flex;gap:16px}
|
| 159 |
+
.lc-error{color:var(--lc-err)}.lc-warning{color:var(--lc-warn)}.lc-clean{color:var(--lc-ok)}
|
| 160 |
+
.lc-note{margin:12px 0 24px;font-size:13px;color:var(--body-text-color-subdued)}
|
| 161 |
+
.lc-group{margin:0 0 20px}
|
| 162 |
+
.lc-ghead{display:flex;align-items:center;gap:8px}
|
| 163 |
+
.lc-ghead strong{font-size:14px}
|
| 164 |
+
.lc-dot{width:8px;height:8px;border-radius:50%;flex:none}
|
| 165 |
+
.lc-dot.lc-error{background:var(--lc-err)}.lc-dot.lc-warning{background:var(--lc-warn)}
|
| 166 |
+
.lc-find{margin:2px 0 0 16px;font-size:12px;overflow-wrap:anywhere}
|
| 167 |
+
.lc-find .lc-muted{margin-right:8px}
|
| 168 |
+
.lc-more{margin:4px 0 0 16px;font-size:12px;color:var(--body-text-color-subdued)}
|
| 169 |
+
.lc-more summary{cursor:pointer;width:max-content}
|
| 170 |
+
.lc-more .lc-find{margin-left:0}
|
| 171 |
+
.lc-notice{padding:12px 14px;border:1px solid var(--border-color-primary);border-left:3px solid var(--lc-accent);border-radius:6px}
|
| 172 |
+
.lc-fine{margin-top:24px;font-size:12px;color:var(--body-text-color-subdued)}
|
| 173 |
+
"""
|
| 174 |
|
| 175 |
+
THEME = gr.themes.Base(
|
| 176 |
+
primary_hue="orange",
|
| 177 |
+
neutral_hue="gray",
|
| 178 |
+
font=["-apple-system", "BlinkMacSystemFont", "Segoe UI", "Noto Sans", "Helvetica", "Arial", "sans-serif"],
|
| 179 |
+
font_mono=["ui-monospace", "SFMono-Regular", "Menlo", "Consolas", "monospace"],
|
| 180 |
+
).set(
|
| 181 |
+
button_primary_background_fill="#b64605",
|
| 182 |
+
button_primary_background_fill_hover="#9a3b04",
|
| 183 |
+
button_primary_background_fill_dark="#b64605",
|
| 184 |
+
button_primary_background_fill_hover_dark="#d0560c",
|
| 185 |
+
button_primary_text_color="#ffffff",
|
| 186 |
+
button_primary_text_color_dark="#ffffff",
|
| 187 |
+
)
|
| 188 |
|
| 189 |
with gr.Blocks(title="leCop: check a LeRobot dataset") as demo:
|
| 190 |
+
gr.HTML(HEADER)
|
| 191 |
+
with gr.Row(equal_height=True):
|
| 192 |
+
repo_box = gr.Dropdown(
|
| 193 |
+
choices=CHOICES,
|
| 194 |
+
value=None,
|
| 195 |
+
label="Dataset",
|
| 196 |
+
info=f"Type to filter {len(CHOICES):,} LeRobot datasets on the Hub, most downloaded first. Any other owner/name works too.",
|
| 197 |
+
allow_custom_value=True,
|
| 198 |
+
filterable=True,
|
| 199 |
+
scale=4,
|
| 200 |
+
)
|
| 201 |
+
rev_box = gr.Textbox(label="Revision", placeholder="main", info="Branch, tag or commit.", scale=1)
|
| 202 |
button = gr.Button("Check", variant="primary")
|
| 203 |
+
examples = gr.Examples([[e] for e in EXAMPLES], inputs=[repo_box], label="Or try one from the results site")
|
| 204 |
+
page = gr.HTML()
|
| 205 |
with gr.Accordion("JSON report", open=False):
|
| 206 |
raw = gr.JSON()
|
| 207 |
+
gr.HTML(FOOTER)
|
| 208 |
button.click(check, inputs=[repo_box, rev_box], outputs=[page, raw], concurrency_limit=2)
|
| 209 |
+
examples.load_input_event.then(check, inputs=[repo_box, rev_box], outputs=[page, raw], concurrency_limit=2)
|
| 210 |
|
| 211 |
if __name__ == "__main__":
|
| 212 |
+
demo.launch(theme=THEME, css=CSS)
|
lecop_space.py
CHANGED
|
@@ -5,9 +5,15 @@ from __future__ import annotations
|
|
| 5 |
|
| 6 |
import re
|
| 7 |
from collections import OrderedDict
|
|
|
|
| 8 |
from typing import Dict, Iterable, List, Optional, Tuple
|
| 9 |
|
| 10 |
CHECKS_URL = "https://github.com/michele-xilo/lecop/blob/main/docs/checks.md"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# The Space downloads no videos, so the checks that read them would report every file missing.
|
| 13 |
VIDEO_CODES = (
|
|
@@ -89,25 +95,83 @@ def group_by_code(issues: Iterable[Dict]) -> "OrderedDict[str, List[Dict]]":
|
|
| 89 |
return OrderedDict((c, [i for i in issues if i["code"] == c]) for c in codes)
|
| 90 |
|
| 91 |
|
| 92 |
-
def
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
errors, warnings = report["errors"], report["warnings"]
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
"",
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
""
|
| 102 |
-
|
| 103 |
groups = group_by_code(report["issues"])
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
import re
|
| 7 |
from collections import OrderedDict
|
| 8 |
+
from html import escape
|
| 9 |
from typing import Dict, Iterable, List, Optional, Tuple
|
| 10 |
|
| 11 |
CHECKS_URL = "https://github.com/michele-xilo/lecop/blob/main/docs/checks.md"
|
| 12 |
+
SITE_URL = "https://michele-xilo.github.io/leCop"
|
| 13 |
+
# Like the results site: a few findings per code in view, the rest folded, and a cap so a code with thousands of
|
| 14 |
+
# findings does not make the page unusable.
|
| 15 |
+
SHOWN_PER_CODE = 5
|
| 16 |
+
CAP_PER_CODE = 200
|
| 17 |
|
| 18 |
# The Space downloads no videos, so the checks that read them would report every file missing.
|
| 19 |
VIDEO_CODES = (
|
|
|
|
| 95 |
return OrderedDict((c, [i for i in issues if i["code"] == c]) for c in codes)
|
| 96 |
|
| 97 |
|
| 98 |
+
def plural(n: int, word: str) -> str:
|
| 99 |
+
return f"{n:,} {word}{'' if n == 1 else 's'}"
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def dataset_choices(hub_ids: Iterable[str], index: Iterable[Dict]) -> List[str]:
|
| 103 |
+
"""The dropdown's datasets: the Hub's, in its order, then the results site's that the Hub list missed."""
|
| 104 |
+
seen = set()
|
| 105 |
+
out = []
|
| 106 |
+
for repo in list(hub_ids) + [e.get("repo") for e in index]:
|
| 107 |
+
if repo and repo not in seen:
|
| 108 |
+
seen.add(repo)
|
| 109 |
+
out.append(repo)
|
| 110 |
+
return out
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def site_page(repo: str, index: Iterable[Dict]) -> Optional[str]:
|
| 114 |
+
"""The results-site page of `repo`, if the site has a record of it (from the site's index.json)."""
|
| 115 |
+
for entry in index:
|
| 116 |
+
if entry.get("repo") == repo and entry.get("name"):
|
| 117 |
+
return f"{SITE_URL}/datasets/{entry['name']}.html"
|
| 118 |
+
return None
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
def _finding(issue: Dict) -> str:
|
| 122 |
+
where = "dataset" if issue.get("episode") is None else f"episode {issue['episode']}"
|
| 123 |
+
return f'<div class="lc-find"><span class="lc-muted">{where}</span>{escape(issue["message"])}</div>'
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def _group(code: str, issues: List[Dict]) -> str:
|
| 127 |
+
shown = issues[:SHOWN_PER_CODE]
|
| 128 |
+
rest = issues[SHOWN_PER_CODE:CAP_PER_CODE]
|
| 129 |
+
more = ""
|
| 130 |
+
if rest:
|
| 131 |
+
hidden = len(issues) - SHOWN_PER_CODE - len(rest)
|
| 132 |
+
tail = f'<div class="lc-find lc-muted">+ {hidden:,} not shown, run leCop locally to see them all</div>' if hidden else ""
|
| 133 |
+
more = f'<details class="lc-more"><summary>+ {len(issues) - SHOWN_PER_CODE:,} more</summary>{"".join(map(_finding, rest))}{tail}</details>'
|
| 134 |
+
severity = escape(issues[0]["severity"])
|
| 135 |
+
return (
|
| 136 |
+
f'<section class="lc-group"><div class="lc-ghead"><span class="lc-dot lc-{severity}" aria-hidden="true"></span>'
|
| 137 |
+
f'<strong class="lc-mono">{escape(code)}</strong><span class="lc-muted">{len(issues):,}</span><span class="lc-grow"></span>'
|
| 138 |
+
f'<a class="lc-link lc-small" href="{CHECKS_URL}" target="_blank">About this check</a></div>'
|
| 139 |
+
f'{"".join(map(_finding, shown))}{more}</section>'
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def render_html(repo: str, revision: str, report: Dict, version: str, site_url: Optional[str] = None) -> str:
|
| 144 |
+
"""The report in the results site's look: a summary strip, then one group per issue code."""
|
| 145 |
errors, warnings = report["errors"], report["warnings"]
|
| 146 |
+
counts = ""
|
| 147 |
+
if errors:
|
| 148 |
+
counts += f'<span class="lc-error">{plural(errors, "error")}</span>'
|
| 149 |
+
if warnings:
|
| 150 |
+
counts += f'<span class="lc-warning">{plural(warnings, "warning")}</span>'
|
| 151 |
+
if not counts:
|
| 152 |
+
counts = '<span class="lc-clean">Clean</span>'
|
| 153 |
+
hub = f"https://huggingface.co/datasets/{repo}/tree/{revision}"
|
| 154 |
groups = group_by_code(report["issues"])
|
| 155 |
+
body = "".join(_group(c, i) for c, i in groups.items()) or (
|
| 156 |
+
'<p class="lc-muted">leCop reported nothing on the metadata and data.</p>'
|
| 157 |
+
)
|
| 158 |
+
site = (
|
| 159 |
+
f' The <a class="lc-link" href="{escape(site_url)}" target="_blank">results site</a> has a full run of this dataset, videos included.'
|
| 160 |
+
if site_url
|
| 161 |
+
else ""
|
| 162 |
+
)
|
| 163 |
+
return (
|
| 164 |
+
f'<div class="lc-report"><h2 class="lc-title">{escape(repo)}</h2>'
|
| 165 |
+
f'<div class="lc-mono lc-muted"><a class="lc-link" href="{escape(hub)}" target="_blank">huggingface.co/datasets/{escape(repo)}</a>'
|
| 166 |
+
f" @ {escape(revision[:7])} · leCop {escape(version)}</div>"
|
| 167 |
+
f'<div class="lc-strip"><span class="lc-big">{counts}</span></div>'
|
| 168 |
+
f'<p class="lc-note">What leCop reported on <code>meta/</code> and <code>data/</code>, not a verdict. '
|
| 169 |
+
f"The video checks were skipped: this Space does not download the videos.{site}</p>"
|
| 170 |
+
f"{body}</div>"
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def notice_html(message: str) -> str:
|
| 175 |
+
"""A request that was not checked, with the reason. `message` may hold `code` spans in backticks."""
|
| 176 |
+
text = re.sub(r"`([^`]*)`", r"<code>\1</code>", escape(message))
|
| 177 |
+
return f'<div class="lc-report"><p class="lc-notice"><strong>Not checked.</strong> {text}</p></div>'
|