{ "id": "star-rating", "name": "Star Rating", "description": "Click stars to set a rating from 1 to 5", "author": "gradio", "tags": [ "input", "rating", "stars" ], "category": "input", "html_template": "

${label} rating:

\n${Array.from({length: 5}, (_, i) => ``).join('')}", "css_template": "img { height: 50px; display: inline-block; cursor: pointer; }\n.faded { filter: grayscale(100%); opacity: 0.3; }", "js_on_load": "const imgs = element.querySelectorAll('img');\nimgs.forEach((img, index) => {\n img.addEventListener('click', () => {\n props.value = index + 1;\n });\n});", "default_props": { "value": 3, "label": "Food" }, "python_code": "class StarRating(gr.HTML):\n def __init__(self, label, value=0, **kwargs):\n html_template = \"\"\"\n

${label} rating:

\n ${Array.from({length: 5}, (_, i) => ``).join('')}\n \"\"\"\n css_template = \"\"\"\n img { height: 50px; display: inline-block; cursor: pointer; }\n .faded { filter: grayscale(100%); opacity: 0.3; }\n \"\"\"\n js_on_load = \"\"\"\n const imgs = element.querySelectorAll('img');\n imgs.forEach((img, index) => {\n img.addEventListener('click', () => {\n props.value = index + 1;\n });\n });\n \"\"\"\n super().__init__(\n value=value, label=label,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )\n\n def api_info(self):\n return {\"type\": \"integer\", \"minimum\": 0, \"maximum\": 5}" }