Spaces:
Running
Running
Download site/progress.js from HuggingFaceSwarms/PyBot: direct link, hf CLI and curl.
- Browser
- Download file 4.41 kB
-
https://huggingface.co/spaces/HuggingFaceSwarms/PyBot/resolve/f6eeecfaadc6fe7c25c122fe581fcaee809a3b23/site/progress.js
- Command line
-
hf download hf://spaces/HuggingFaceSwarms/PyBot@f6eeecfaadc6fe7c25c122fe581fcaee809a3b23/site/progress.js
-
curl -L -o progress.js https://huggingface.co/spaces/HuggingFaceSwarms/PyBot/resolve/f6eeecfaadc6fe7c25c122fe581fcaee809a3b23/site/progress.js
4.41 kB
| async function drawProgress() { | |
| const status = document.getElementById("progress-status"); | |
| const chart = document.getElementById("progress-chart"); | |
| const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)"); | |
| const animateOnScroll = !reducedMotion.matches && "IntersectionObserver" in window; | |
| if (animateOnScroll) chart.classList.add("awaiting-reveal"); | |
| try { | |
| const response = await fetch("api/progress", {cache: "no-store"}); | |
| if (!response.ok) throw new Error("Progress data unavailable"); | |
| const data = await response.json(); | |
| const points = data.points; | |
| const extent = [points[0].revision, points[points.length - 1].revision]; | |
| const traces = [{ | |
| type: "scatter", mode: "lines", name: "PyBot", | |
| x: points.map(p => p.revision), y: points.map(p => p.score), | |
| customdata: points.map(p => p.commit), | |
| line: {color: "#eb6834", width: 2}, | |
| hovertemplate: "PyBot · revision %{x:,}<br>Win rate: %{y:.2f}%<br>Commit %{customdata}<extra></extra>" | |
| }, { | |
| type: "scatter", mode: "lines", name: "Lines of code", yaxis: "y2", | |
| x: points.map(p => p.revision), y: points.map(p => p.lines_of_code), | |
| customdata: points.map(p => p.commit), | |
| line: {color: "#287a9b", width: 2}, | |
| hovertemplate: "Revision %{x:,}<br>Lines of code: %{y:,}<br>Python source in bot/ (including blanks and comments)<br>Commit %{customdata}<extra></extra>" | |
| }, ...data.baselines.map((baseline, index) => ({ | |
| type: "scatter", mode: "lines", | |
| name: baseline.name, | |
| x: extent, y: [baseline.score, baseline.score], | |
| line: {color: ["#999999", "#555555", "#000000"][index], width: 1.5, | |
| dash: ["dot", "dash", "dashdot"][index]}, | |
| hovertemplate: `${baseline.name}<br>Win rate: %{y:.2f}%<extra></extra>` | |
| }))]; | |
| await Plotly.newPlot("progress-chart", traces, { | |
| margin: {l: 60, r: 72, t: 30, b: 60}, | |
| paper_bgcolor: "#ffffff", plot_bgcolor: "#ffffff", | |
| font: {family: "'Letter Gothic', monospace", size: 12, color: "#000000"}, | |
| xaxis: {title: {text: "PyBot commit", standoff: 12}, | |
| range: extent, gridcolor: "#eeeeee", zeroline: false, automargin: true}, | |
| yaxis: {title: {text: "Win rate (%)", standoff: 10}, rangemode: "tozero", | |
| color: "#eb6834", | |
| gridcolor: "#eeeeee", zerolinecolor: "#dddddd", automargin: true}, | |
| yaxis2: {title: {text: "Lines of code", standoff: 10}, overlaying: "y", side: "right", | |
| rangemode: "tozero", color: "#287a9b", tickformat: "~s", | |
| showgrid: false, zeroline: false, automargin: true}, | |
| showlegend: false, | |
| annotations: data.baselines.map(baseline => ({ | |
| text: baseline.name, x: 1, xref: "paper", y: baseline.score, yref: "y", | |
| xanchor: "right", yanchor: "bottom", yshift: 4, showarrow: false, | |
| font: {size: 11, color: "#000000"}, bgcolor: "#ffffff", borderpad: 2 | |
| })), | |
| hoverlabel: {bgcolor: "#ffffff", bordercolor: "#000000"} | |
| }, {responsive: true, displayModeBar: false, displaylogo: false}); | |
| status.hidden = true; | |
| if (animateOnScroll) { | |
| const observer = new IntersectionObserver(entries => { | |
| if (!entries.some(entry => entry.isIntersecting && entry.intersectionRatio >= 0.3)) return; | |
| observer.disconnect(); | |
| // Reveal the rendered SVG traces, keeping both axes and all data fixed. | |
| // This avoids redrawing thousands of points on every animation frame. | |
| chart.classList.remove("awaiting-reveal"); | |
| if (reducedMotion.matches) return; | |
| const animations = [...chart.querySelectorAll(".scatterlayer .trace")].map(trace => | |
| trace.animate([ | |
| {clipPath: "inset(-10px 100% -10px 0)"}, | |
| {clipPath: "inset(-10px 0% -10px 0)"} | |
| ], {duration: 1800, easing: "cubic-bezier(0.22, 1, 0.36, 1)"})); | |
| const finish = () => animations.forEach(animation => animation.finish()); | |
| reducedMotion.addEventListener("change", finish, {once: true}); | |
| Promise.all(animations.map(animation => animation.finished)).finally(() => | |
| reducedMotion.removeEventListener("change", finish)); | |
| }, {threshold: 0.3}); | |
| observer.observe(chart); | |
| } | |
| } catch (error) { | |
| document.getElementById("progress-chart").hidden = true; | |
| status.textContent = "The progress chart is currently unavailable."; | |
| } | |
| } | |
| drawProgress(); | |