Update components.json
Browse files- components.json +31 -5
components.json
CHANGED
|
@@ -27,8 +27,8 @@
|
|
| 27 |
{
|
| 28 |
"id": "detection-viewer",
|
| 29 |
"name": "Detection Viewer",
|
| 30 |
-
"description": "",
|
| 31 |
-
"author": "",
|
| 32 |
"tags": [],
|
| 33 |
"category": "display",
|
| 34 |
"html_template": "<div class=\"pose-viewer-container\" data-panel-title=\"Detections\" data-list-height=\"300\" data-score-threshold-min=\"0.0\" data-score-threshold-max=\"1.0\" data-keypoint-threshold=\"0.0\" data-keypoint-radius=\"3\">\n <script type=\"application/json\" class=\"pose-data\">${value}</script>\n <div class=\"canvas-wrapper\">\n <canvas></canvas>\n </div>\n <div class=\"tooltip\"></div>\n <div class=\"control-panel\">\n <div class=\"control-panel-header\">\n <div class=\"control-panel-header-info\">\n <span class=\"control-panel-title\">Detections</span>\n <span class=\"control-panel-count\"></span>\n </div>\n <div class=\"control-panel-actions\">\n <button class=\"cp-btn toggle-image-btn active\" title=\"Toggle base image (I)\">Image</button>\n <button class=\"cp-btn reset-btn\" title=\"Reset to defaults (R)\">↺</button>\n <button class=\"cp-btn help-btn\" title=\"Keyboard shortcuts (?)\">?</button>\n <button class=\"cp-btn maximize-btn\" title=\"Maximize (F)\">⛶</button>\n </div>\n </div>\n <div class=\"control-panel-body\">\n <div class=\"annotation-list\"></div>\n </div>\n </div>\n <div class=\"help-overlay\">\n <div class=\"help-dialog\">\n <div class=\"help-header\">\n <span>Keyboard Shortcuts</span>\n <button class=\"help-close-btn\">×</button>\n </div>\n <table class=\"help-table\">\n <tr><td><kbd>?</kbd></td><td>Show keyboard shortcuts</td></tr>\n <tr><td><kbd>F</kbd></td><td>Toggle maximize</td></tr>\n <tr><td><kbd>I</kbd></td><td>Toggle base image</td></tr>\n <tr><td><kbd>A</kbd></td><td>Toggle all annotations</td></tr>\n <tr><td><kbd>H</kbd></td><td>Hide selected annotation</td></tr>\n <tr><td><kbd>Shift+Click</kbd></td><td>Hide clicked annotation</td></tr>\n <tr><td><kbd>Esc</kbd></td><td>Deselect / exit maximize</td></tr>\n <tr><td><kbd>+</kbd> / <kbd>-</kbd></td><td>Zoom in / out</td></tr>\n <tr><td><kbd>0</kbd></td><td>Reset zoom</td></tr>\n <tr><td><kbd>R</kbd></td><td>Reset all to defaults</td></tr>\n </table>\n </div>\n </div>\n <div class=\"loading-indicator\"><div class=\"loading-spinner\"></div></div>\n <div class=\"placeholder\">No data</div>\n</div>\n",
|
|
@@ -37,13 +37,39 @@
|
|
| 37 |
"default_props": {
|
| 38 |
"value": "{\"image\": \"https://huggingface.co/datasets/gradio/custom-html-gallery/resolve/main/assets/hyst_image.webp\", \"annotations\": [{\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"microwave\", \"bbox\": {\"x\": 1254.9686279296875, \"y\": 732.0140991210938, \"width\": 731.1876220703125, \"height\": 576.3329467773438}, \"score\": 0.941}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"refrigerator\", \"bbox\": {\"x\": 339.1869812011719, \"y\": 990.19970703125, \"width\": 876.6739807128906, \"height\": 2429.93701171875}, \"score\": 0.933}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"bowl\", \"bbox\": {\"x\": 2060.535888671875, \"y\": 2244.39990234375, \"width\": 336.198486328125, \"height\": 167.25927734375}, \"score\": 0.876}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"bottle\", \"bbox\": {\"x\": 4423.5615234375, \"y\": 2121.12939453125, \"width\": 234.41064453125, \"height\": 441.45458984375}, \"score\": 0.835}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"bowl\", \"bbox\": {\"x\": 2043.2069091796875, \"y\": 2370.33642578125, \"width\": 329.2586669921875, \"height\": 146.4755859375}, \"score\": 0.752}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"bottle\", \"bbox\": {\"x\": 3447.89111328125, \"y\": 1566.84814453125, \"width\": 134.972412109375, \"height\": 196.5047607421875}, \"score\": 0.74}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"spoon\", \"bbox\": {\"x\": 2970.81494140625, \"y\": 1495.561767578125, \"width\": 140.395263671875, \"height\": 229.298095703125}, \"score\": 0.73}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"bowl\", \"bbox\": {\"x\": 2439.3310546875, \"y\": 2352.2724609375, \"width\": 310.017578125, \"height\": 198.46630859375}, \"score\": 0.663}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"sink\", \"bbox\": {\"x\": 3237.94775390625, \"y\": 2000.548828125, \"width\": 1229.5615234375, \"height\": 525.7890625}, \"score\": 0.651}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"spoon\", \"bbox\": {\"x\": 2434.916748046875, \"y\": 958.53125, \"width\": 90.868896484375, \"height\": 397.71923828125}, \"score\": 0.624}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"spoon\", \"bbox\": {\"x\": 2713.24267578125, \"y\": 938.8221435546875, \"width\": 59.1435546875, \"height\": 356.3812255859375}, \"score\": 0.595}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"vase\", \"bbox\": {\"x\": 3051.519775390625, \"y\": 1703.9114990234375, \"width\": 163.010498046875, \"height\": 211.6363525390625}, \"score\": 0.534}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"spoon\", \"bbox\": {\"x\": 3219.201171875, \"y\": 1489.04345703125, \"width\": 131.72900390625, \"height\": 113.6300048828125}, \"score\": 0.529}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"cup\", \"bbox\": {\"x\": 1710.7325439453125, \"y\": 206.48187255859375, \"width\": 113.3707275390625, \"height\": 66.7637939453125}, \"score\": 0.519}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"cup\", \"bbox\": {\"x\": 1905.1246337890625, \"y\": 1348.912841796875, \"width\": 162.7110595703125, \"height\": 180.4144287109375}, \"score\": 0.51}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"spoon\", \"bbox\": {\"x\": 2532.578857421875, \"y\": 956.0765380859375, \"width\": 110.283203125, \"height\": 391.587890625}, \"score\": 0.505}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"cup\", \"bbox\": {\"x\": 1513.127685546875, \"y\": 233.4671173095703, \"width\": 121.0208740234375, \"height\": 74.86408996582031}, \"score\": 0.498}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"cup\", \"bbox\": {\"x\": 3601.44775390625, \"y\": 1676.3946533203125, \"width\": 86.130126953125, \"height\": 83.6402587890625}, \"score\": 0.489}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"sink\", \"bbox\": {\"x\": 2045.0098876953125, \"y\": 1902.2047119140625, \"width\": 992.6627197265625, \"height\": 138.331298828125}, \"score\": 0.48}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"spoon\", \"bbox\": {\"x\": 2750.8525390625, \"y\": 914.2452392578125, \"width\": 138.5458984375, \"height\": 454.1220703125}, \"score\": 0.479}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"cup\", \"bbox\": {\"x\": 1292.629150390625, \"y\": 249.5679168701172, \"width\": 106.822021484375, \"height\": 69.71885681152344}, \"score\": 0.475}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"knife\", \"bbox\": {\"x\": 2167.822021484375, \"y\": 960.3970947265625, \"width\": 43.119140625, \"height\": 483.4991455078125}, \"score\": 0.465}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"bottle\", \"bbox\": {\"x\": 4585.04150390625, \"y\": 2098.5009765625, \"width\": 116.8916015625, \"height\": 316.954345703125}, \"score\": 0.459}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"cup\", \"bbox\": {\"x\": 1712.269775390625, \"y\": 1363.4146728515625, \"width\": 168.132568359375, \"height\": 171.383056640625}, \"score\": 0.45}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"cup\", \"bbox\": {\"x\": 1754.1475830078125, \"y\": 1726.2864990234375, \"width\": 132.280517578125, \"height\": 180.217529296875}, \"score\": 0.443}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"spoon\", \"bbox\": {\"x\": 2464.33349609375, \"y\": 962.2620239257812, \"width\": 98.230712890625, \"height\": 395.64776611328125}, \"score\": 0.432}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"oven\", \"bbox\": {\"x\": 2045.0098876953125, \"y\": 1902.2047119140625, \"width\": 992.6627197265625, \"height\": 138.331298828125}, \"score\": 0.43}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"spoon\", \"bbox\": {\"x\": 2338.453369140625, \"y\": 970.2446899414062, \"width\": 88.694091796875, \"height\": 284.50689697265625}, \"score\": 0.415}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"cup\", \"bbox\": {\"x\": 1600.4539794921875, \"y\": 1722.7650146484375, \"width\": 126.56103515625, \"height\": 181.688720703125}, \"score\": 0.409}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"cup\", \"bbox\": {\"x\": 1915.982421875, \"y\": 1727.005859375, \"width\": 161.400634765625, \"height\": 180.8668212890625}, \"score\": 0.407}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"knife\", \"bbox\": {\"x\": 2122.896240234375, \"y\": 973.0816040039062, \"width\": 45.917724609375, \"height\": 480.61651611328125}, \"score\": 0.402}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"knife\", \"bbox\": {\"x\": 2050.469970703125, \"y\": 1032.178955078125, \"width\": 48.721923828125, \"height\": 364.73681640625}, \"score\": 0.391}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"knife\", \"bbox\": {\"x\": 2204.854736328125, \"y\": 1075.57177734375, \"width\": 37.0556640625, \"height\": 365.2413330078125}, \"score\": 0.388}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"knife\", \"bbox\": {\"x\": 2137.04345703125, \"y\": 967.40380859375, \"width\": 46.23291015625, \"height\": 482.9554443359375}, \"score\": 0.382}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"cup\", \"bbox\": {\"x\": 1938.565185546875, \"y\": 184.62074279785156, \"width\": 144.8037109375, \"height\": 72.32969665527344}, \"score\": 0.379}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"vase\", \"bbox\": {\"x\": 4364.35546875, \"y\": 1642.5433349609375, \"width\": 325.09130859375, \"height\": 552.6705322265625}, \"score\": 0.359}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"spoon\", \"bbox\": {\"x\": 3148.77392578125, \"y\": 1489.83251953125, \"width\": 200.311279296875, \"height\": 217.281494140625}, \"score\": 0.358}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"spoon\", \"bbox\": {\"x\": 2325.773193359375, \"y\": 966.5449829101562, \"width\": 126.0576171875, \"height\": 382.44464111328125}, \"score\": 0.351}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"handbag\", \"bbox\": {\"x\": 342.6567077636719, \"y\": 832.3612060546875, \"width\": 408.2694396972656, \"height\": 182.2032470703125}, \"score\": 0.347}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"sink\", \"bbox\": {\"x\": 3422.76611328125, \"y\": 2016.8096923828125, \"width\": 776.34912109375, \"height\": 293.2298583984375}, \"score\": 0.346}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"oven\", \"bbox\": {\"x\": 2040.9306640625, \"y\": 1891.8070068359375, \"width\": 998.08642578125, \"height\": 601.4830322265625}, \"score\": 0.34}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"spoon\", \"bbox\": {\"x\": 2578.92724609375, \"y\": 950.519287109375, \"width\": 68.382080078125, \"height\": 385.21142578125}, \"score\": 0.339}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"bowl\", \"bbox\": {\"x\": 1938.565185546875, \"y\": 184.62074279785156, \"width\": 144.8037109375, \"height\": 72.32969665527344}, \"score\": 0.337}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"knife\", \"bbox\": {\"x\": 2118.98876953125, \"y\": 976.58642578125, \"width\": 37.457763671875, \"height\": 448.0491943359375}, \"score\": 0.326}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"knife\", \"bbox\": {\"x\": 2080.163818359375, \"y\": 1028.6563720703125, \"width\": 46.5048828125, \"height\": 370.2650146484375}, \"score\": 0.318}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"spoon\", \"bbox\": {\"x\": 2581.24658203125, \"y\": 950.1279296875, \"width\": 67.4453125, \"height\": 384.987548828125}, \"score\": 0.318}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"knife\", \"bbox\": {\"x\": 2095.49951171875, \"y\": 1014.590087890625, \"width\": 48.67724609375, \"height\": 420.140869140625}, \"score\": 0.317}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"knife\", \"bbox\": {\"x\": 2113.23095703125, \"y\": 977.2379760742188, \"width\": 38.787841796875, \"height\": 431.59820556640625}, \"score\": 0.312}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"spoon\", \"bbox\": {\"x\": 3144.85888671875, \"y\": 1568.898681640625, \"width\": 87.18017578125, \"height\": 141.762939453125}, \"score\": 0.305}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"knife\", \"bbox\": {\"x\": 2124.10546875, \"y\": 978.140380859375, \"width\": 38.487060546875, \"height\": 460.7664794921875}, \"score\": 0.302}], \"scoreThresholdMin\": 0.3, \"scoreThresholdMax\": 1.0}"
|
| 39 |
},
|
| 40 |
-
"python_code": "class DetectionViewer(gr.HTML):\n def __init__(\n self,\n value: tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]]]\n | tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]], dict[str, Any]]\n | None = None,\n *,\n label: str | None = None,\n panel_title: str = \"Detections\",\n list_height: int = 300,\n score_threshold: tuple[float, float] = (0.0, 1.0),\n keypoint_threshold: float = 0.0,\n keypoint_radius: int = 3,\n **kwargs: object,\n ) -> None:\n html_template = (_STATIC_DIR / \"template.html\").read_text(encoding=\"utf-8\")\n html_template = html_template.replace(\"${panel_title}\", panel_title)\n html_template = html_template.replace(\"${list_height}\", str(list_height))\n html_template = html_template.replace(\"${score_threshold_min}\", str(score_threshold[0]))\n html_template = html_template.replace(\"${score_threshold_max}\", str(score_threshold[1]))\n html_template = html_template.replace(\"${keypoint_threshold}\", str(keypoint_threshold))\n html_template = html_template.replace(\"${keypoint_radius}\", str(keypoint_radius))\n css_template = (_STATIC_DIR / \"style.css\").read_text(encoding=\"utf-8\")\n css_template = css_template.replace(\"${list_height}\", str(list_height))\n js_on_load = (_STATIC_DIR / \"script.js\").read_text(encoding=\"utf-8\")\n\n has_label = label is not None\n super().__init__(\n value=value,\n label=label,\n show_label=has_label,\n container=has_label,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load,\n **kwargs,\n )\n\n def postprocess(self, value: Any) -> str | None: # noqa: ANN401\n if isinstance(value, str):\n return value\n return self._process(value)\n\n def _process(\n self,\n value: tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]]]\n | tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]], dict[str, Any]]\n | None,\n ) -> str | None:\n if value is None:\n return None\n\n if len(value) == 3: # noqa: PLR2004 - tuple length check\n image_src, annotations, config = value\n else:\n image_src, annotations = value\n config = {}\n\n img = _load_image(image_src)\n image_url = _save_image_to_cache(img, self.GRADIO_CACHE)\n\n processed: list[dict[str, Any]] = []\n for i, ann in enumerate(annotations):\n has_kps = \"keypoints\" in ann and len(ann[\"keypoints\"]) > 0\n default_label = f\"Person {i + 1}\" if has_kps else f\"Detection {i + 1}\"\n\n entry: dict[str, Any] = {\n \"keypoints\": ann.get(\"keypoints\", []),\n \"connections\": ann.get(\"connections\", []),\n \"color\": ann.get(\"color\", _COLOR_PALETTE[i % len(_COLOR_PALETTE)]),\n \"label\": ann.get(\"label\", default_label),\n }\n if \"bbox\" in ann:\n entry[\"bbox\"] = ann[\"bbox\"]\n if \"score\" in ann:\n entry[\"score\"] = ann[\"score\"]\n if \"mask\" in ann:\n entry[\"mask\"] = ann[\"mask\"]\n processed.append(entry)\n\n result: dict[str, Any] = {\"image\": image_url, \"annotations\": processed}\n if \"score_threshold\" in config:\n result[\"scoreThresholdMin\"] = config[\"score_threshold\"][0]\n result[\"scoreThresholdMax\"] = config[\"score_threshold\"][1]\n\n return json.dumps(result)\n\n def api_info(self) -> dict[str, Any]:\n return {\n \"type\": \"string\",\n \"description\": (\n \"JSON string containing detection visualization data. \"\n \"Structure: {image: string (URL), annotations: [\"\n \"{color: string, label: string, \"\n \"bbox?: {x: float, y: float, width: float, height: float}, \"\n \"score?: float, \"\n \"mask?: {counts: [int], size: [int, int]}, \"\n \"keypoints?: [{x: float, y: float, name: string, confidence?: float}], \"\n \"connections?: [[int, int]]}], \"\n \"scoreThresholdMin?: float, scoreThresholdMax?: float}\"\n ),\n }\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
},
|
| 42 |
{
|
| 43 |
"id": "spin-wheel",
|
| 44 |
"name": "Spin Wheel",
|
| 45 |
-
"description": "",
|
| 46 |
-
"author": "",
|
| 47 |
"tags": [],
|
| 48 |
"category": "display",
|
| 49 |
"html_template": "\n<div class=\"wheel-container\">\n <div class=\"wheel-wrapper\">\n <!-- Pointer -->\n <div class=\"wheel-pointer\">\u25bc</div>\n \n <!-- Wheel - rotation prop preserves position across re-renders -->\n <div class=\"wheel\" id=\"prize-wheel\" style=\"transform: rotate(${rotation || 0}deg);\">\n <svg viewBox=\"0 0 400 400\" class=\"wheel-svg\">\n ${(() => {\n const segments = JSON.parse(segments_json || '[]');\n const cx = 200, cy = 200, r = 180;\n let html = '';\n \n segments.forEach((seg, i) => {\n const startRad = (seg.startAngle - 90) * Math.PI / 180;\n const endRad = (seg.endAngle - 90) * Math.PI / 180;\n const x1 = cx + r * Math.cos(startRad);\n const y1 = cy + r * Math.sin(startRad);\n const x2 = cx + r * Math.cos(endRad);\n const y2 = cy + r * Math.sin(endRad);\n const largeArc = seg.endAngle - seg.startAngle > 180 ? 1 : 0;\n \n const d = `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 ${largeArc} 1 ${x2} ${y2} Z`;\n html += `<path d=\"${d}\" fill=\"${seg.color}\" stroke=\"#fff\" stroke-width=\"2\" class=\"segment\" data-index=\"${i}\"/>`;\n \n // Text label\n const midRad = (seg.midAngle - 90) * Math.PI / 180;\n const textR = r * 0.65;\n const tx = cx + textR * Math.cos(midRad);\n const ty = cy + textR * Math.sin(midRad);\n const rotation = seg.midAngle;\n html += `<text x=\"${tx}\" y=\"${ty}\" fill=\"#fff\" font-size=\"11\" font-weight=\"bold\" \n text-anchor=\"middle\" dominant-baseline=\"middle\" \n transform=\"rotate(${rotation}, ${tx}, ${ty})\"\n style=\"text-shadow: 1px 1px 2px rgba(0,0,0,0.5); pointer-events: none;\">${seg.label}</text>`;\n });\n \n // Center circle\n html += `<circle cx=\"200\" cy=\"200\" r=\"35\" fill=\"#1a1a2e\" stroke=\"#FFD700\" stroke-width=\"4\" class=\"center-btn\"/>`;\n html += `<text x=\"200\" y=\"200\" fill=\"#FFD700\" font-size=\"14\" font-weight=\"bold\" text-anchor=\"middle\" dominant-baseline=\"middle\" style=\"pointer-events: none;\">SPIN</text>`;\n \n return html;\n })()}\n </svg>\n </div>\n \n <!-- Decorative lights -->\n <div class=\"wheel-lights\">\n ${Array.from({length: 16}, (_, i) => `<div class=\"light\" style=\"--i: ${i}\"></div>`).join('')}\n </div>\n </div>\n \n <!-- Result Display -->\n <div class=\"result-display ${value ? 'show' : ''}\" id=\"result-display\">\n ${value ? `<div class=\"result-text\">\ud83c\udf89 You won: <strong>${value}</strong></div>` : '<div class=\"result-text\">Spin to win!</div>'}\n </div>\n \n <!-- Spin Button -->\n <button class=\"spin-button\" id=\"spin-btn\">\n \ud83c\udfb0 SPIN TO WIN!\n </button>\n \n <!-- Confetti container -->\n <div class=\"confetti-container\" id=\"confetti\"></div>\n</div>\n",
|
|
|
|
| 27 |
{
|
| 28 |
"id": "detection-viewer",
|
| 29 |
"name": "Detection Viewer",
|
| 30 |
+
"description": "Rich viewer for object detection model outputs",
|
| 31 |
+
"author": "hysts",
|
| 32 |
"tags": [],
|
| 33 |
"category": "display",
|
| 34 |
"html_template": "<div class=\"pose-viewer-container\" data-panel-title=\"Detections\" data-list-height=\"300\" data-score-threshold-min=\"0.0\" data-score-threshold-max=\"1.0\" data-keypoint-threshold=\"0.0\" data-keypoint-radius=\"3\">\n <script type=\"application/json\" class=\"pose-data\">${value}</script>\n <div class=\"canvas-wrapper\">\n <canvas></canvas>\n </div>\n <div class=\"tooltip\"></div>\n <div class=\"control-panel\">\n <div class=\"control-panel-header\">\n <div class=\"control-panel-header-info\">\n <span class=\"control-panel-title\">Detections</span>\n <span class=\"control-panel-count\"></span>\n </div>\n <div class=\"control-panel-actions\">\n <button class=\"cp-btn toggle-image-btn active\" title=\"Toggle base image (I)\">Image</button>\n <button class=\"cp-btn reset-btn\" title=\"Reset to defaults (R)\">↺</button>\n <button class=\"cp-btn help-btn\" title=\"Keyboard shortcuts (?)\">?</button>\n <button class=\"cp-btn maximize-btn\" title=\"Maximize (F)\">⛶</button>\n </div>\n </div>\n <div class=\"control-panel-body\">\n <div class=\"annotation-list\"></div>\n </div>\n </div>\n <div class=\"help-overlay\">\n <div class=\"help-dialog\">\n <div class=\"help-header\">\n <span>Keyboard Shortcuts</span>\n <button class=\"help-close-btn\">×</button>\n </div>\n <table class=\"help-table\">\n <tr><td><kbd>?</kbd></td><td>Show keyboard shortcuts</td></tr>\n <tr><td><kbd>F</kbd></td><td>Toggle maximize</td></tr>\n <tr><td><kbd>I</kbd></td><td>Toggle base image</td></tr>\n <tr><td><kbd>A</kbd></td><td>Toggle all annotations</td></tr>\n <tr><td><kbd>H</kbd></td><td>Hide selected annotation</td></tr>\n <tr><td><kbd>Shift+Click</kbd></td><td>Hide clicked annotation</td></tr>\n <tr><td><kbd>Esc</kbd></td><td>Deselect / exit maximize</td></tr>\n <tr><td><kbd>+</kbd> / <kbd>-</kbd></td><td>Zoom in / out</td></tr>\n <tr><td><kbd>0</kbd></td><td>Reset zoom</td></tr>\n <tr><td><kbd>R</kbd></td><td>Reset all to defaults</td></tr>\n </table>\n </div>\n </div>\n <div class=\"loading-indicator\"><div class=\"loading-spinner\"></div></div>\n <div class=\"placeholder\">No data</div>\n</div>\n",
|
|
|
|
| 37 |
"default_props": {
|
| 38 |
"value": "{\"image\": \"https://huggingface.co/datasets/gradio/custom-html-gallery/resolve/main/assets/hyst_image.webp\", \"annotations\": [{\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"microwave\", \"bbox\": {\"x\": 1254.9686279296875, \"y\": 732.0140991210938, \"width\": 731.1876220703125, \"height\": 576.3329467773438}, \"score\": 0.941}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"refrigerator\", \"bbox\": {\"x\": 339.1869812011719, \"y\": 990.19970703125, \"width\": 876.6739807128906, \"height\": 2429.93701171875}, \"score\": 0.933}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"bowl\", \"bbox\": {\"x\": 2060.535888671875, \"y\": 2244.39990234375, \"width\": 336.198486328125, \"height\": 167.25927734375}, \"score\": 0.876}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"bottle\", \"bbox\": {\"x\": 4423.5615234375, \"y\": 2121.12939453125, \"width\": 234.41064453125, \"height\": 441.45458984375}, \"score\": 0.835}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"bowl\", \"bbox\": {\"x\": 2043.2069091796875, \"y\": 2370.33642578125, \"width\": 329.2586669921875, \"height\": 146.4755859375}, \"score\": 0.752}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"bottle\", \"bbox\": {\"x\": 3447.89111328125, \"y\": 1566.84814453125, \"width\": 134.972412109375, \"height\": 196.5047607421875}, \"score\": 0.74}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"spoon\", \"bbox\": {\"x\": 2970.81494140625, \"y\": 1495.561767578125, \"width\": 140.395263671875, \"height\": 229.298095703125}, \"score\": 0.73}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"bowl\", \"bbox\": {\"x\": 2439.3310546875, \"y\": 2352.2724609375, \"width\": 310.017578125, \"height\": 198.46630859375}, \"score\": 0.663}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"sink\", \"bbox\": {\"x\": 3237.94775390625, \"y\": 2000.548828125, \"width\": 1229.5615234375, \"height\": 525.7890625}, \"score\": 0.651}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"spoon\", \"bbox\": {\"x\": 2434.916748046875, \"y\": 958.53125, \"width\": 90.868896484375, \"height\": 397.71923828125}, \"score\": 0.624}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"spoon\", \"bbox\": {\"x\": 2713.24267578125, \"y\": 938.8221435546875, \"width\": 59.1435546875, \"height\": 356.3812255859375}, \"score\": 0.595}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"vase\", \"bbox\": {\"x\": 3051.519775390625, \"y\": 1703.9114990234375, \"width\": 163.010498046875, \"height\": 211.6363525390625}, \"score\": 0.534}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"spoon\", \"bbox\": {\"x\": 3219.201171875, \"y\": 1489.04345703125, \"width\": 131.72900390625, \"height\": 113.6300048828125}, \"score\": 0.529}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"cup\", \"bbox\": {\"x\": 1710.7325439453125, \"y\": 206.48187255859375, \"width\": 113.3707275390625, \"height\": 66.7637939453125}, \"score\": 0.519}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"cup\", \"bbox\": {\"x\": 1905.1246337890625, \"y\": 1348.912841796875, \"width\": 162.7110595703125, \"height\": 180.4144287109375}, \"score\": 0.51}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"spoon\", \"bbox\": {\"x\": 2532.578857421875, \"y\": 956.0765380859375, \"width\": 110.283203125, \"height\": 391.587890625}, \"score\": 0.505}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"cup\", \"bbox\": {\"x\": 1513.127685546875, \"y\": 233.4671173095703, \"width\": 121.0208740234375, \"height\": 74.86408996582031}, \"score\": 0.498}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"cup\", \"bbox\": {\"x\": 3601.44775390625, \"y\": 1676.3946533203125, \"width\": 86.130126953125, \"height\": 83.6402587890625}, \"score\": 0.489}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"sink\", \"bbox\": {\"x\": 2045.0098876953125, \"y\": 1902.2047119140625, \"width\": 992.6627197265625, \"height\": 138.331298828125}, \"score\": 0.48}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"spoon\", \"bbox\": {\"x\": 2750.8525390625, \"y\": 914.2452392578125, \"width\": 138.5458984375, \"height\": 454.1220703125}, \"score\": 0.479}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"cup\", \"bbox\": {\"x\": 1292.629150390625, \"y\": 249.5679168701172, \"width\": 106.822021484375, \"height\": 69.71885681152344}, \"score\": 0.475}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"knife\", \"bbox\": {\"x\": 2167.822021484375, \"y\": 960.3970947265625, \"width\": 43.119140625, \"height\": 483.4991455078125}, \"score\": 0.465}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"bottle\", \"bbox\": {\"x\": 4585.04150390625, \"y\": 2098.5009765625, \"width\": 116.8916015625, \"height\": 316.954345703125}, \"score\": 0.459}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"cup\", \"bbox\": {\"x\": 1712.269775390625, \"y\": 1363.4146728515625, \"width\": 168.132568359375, \"height\": 171.383056640625}, \"score\": 0.45}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"cup\", \"bbox\": {\"x\": 1754.1475830078125, \"y\": 1726.2864990234375, \"width\": 132.280517578125, \"height\": 180.217529296875}, \"score\": 0.443}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"spoon\", \"bbox\": {\"x\": 2464.33349609375, \"y\": 962.2620239257812, \"width\": 98.230712890625, \"height\": 395.64776611328125}, \"score\": 0.432}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"oven\", \"bbox\": {\"x\": 2045.0098876953125, \"y\": 1902.2047119140625, \"width\": 992.6627197265625, \"height\": 138.331298828125}, \"score\": 0.43}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"spoon\", \"bbox\": {\"x\": 2338.453369140625, \"y\": 970.2446899414062, \"width\": 88.694091796875, \"height\": 284.50689697265625}, \"score\": 0.415}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"cup\", \"bbox\": {\"x\": 1600.4539794921875, \"y\": 1722.7650146484375, \"width\": 126.56103515625, \"height\": 181.688720703125}, \"score\": 0.409}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"cup\", \"bbox\": {\"x\": 1915.982421875, \"y\": 1727.005859375, \"width\": 161.400634765625, \"height\": 180.8668212890625}, \"score\": 0.407}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"knife\", \"bbox\": {\"x\": 2122.896240234375, \"y\": 973.0816040039062, \"width\": 45.917724609375, \"height\": 480.61651611328125}, \"score\": 0.402}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"knife\", \"bbox\": {\"x\": 2050.469970703125, \"y\": 1032.178955078125, \"width\": 48.721923828125, \"height\": 364.73681640625}, \"score\": 0.391}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"knife\", \"bbox\": {\"x\": 2204.854736328125, \"y\": 1075.57177734375, \"width\": 37.0556640625, \"height\": 365.2413330078125}, \"score\": 0.388}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"knife\", \"bbox\": {\"x\": 2137.04345703125, \"y\": 967.40380859375, \"width\": 46.23291015625, \"height\": 482.9554443359375}, \"score\": 0.382}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"cup\", \"bbox\": {\"x\": 1938.565185546875, \"y\": 184.62074279785156, \"width\": 144.8037109375, \"height\": 72.32969665527344}, \"score\": 0.379}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"vase\", \"bbox\": {\"x\": 4364.35546875, \"y\": 1642.5433349609375, \"width\": 325.09130859375, \"height\": 552.6705322265625}, \"score\": 0.359}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"spoon\", \"bbox\": {\"x\": 3148.77392578125, \"y\": 1489.83251953125, \"width\": 200.311279296875, \"height\": 217.281494140625}, \"score\": 0.358}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"spoon\", \"bbox\": {\"x\": 2325.773193359375, \"y\": 966.5449829101562, \"width\": 126.0576171875, \"height\": 382.44464111328125}, \"score\": 0.351}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"handbag\", \"bbox\": {\"x\": 342.6567077636719, \"y\": 832.3612060546875, \"width\": 408.2694396972656, \"height\": 182.2032470703125}, \"score\": 0.347}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"sink\", \"bbox\": {\"x\": 3422.76611328125, \"y\": 2016.8096923828125, \"width\": 776.34912109375, \"height\": 293.2298583984375}, \"score\": 0.346}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"oven\", \"bbox\": {\"x\": 2040.9306640625, \"y\": 1891.8070068359375, \"width\": 998.08642578125, \"height\": 601.4830322265625}, \"score\": 0.34}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"spoon\", \"bbox\": {\"x\": 2578.92724609375, \"y\": 950.519287109375, \"width\": 68.382080078125, \"height\": 385.21142578125}, \"score\": 0.339}, {\"keypoints\": [], \"connections\": [], \"color\": \"#4CAF50\", \"label\": \"bowl\", \"bbox\": {\"x\": 1938.565185546875, \"y\": 184.62074279785156, \"width\": 144.8037109375, \"height\": 72.32969665527344}, \"score\": 0.337}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF9800\", \"label\": \"knife\", \"bbox\": {\"x\": 2118.98876953125, \"y\": 976.58642578125, \"width\": 37.457763671875, \"height\": 448.0491943359375}, \"score\": 0.326}, {\"keypoints\": [], \"connections\": [], \"color\": \"#9C27B0\", \"label\": \"knife\", \"bbox\": {\"x\": 2080.163818359375, \"y\": 1028.6563720703125, \"width\": 46.5048828125, \"height\": 370.2650146484375}, \"score\": 0.318}, {\"keypoints\": [], \"connections\": [], \"color\": \"#00BCD4\", \"label\": \"spoon\", \"bbox\": {\"x\": 2581.24658203125, \"y\": 950.1279296875, \"width\": 67.4453125, \"height\": 384.987548828125}, \"score\": 0.318}, {\"keypoints\": [], \"connections\": [], \"color\": \"#E91E63\", \"label\": \"knife\", \"bbox\": {\"x\": 2095.49951171875, \"y\": 1014.590087890625, \"width\": 48.67724609375, \"height\": 420.140869140625}, \"score\": 0.317}, {\"keypoints\": [], \"connections\": [], \"color\": \"#8BC34A\", \"label\": \"knife\", \"bbox\": {\"x\": 2113.23095703125, \"y\": 977.2379760742188, \"width\": 38.787841796875, \"height\": 431.59820556640625}, \"score\": 0.312}, {\"keypoints\": [], \"connections\": [], \"color\": \"#FF0000\", \"label\": \"spoon\", \"bbox\": {\"x\": 3144.85888671875, \"y\": 1568.898681640625, \"width\": 87.18017578125, \"height\": 141.762939453125}, \"score\": 0.305}, {\"keypoints\": [], \"connections\": [], \"color\": \"#2196F3\", \"label\": \"knife\", \"bbox\": {\"x\": 2124.10546875, \"y\": 978.140380859375, \"width\": 38.487060546875, \"height\": 460.7664794921875}, \"score\": 0.302}], \"scoreThresholdMin\": 0.3, \"scoreThresholdMax\": 1.0}"
|
| 39 |
},
|
| 40 |
+
"python_code": "class DetectionViewer(gr.HTML):\n def __init__(\n self,\n value: tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]]]\n | tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]], dict[str, Any]]\n | None = None,\n *,\n label: str | None = None,\n panel_title: str = \"Detections\",\n list_height: int = 300,\n score_threshold: tuple[float, float] = (0.0, 1.0),\n keypoint_threshold: float = 0.0,\n keypoint_radius: int = 3,\n **kwargs: object,\n ) -> None:\n html_template = (_STATIC_DIR / \"template.html\").read_text(encoding=\"utf-8\")\n html_template = html_template.replace(\"${panel_title}\", panel_title)\n html_template = html_template.replace(\"${list_height}\", str(list_height))\n html_template = html_template.replace(\"${score_threshold_min}\", str(score_threshold[0]))\n html_template = html_template.replace(\"${score_threshold_max}\", str(score_threshold[1]))\n html_template = html_template.replace(\"${keypoint_threshold}\", str(keypoint_threshold))\n html_template = html_template.replace(\"${keypoint_radius}\", str(keypoint_radius))\n css_template = (_STATIC_DIR / \"style.css\").read_text(encoding=\"utf-8\")\n css_template = css_template.replace(\"${list_height}\", str(list_height))\n js_on_load = (_STATIC_DIR / \"script.js\").read_text(encoding=\"utf-8\")\n\n has_label = label is not None\n super().__init__(\n value=value,\n label=label,\n show_label=has_label,\n container=has_label,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load,\n **kwargs,\n )\n\n def postprocess(self, value: Any) -> str | None: # noqa: ANN401\n if isinstance(value, str):\n return value\n return self._process(value)\n\n def _process(\n self,\n value: tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]]]\n | tuple[str | Path | Image.Image | np.ndarray, list[dict[str, Any]], dict[str, Any]]\n | None,\n ) -> str | None:\n if value is None:\n return None\n\n if len(value) == 3: # noqa: PLR2004 - tuple length check\n image_src, annotations, config = value\n else:\n image_src, annotations = value\n config = {}\n\n img = _load_image(image_src)\n image_url = _save_image_to_cache(img, self.GRADIO_CACHE)\n\n processed: list[dict[str, Any]] = []\n for i, ann in enumerate(annotations):\n has_kps = \"keypoints\" in ann and len(ann[\"keypoints\"]) > 0\n default_label = f\"Person {i + 1}\" if has_kps else f\"Detection {i + 1}\"\n\n entry: dict[str, Any] = {\n \"keypoints\": ann.get(\"keypoints\", []),\n \"connections\": ann.get(\"connections\", []),\n \"color\": ann.get(\"color\", _COLOR_PALETTE[i % len(_COLOR_PALETTE)]),\n \"label\": ann.get(\"label\", default_label),\n }\n if \"bbox\" in ann:\n entry[\"bbox\"] = ann[\"bbox\"]\n if \"score\" in ann:\n entry[\"score\"] = ann[\"score\"]\n if \"mask\" in ann:\n entry[\"mask\"] = ann[\"mask\"]\n processed.append(entry)\n\n result: dict[str, Any] = {\"image\": image_url, \"annotations\": processed}\n if \"score_threshold\" in config:\n result[\"scoreThresholdMin\"] = config[\"score_threshold\"][0]\n result[\"scoreThresholdMax\"] = config[\"score_threshold\"][1]\n\n return json.dumps(result)\n\n def api_info(self) -> dict[str, Any]:\n return {\n \"type\": \"string\",\n \"description\": (\n \"JSON string containing detection visualization data. \"\n \"Structure: {image: string (URL), annotations: [\"\n \"{color: string, label: string, \"\n \"bbox?: {x: float, y: float, width: float, height: float}, \"\n \"score?: float, \"\n \"mask?: {counts: [int], size: [int, int]}, \"\n \"keypoints?: [{x: float, y: float, name: string, confidence?: float}], \"\n \"connections?: [[int, int]]}], \"\n \"scoreThresholdMin?: float, scoreThresholdMax?: float}\"\n ),\n }\n",
|
| 41 |
+
"repo_url": "https://github.com/hysts/gradio-detection-viewer/"
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"id": "contribution-heatmap",
|
| 45 |
+
"name": "Contribution Heatmap",
|
| 46 |
+
"description": "Reusable GitHub-style contribution heatmap",
|
| 47 |
+
"author": "ysharma",
|
| 48 |
+
"tags": [
|
| 49 |
+
"Business"
|
| 50 |
+
],
|
| 51 |
+
"category": "Display",
|
| 52 |
+
"html_template": "\n<div class=\"heatmap-container\">\n <div class=\"heatmap-header\">\n <h2>${(() => {\n const total = Object.values(value || {}).reduce((a, b) => a + b, 0);\n return '\ud83d\udcca ' + total.toLocaleString() + ' contributions in ' + year;\n })()}</h2>\n <div class=\"legend\">\n <span>Less</span>\n <div class=\"legend-box\" style=\"background:${c0}\"></div>\n <div class=\"legend-box\" style=\"background:${c1}\"></div>\n <div class=\"legend-box\" style=\"background:${c2}\"></div>\n <div class=\"legend-box\" style=\"background:${c3}\"></div>\n <div class=\"legend-box\" style=\"background:${c4}\"></div>\n <span>More</span>\n </div>\n </div>\n <div class=\"month-labels\">\n ${(() => {\n const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\n return months.map((m, i) =>\n '<span style=\"grid-column:' + (Math.floor(i * 4.33) + 2) + '\">' + m + '</span>'\n ).join('');\n })()}\n </div>\n <div class=\"heatmap-grid\">\n <div class=\"day-labels\">\n <span></span><span>Mon</span><span></span><span>Wed</span><span></span><span>Fri</span><span></span>\n </div>\n <div class=\"cells\">\n ${(() => {\n const v = value || {};\n const sd = new Date(year, 0, 1);\n const pad = sd.getDay();\n const cells = [];\n for (let i = 0; i < pad; i++) cells.push('<div class=\"cell empty\"></div>');\n const totalDays = Math.floor((new Date(year, 11, 31) - sd) / 86400000) + 1;\n for (let d = 0; d < totalDays; d++) {\n const dt = new Date(year, 0, 1 + d);\n const key = dt.getFullYear() + '-' + String(dt.getMonth()+1).padStart(2,'0') + '-' + String(dt.getDate()).padStart(2,'0');\n const count = v[key] || 0;\n let lv = 0;\n if (count > 0) lv = 1;\n if (count >= 3) lv = 2;\n if (count >= 6) lv = 3;\n if (count >= 10) lv = 4;\n const mn = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\n const tip = count + ' contributions on ' + mn[dt.getMonth()] + ' ' + dt.getDate() + ', ' + year;\n cells.push('<div class=\"cell level-' + lv + '\" data-date=\"' + key + '\" data-count=\"' + count + '\" title=\"' + tip + '\"></div>');\n }\n return cells.join('');\n })()}\n </div>\n </div>\n <div class=\"stats-bar\">\n ${(() => {\n const v = value || {};\n const totalDays = Math.floor((new Date(year, 11, 31) - new Date(year, 0, 1)) / 86400000) + 1;\n let streak = 0, maxStreak = 0, total = 0, active = 0, best = 0;\n const vals = [];\n for (let d = 0; d < totalDays; d++) {\n const dt = new Date(year, 0, 1 + d);\n const key = dt.getFullYear() + '-' + String(dt.getMonth()+1).padStart(2,'0') + '-' + String(dt.getDate()).padStart(2,'0');\n const c = v[key] || 0;\n total += c;\n if (c > 0) { streak++; maxStreak = Math.max(maxStreak, streak); active++; best = Math.max(best, c); vals.push(c); }\n else { streak = 0; }\n }\n const avg = vals.length ? (total / vals.length).toFixed(1) : '0';\n const stats = [\n ['\ud83d\udd25', maxStreak, 'Longest Streak'],\n ['\ud83d\udcc5', active, 'Active Days'],\n ['\u26a1', best, 'Best Day'],\n ['\ud83d\udcc8', avg, 'Avg / Active Day'],\n ['\ud83c\udfc6', total.toLocaleString(), 'Total'],\n ];\n return stats.map(s =>\n '<div class=\"stat\"><span class=\"stat-value\">' + s[1] + '</span><span class=\"stat-label\">' + s[0] + ' ' + s[2] + '</span></div>'\n ).join('');\n })()}\n </div>\n</div>\n",
|
| 53 |
+
"css_template": "\n .heatmap-container {\n background: #0d1117;\n border-radius: 12px;\n padding: 24px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n color: #c9d1d9;\n overflow-x: auto;\n }\n .heatmap-header {\n display: flex; justify-content: space-between; align-items: center;\n margin-bottom: 12px; flex-wrap: wrap; gap: 10px;\n }\n .heatmap-header h2 { margin: 0; font-size: 16px; font-weight: 500; color: #f0f6fc; }\n .legend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: #8b949e; }\n .legend-box { width: 12px; height: 12px; border-radius: 2px; }\n .month-labels {\n display: grid; grid-template-columns: 30px repeat(53, 1fr);\n font-size: 11px; color: #8b949e; margin-bottom: 4px; padding-left: 2px;\n }\n .heatmap-grid { display: flex; gap: 4px; }\n .day-labels {\n display: grid; grid-template-rows: repeat(7, 1fr);\n font-size: 11px; color: #8b949e; width: 30px; gap: 2px;\n }\n .day-labels span { height: 13px; display: flex; align-items: center; }\n .cells {\n display: grid; grid-template-rows: repeat(7, 1fr);\n grid-auto-flow: column; gap: 2px; flex: 1;\n }\n .cell {\n width: 13px; height: 13px; border-radius: 2px; cursor: pointer;\n transition: all 0.15s ease; outline: 1px solid rgba(27,31,35,0.06);\n }\n .cell:hover {\n outline: 2px solid #58a6ff; outline-offset: -1px;\n transform: scale(1.3); z-index: 1;\n }\n .cell.empty { visibility: hidden; }\n .level-0 { background: ${c0}; }\n .level-1 { background: ${c1}; }\n .level-2 { background: ${c2}; }\n .level-3 { background: ${c3}; }\n .level-4 { background: ${c4}; }\n .stats-bar {\n display: flex; justify-content: space-around; margin-top: 20px;\n padding-top: 16px; border-top: 1px solid #21262d;\n flex-wrap: wrap; gap: 12px;\n }\n .stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }\n .stat-value { font-size: 22px; font-weight: 700; color: ${c4}; }\n .stat-label { font-size: 12px; color: #8b949e; }\n",
|
| 54 |
+
"js_on_load": "\n element.addEventListener('click', (e) => {\n if (e.target && e.target.classList.contains('cell') && !e.target.classList.contains('empty')) {\n const date = e.target.dataset.date;\n const cur = parseInt(e.target.dataset.count) || 0;\n const next = cur >= 12 ? 0 : cur + 1;\n const nv = {...(props.value || {})};\n if (next === 0) delete nv[date]; else nv[date] = next;\n props.value = nv;\n trigger('change');\n }\n });\n",
|
| 55 |
+
"default_props": {
|
| 56 |
+
"value": {},
|
| 57 |
+
"year": 2025,
|
| 58 |
+
"c0": "#161b22",
|
| 59 |
+
"c1": "#0e4429",
|
| 60 |
+
"c2": "#006d32",
|
| 61 |
+
"c3": "#26a641",
|
| 62 |
+
"c4": "#39d353"
|
| 63 |
+
},
|
| 64 |
+
"python_code": "class ContributionHeatmap(gr.HTML):\n \"\"\"Reusable GitHub-style contribution heatmap built on gr.HTML.\"\"\"\n\n def __init__(self, value=None, year=2025, theme=\"green\",\n c0=None, c1=None, c2=None, c3=None, c4=None, **kwargs):\n if value is None:\n value = {}\n # Use explicit c0-c4 if provided (from gr.HTML updates), else derive from theme\n colors = COLOR_SCHEMES.get(theme, COLOR_SCHEMES[\"green\"])\n super().__init__(\n value=value,\n year=year,\n c0=c0 or colors[0],\n c1=c1 or colors[1],\n c2=c2 or colors[2],\n c3=c3 or colors[3],\n c4=c4 or colors[4],\n html_template=HEATMAP_HTML,\n css_template=HEATMAP_CSS,\n js_on_load=HEATMAP_JS,\n **kwargs,\n )\n\n def api_info(self):\n return {\"type\": \"object\", \"description\": \"Dict mapping YYYY-MM-DD to int counts\"}\n",
|
| 65 |
+
"head": "",
|
| 66 |
+
"repo_url": "https://huggingface.co/spaces/ysharma/github-contribution-heatmap"
|
| 67 |
},
|
| 68 |
{
|
| 69 |
"id": "spin-wheel",
|
| 70 |
"name": "Spin Wheel",
|
| 71 |
+
"description": "Spin the wheel to win a prize!",
|
| 72 |
+
"author": "ysharma",
|
| 73 |
"tags": [],
|
| 74 |
"category": "display",
|
| 75 |
"html_template": "\n<div class=\"wheel-container\">\n <div class=\"wheel-wrapper\">\n <!-- Pointer -->\n <div class=\"wheel-pointer\">\u25bc</div>\n \n <!-- Wheel - rotation prop preserves position across re-renders -->\n <div class=\"wheel\" id=\"prize-wheel\" style=\"transform: rotate(${rotation || 0}deg);\">\n <svg viewBox=\"0 0 400 400\" class=\"wheel-svg\">\n ${(() => {\n const segments = JSON.parse(segments_json || '[]');\n const cx = 200, cy = 200, r = 180;\n let html = '';\n \n segments.forEach((seg, i) => {\n const startRad = (seg.startAngle - 90) * Math.PI / 180;\n const endRad = (seg.endAngle - 90) * Math.PI / 180;\n const x1 = cx + r * Math.cos(startRad);\n const y1 = cy + r * Math.sin(startRad);\n const x2 = cx + r * Math.cos(endRad);\n const y2 = cy + r * Math.sin(endRad);\n const largeArc = seg.endAngle - seg.startAngle > 180 ? 1 : 0;\n \n const d = `M ${cx} ${cy} L ${x1} ${y1} A ${r} ${r} 0 ${largeArc} 1 ${x2} ${y2} Z`;\n html += `<path d=\"${d}\" fill=\"${seg.color}\" stroke=\"#fff\" stroke-width=\"2\" class=\"segment\" data-index=\"${i}\"/>`;\n \n // Text label\n const midRad = (seg.midAngle - 90) * Math.PI / 180;\n const textR = r * 0.65;\n const tx = cx + textR * Math.cos(midRad);\n const ty = cy + textR * Math.sin(midRad);\n const rotation = seg.midAngle;\n html += `<text x=\"${tx}\" y=\"${ty}\" fill=\"#fff\" font-size=\"11\" font-weight=\"bold\" \n text-anchor=\"middle\" dominant-baseline=\"middle\" \n transform=\"rotate(${rotation}, ${tx}, ${ty})\"\n style=\"text-shadow: 1px 1px 2px rgba(0,0,0,0.5); pointer-events: none;\">${seg.label}</text>`;\n });\n \n // Center circle\n html += `<circle cx=\"200\" cy=\"200\" r=\"35\" fill=\"#1a1a2e\" stroke=\"#FFD700\" stroke-width=\"4\" class=\"center-btn\"/>`;\n html += `<text x=\"200\" y=\"200\" fill=\"#FFD700\" font-size=\"14\" font-weight=\"bold\" text-anchor=\"middle\" dominant-baseline=\"middle\" style=\"pointer-events: none;\">SPIN</text>`;\n \n return html;\n })()}\n </svg>\n </div>\n \n <!-- Decorative lights -->\n <div class=\"wheel-lights\">\n ${Array.from({length: 16}, (_, i) => `<div class=\"light\" style=\"--i: ${i}\"></div>`).join('')}\n </div>\n </div>\n \n <!-- Result Display -->\n <div class=\"result-display ${value ? 'show' : ''}\" id=\"result-display\">\n ${value ? `<div class=\"result-text\">\ud83c\udf89 You won: <strong>${value}</strong></div>` : '<div class=\"result-text\">Spin to win!</div>'}\n </div>\n \n <!-- Spin Button -->\n <button class=\"spin-button\" id=\"spin-btn\">\n \ud83c\udfb0 SPIN TO WIN!\n </button>\n \n <!-- Confetti container -->\n <div class=\"confetti-container\" id=\"confetti\"></div>\n</div>\n",
|