freddyaboulton HF Staff commited on
Commit
c5cf27c
·
verified ·
1 Parent(s): ac70064

Upload components.json with huggingface_hub

Browse files
Files changed (1) hide show
  1. components.json +282 -0
components.json ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "id": "star-rating",
4
+ "name": "Star Rating",
5
+ "description": "Click stars to set a rating from 1 to 5",
6
+ "author": "gradio",
7
+ "tags": [
8
+ "input",
9
+ "rating",
10
+ "stars"
11
+ ],
12
+ "category": "input",
13
+ "html_template": "<h2>${label} rating:</h2>\n${Array.from({length: 5}, (_, i) => `<img class='${i < value ? '' : 'faded'}' src='https://upload.wikimedia.org/wikipedia/commons/d/df/Award-star-gold-3d.svg'>`).join('')}",
14
+ "css_template": "img { height: 50px; display: inline-block; cursor: pointer; }\n.faded { filter: grayscale(100%); opacity: 0.3; }",
15
+ "js_on_load": "const imgs = element.querySelectorAll('img');\nimgs.forEach((img, index) => {\n img.addEventListener('click', () => {\n props.value = index + 1;\n });\n});",
16
+ "default_props": {
17
+ "value": 3,
18
+ "label": "Food"
19
+ },
20
+ "python_code": "class StarRating(gr.HTML):\n def __init__(self, label, value=0, **kwargs):\n html_template = \"\"\"\n <h2>${label} rating:</h2>\n ${Array.from({length: 5}, (_, i) => `<img class='${i < value ? '' : 'faded'}' src='https://upload.wikimedia.org/wikipedia/commons/d/df/Award-star-gold-3d.svg'>`).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}"
21
+ },
22
+ {
23
+ "id": "button-set",
24
+ "name": "Button Set",
25
+ "description": "Multiple buttons that trigger events with click data",
26
+ "author": "gradio",
27
+ "tags": [
28
+ "input",
29
+ "buttons",
30
+ "events"
31
+ ],
32
+ "category": "input",
33
+ "html_template": "<button id='A'>A</button>\n<button id='B'>B</button>\n<button id='C'>C</button>",
34
+ "css_template": "button {\n padding: 10px 20px;\n background-color: #f97316;\n color: white;\n border: none;\n border-radius: 8px;\n cursor: pointer;\n font-weight: 600;\n margin-right: 8px;\n transition: background 0.15s;\n}\nbutton:hover { background-color: #ea580c; }",
35
+ "js_on_load": "const buttons = element.querySelectorAll('button');\nbuttons.forEach(button => {\n button.addEventListener('click', () => {\n trigger('click', {clicked: button.innerText});\n });\n});",
36
+ "default_props": {},
37
+ "python_code": "button_set = gr.HTML(\n html_template=\"\"\"\n <button id='A'>A</button>\n <button id='B'>B</button>\n <button id='C'>C</button>\n \"\"\",\n css_template=\"\"\"\n button {\n padding: 10px 20px;\n background-color: #f97316;\n color: white; border: none;\n border-radius: 8px; cursor: pointer;\n }\n button:hover { background-color: #ea580c; }\n \"\"\",\n js_on_load=\"\"\"\n const buttons = element.querySelectorAll('button');\n buttons.forEach(button => {\n button.addEventListener('click', () => {\n trigger('click', {clicked: button.innerText});\n });\n });\n \"\"\"\n)\n\ndef on_button_click(evt: gr.EventData):\n return evt.clicked\n\nbutton_set.click(on_button_click, outputs=clicked_box)"
38
+ },
39
+ {
40
+ "id": "progress-bar",
41
+ "name": "Progress Bar",
42
+ "description": "Interactive progress bar - click the track to set progress",
43
+ "author": "gradio",
44
+ "tags": [
45
+ "display",
46
+ "progress",
47
+ "animation"
48
+ ],
49
+ "category": "display",
50
+ "html_template": "<div class=\"progress-container\">\n <div class=\"progress-label\">${label}</div>\n <div class=\"progress-track\">\n <div class=\"progress-fill\" style=\"width: ${value}%\"></div>\n </div>\n <div class=\"progress-text\">${value}%</div>\n</div>",
51
+ "css_template": ".progress-container { padding: 8px 0; }\n.progress-label { font-weight: 600; margin-bottom: 8px; font-size: 15px; }\n.progress-track { width: 100%; height: 24px; background: #e5e7eb; border-radius: 12px; overflow: hidden; cursor: pointer; }\n.progress-fill { height: 100%; background: linear-gradient(90deg, #f97316, #fb923c); border-radius: 12px; transition: width 0.4s ease; }\n.progress-text { margin-top: 6px; font-size: 14px; color: #6b7280; text-align: right; font-variant-numeric: tabular-nums; }",
52
+ "js_on_load": "const track = element.querySelector('.progress-track');\ntrack.addEventListener('click', (e) => {\n const rect = track.getBoundingClientRect();\n const pct = Math.round(((e.clientX - rect.left) / rect.width) * 100);\n props.value = Math.max(0, Math.min(100, pct));\n});",
53
+ "default_props": {
54
+ "value": 65,
55
+ "label": "Upload Progress"
56
+ },
57
+ "python_code": "progress = gr.HTML(\n value=65,\n label=\"Upload Progress\",\n html_template=\"\"\"\n <div class=\"progress-container\">\n <div class=\"progress-label\">${label}</div>\n <div class=\"progress-track\">\n <div class=\"progress-fill\" style=\"width: ${value}%\"></div>\n </div>\n <div class=\"progress-text\">${value}%</div>\n </div>\n \"\"\",\n css_template=\"\"\"\n .progress-track {\n width: 100%; height: 24px;\n background: #e5e7eb; border-radius: 12px;\n overflow: hidden; cursor: pointer;\n }\n .progress-fill {\n height: 100%;\n background: linear-gradient(90deg, #f97316, #fb923c);\n border-radius: 12px; transition: width 0.4s ease;\n }\n \"\"\",\n js_on_load=\"\"\"\n const track = element.querySelector('.progress-track');\n track.addEventListener('click', (e) => {\n const rect = track.getBoundingClientRect();\n const pct = Math.round(\n ((e.clientX - rect.left) / rect.width) * 100\n );\n props.value = Math.max(0, Math.min(100, pct));\n });\n \"\"\"\n)"
58
+ },
59
+ {
60
+ "id": "likert-scale",
61
+ "name": "Likert Scale",
62
+ "description": "Agreement scale from Strongly Disagree to Strongly Agree",
63
+ "author": "gradio",
64
+ "tags": [
65
+ "input",
66
+ "survey",
67
+ "scale"
68
+ ],
69
+ "category": "input",
70
+ "html_template": "<div class=\"likert-container\">\n <div class=\"likert-question\">${question}</div>\n <div class=\"likert-scale\">\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n <label class=\"likert-option ${value === i + 1 ? 'selected' : ''}\">\n <input type=\"radio\" name=\"likert\" value=\"${i + 1}\" ${value === i + 1 ? 'checked' : ''} />\n <span class=\"likert-dot\"></span>\n <span class=\"likert-label\">${label}</span>\n </label>\n `).join('')}\n </div>\n</div>",
71
+ "css_template": ".likert-container { padding: 8px 0; }\n.likert-question { font-weight: 600; margin-bottom: 16px; font-size: 15px; }\n.likert-scale { display: flex; justify-content: space-between; gap: 4px; }\n.likert-option { display: flex; flex-direction: column; align-items: center; cursor: pointer; flex: 1; gap: 8px; }\n.likert-option input { display: none; }\n.likert-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #d1d5db; transition: all 0.2s; }\n.likert-option:hover .likert-dot { border-color: #f97316; }\n.likert-option.selected .likert-dot { background: #f97316; border-color: #f97316; }\n.likert-label { font-size: 11px; text-align: center; color: #6b7280; line-height: 1.3; }",
72
+ "js_on_load": "const radios = element.querySelectorAll('input[type=\"radio\"]');\nradios.forEach(radio => {\n radio.addEventListener('change', () => {\n props.value = parseInt(radio.value);\n });\n});",
73
+ "default_props": {
74
+ "value": 0,
75
+ "question": "This component is easy to use"
76
+ },
77
+ "python_code": "class LikertScale(gr.HTML):\n def __init__(self, question=\"Rate this item\", value=0, **kwargs):\n html_template = \"\"\"\n <div class=\"likert-container\">\n <div class=\"likert-question\">${question}</div>\n <div class=\"likert-scale\">\n ${['Strongly Disagree', 'Disagree', 'Neutral', 'Agree', 'Strongly Agree'].map((label, i) => `\n <label class=\"likert-option ${value === i + 1 ? 'selected' : ''}\">\n <input type=\"radio\" name=\"likert\" value=\"${i + 1}\" ${value === i + 1 ? 'checked' : ''} />\n <span class=\"likert-dot\"></span>\n <span class=\"likert-label\">${label}</span>\n </label>\n `).join('')}\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .likert-scale { display: flex; justify-content: space-between; }\n .likert-option { display: flex; flex-direction: column; align-items: center; cursor: pointer; }\n .likert-dot { width: 24px; height: 24px; border-radius: 50%; border: 2px solid #d1d5db; }\n .likert-option.selected .likert-dot { background: #f97316; border-color: #f97316; }\n \"\"\"\n js_on_load = \"\"\"\n const radios = element.querySelectorAll('input[type=\"radio\"]');\n radios.forEach(radio => {\n radio.addEventListener('change', () => {\n props.value = parseInt(radio.value);\n });\n });\n \"\"\"\n super().__init__(\n value=value, question=question,\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}"
78
+ },
79
+ {
80
+ "id": "tag-input",
81
+ "name": "Tag Input",
82
+ "description": "Add and remove tags with keyboard input",
83
+ "author": "gradio",
84
+ "tags": [
85
+ "input",
86
+ "tags",
87
+ "text"
88
+ ],
89
+ "category": "input",
90
+ "html_template": "<div class=\"tag-input-container\">\n <div class=\"tag-list\">\n ${(value || []).map((tag, i) => `\n <span class=\"tag-pill\">\n ${tag}\n <button class=\"tag-remove\" data-index=\"${i}\">&times;</button>\n </span>\n `).join('')}\n <input type=\"text\" class=\"tag-text-input\" placeholder=\"${(value || []).length === 0 ? 'Type a tag and press Enter...' : 'Add more...'}\" />\n </div>\n</div>",
91
+ "css_template": ".tag-input-container { padding: 4px 0; }\n.tag-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; border: 1px solid #e5e7eb; border-radius: 8px; min-height: 42px; }\n.tag-pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; background: #fff7ed; color: #ea580c; border-radius: 16px; font-size: 13px; font-weight: 500; border: 1px solid #fed7aa; }\n.tag-remove { background: none; border: none; color: #ea580c; cursor: pointer; font-size: 16px; padding: 0 2px; line-height: 1; opacity: 0.6; }\n.tag-remove:hover { opacity: 1; }\n.tag-text-input { border: none; outline: none; flex: 1; min-width: 120px; font-size: 14px; padding: 4px; background: transparent; }",
92
+ "js_on_load": "const input = element.querySelector('.tag-text-input');\ninput.addEventListener('keydown', (e) => {\n if (e.key === 'Enter' && input.value.trim()) {\n e.preventDefault();\n const tags = [...(props.value || []), input.value.trim()];\n props.value = tags;\n input.value = '';\n }\n if (e.key === 'Backspace' && !input.value && props.value && props.value.length > 0) {\n props.value = props.value.slice(0, -1);\n }\n});\nelement.addEventListener('click', (e) => {\n const btn = e.target.closest('.tag-remove');\n if (!btn) return;\n const idx = parseInt(btn.dataset.index);\n const tags = [...(props.value || [])];\n tags.splice(idx, 1);\n props.value = tags;\n});",
93
+ "default_props": {
94
+ "value": [
95
+ "python",
96
+ "gradio",
97
+ "html"
98
+ ]
99
+ },
100
+ "python_code": "class TagInput(gr.HTML):\n def __init__(self, value=None, **kwargs):\n html_template = \"\"\"\n <div class=\"tag-input-container\">\n <div class=\"tag-list\">\n ${(value || []).map((tag, i) => `\n <span class=\"tag-pill\">\n ${tag}\n <button class=\"tag-remove\" data-index=\"${i}\">&times;</button>\n </span>\n `).join('')}\n <input type=\"text\" class=\"tag-text-input\"\n placeholder=\"Type a tag and press Enter...\" />\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .tag-list {\n display: flex; flex-wrap: wrap; gap: 6px;\n padding: 8px; border: 1px solid #e5e7eb;\n border-radius: 8px;\n }\n .tag-pill {\n padding: 4px 10px; background: #fff7ed;\n color: #ea580c; border-radius: 16px;\n font-size: 13px; border: 1px solid #fed7aa;\n }\n \"\"\"\n js_on_load = \"\"\"\n const input = element.querySelector('.tag-text-input');\n input.addEventListener('keydown', (e) => {\n if (e.key === 'Enter' && input.value.trim()) {\n e.preventDefault();\n props.value = [...(props.value || []), input.value.trim()];\n input.value = '';\n }\n });\n element.addEventListener('click', (e) => {\n const btn = e.target.closest('.tag-remove');\n if (!btn) return;\n const idx = parseInt(btn.dataset.index);\n const tags = [...(props.value || [])];\n tags.splice(idx, 1);\n props.value = tags;\n });\n \"\"\"\n super().__init__(\n value=value or [],\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\": \"array\", \"items\": {\"type\": \"string\"}}"
101
+ },
102
+ {
103
+ "id": "colored-checkbox-group",
104
+ "name": "Colored Checkbox Group",
105
+ "description": "Multi-select checkbox group with custom colors per option",
106
+ "author": "gradio",
107
+ "tags": [
108
+ "input",
109
+ "checkbox",
110
+ "color"
111
+ ],
112
+ "category": "input",
113
+ "html_template": "<div class=\"colored-checkbox-container\">\n ${label ? `<label class=\"container-label\">${label}</label>` : ''}\n <div class=\"colored-checkbox-group\">\n ${choices.map((choice, i) => `\n <label class=\"checkbox-label\" data-color-index=\"${i}\">\n <input type=\"checkbox\" value=\"${choice}\" ${(value || []).includes(choice) ? 'checked' : ''}>\n ${choice}\n </label>\n `).join('')}\n </div>\n</div>",
114
+ "css_template": ".colored-checkbox-container { border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; }\n.container-label { display: block; margin-bottom: 12px; font-weight: 600; }\n.colored-checkbox-group { display: flex; flex-direction: column; gap: 6px; }\n.checkbox-label { display: flex; align-items: center; cursor: pointer; padding: 4px 0; }\n.checkbox-label input { margin-right: 8px; }\n${choices.map((choice, i) => `.checkbox-label[data-color-index=\"${i}\"] { color: ${colors[i]}; }`).join(' ')}",
115
+ "js_on_load": "const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\ncheckboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n props.value = Array.from(checkboxes)\n .filter(cb => cb.checked)\n .map(cb => cb.value);\n });\n});",
116
+ "default_props": {
117
+ "value": [],
118
+ "choices": [
119
+ "Apple",
120
+ "Banana",
121
+ "Cherry"
122
+ ],
123
+ "colors": [
124
+ "#dc2626",
125
+ "#eab308",
126
+ "#dc2626"
127
+ ],
128
+ "label": "Select fruits"
129
+ },
130
+ "python_code": "class ColoredCheckboxGroup(gr.HTML):\n def __init__(self, choices, *, value=None, colors, label=None, **kwargs):\n html_template = \"\"\"\n <div class=\"colored-checkbox-container\">\n ${label ? `<label>${label}</label>` : ''}\n <div class=\"colored-checkbox-group\">\n ${choices.map((choice, i) => `\n <label class=\"checkbox-label\" data-color-index=\"${i}\">\n <input type=\"checkbox\" value=\"${choice}\"\n ${(value || []).includes(choice) ? 'checked' : ''}>\n ${choice}\n </label>\n `).join('')}\n </div>\n </div>\n \"\"\"\n css_template = \"\"\"\n .colored-checkbox-group { display: flex; flex-direction: column; gap: 6px; }\n .checkbox-label { display: flex; align-items: center; cursor: pointer; }\n ${choices.map((choice, i) =>\n `.checkbox-label[data-color-index=\"${i}\"] { color: ${colors[i]}; }`\n ).join(' ')}\n \"\"\"\n js_on_load = \"\"\"\n const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\n checkboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n props.value = Array.from(checkboxes)\n .filter(cb => cb.checked)\n .map(cb => cb.value);\n });\n });\n \"\"\"\n super().__init__(\n value=value or [], choices=choices,\n colors=colors, label=label,\n html_template=html_template,\n css_template=css_template,\n js_on_load=js_on_load, **kwargs\n )"
131
+ },
132
+ {
133
+ "id": "todo-list",
134
+ "name": "Todo List",
135
+ "description": "Interactive checklist with strikethrough on completed items",
136
+ "author": "gradio",
137
+ "tags": [
138
+ "form",
139
+ "todo",
140
+ "checklist"
141
+ ],
142
+ "category": "form",
143
+ "html_template": "<h2>Todo List</h2>\n<ul>\n ${value.map((item, index) => `\n <li style=\"text-decoration: ${completed.includes(index) ? 'line-through' : 'none'}; list-style: none; padding: 6px 0;\">\n <input type=\"checkbox\" ${completed.includes(index) ? 'checked' : ''} data-index=\"${index}\" />\n ${item}\n </li>\n `).join('')}\n</ul>",
144
+ "css_template": "h2 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }\nul { padding: 0; margin: 0; }\nli { font-size: 14px; transition: opacity 0.2s; }\nli input { margin-right: 8px; cursor: pointer; }",
145
+ "js_on_load": "const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\ncheckboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n const index = parseInt(checkbox.getAttribute('data-index'));\n let completed = props.completed || [];\n if (checkbox.checked) {\n if (!completed.includes(index)) {\n completed.push(index);\n }\n } else {\n completed = completed.filter(i => i !== index);\n }\n props.completed = [...completed];\n });\n});",
146
+ "default_props": {
147
+ "value": [
148
+ "Buy groceries",
149
+ "Walk the dog",
150
+ "Read a book",
151
+ "Write code"
152
+ ],
153
+ "completed": [
154
+ 1
155
+ ]
156
+ },
157
+ "python_code": "class TodoList(gr.HTML):\n def __init__(self, value=None, completed=None, **kwargs):\n html_template = \"\"\"\n <h2>Todo List</h2>\n <ul>\n ${value.map((item, index) => `\n <li style=\"text-decoration: ${completed.includes(index) ? 'line-through' : 'none'};\">\n <input type=\"checkbox\" ${completed.includes(index) ? 'checked' : ''} data-index=\"${index}\" />\n ${item}\n </li>\n `).join('')}\n </ul>\n \"\"\"\n js_on_load = \"\"\"\n const checkboxes = element.querySelectorAll('input[type=\"checkbox\"]');\n checkboxes.forEach(checkbox => {\n checkbox.addEventListener('change', () => {\n const index = parseInt(checkbox.getAttribute('data-index'));\n let completed = props.completed || [];\n if (checkbox.checked) {\n if (!completed.includes(index)) completed.push(index);\n } else {\n completed = completed.filter(i => i !== index);\n }\n props.completed = [...completed];\n });\n });\n \"\"\"\n super().__init__(\n value=value or [], completed=completed or [],\n html_template=html_template,\n js_on_load=js_on_load, **kwargs\n )"
158
+ },
159
+ {
160
+ "id": "audio-gallery",
161
+ "name": "Audio Gallery",
162
+ "description": "Grid of audio players with waveform visualization and selection",
163
+ "author": "gradio",
164
+ "tags": [
165
+ "display",
166
+ "audio",
167
+ "gallery",
168
+ "media"
169
+ ],
170
+ "category": "display",
171
+ "html_template": "<div class=\"audio-gallery-container\">\n ${label ? `<label class=\"container-label\">${label}</label>` : ''}\n <div class=\"audio-gallery-grid\" style=\"grid-template-columns: repeat(${columns}, 1fr);\">\n ${audio_urls.map((url, i) => `\n <div class=\"audio-item\" data-index=\"${i}\">\n <div class=\"audio-label\">${labels && labels[i] ? labels[i] : 'Audio ' + (i + 1)}</div>\n <canvas class=\"waveform-canvas\" data-url=\"${url}\" width=\"300\" height=\"80\"></canvas>\n <audio src=\"${url}\" preload=\"metadata\" ${value === url ? 'data-selected=\"true\"' : ''}></audio>\n <div class=\"audio-controls\">\n <button class=\"play-btn\">\u25b6</button>\n <div class=\"time-display\">0:00</div>\n </div>\n </div>\n `).join('')}\n </div>\n</div>",
172
+ "css_template": ".audio-gallery-container { padding: 8px; }\n.container-label { display: block; margin-bottom: 12px; font-weight: 600; }\n.audio-gallery-grid { display: grid; gap: 12px; }\n.audio-item { border: 2px solid #e5e7eb; border-radius: 10px; padding: 12px; cursor: pointer; transition: all 0.2s; }\n.audio-item:hover { border-color: #f97316; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }\n.audio-item[data-selected=\"true\"] { border-color: #f97316; background-color: #fff7ed; }\n.audio-label { margin-bottom: 8px; text-align: center; font-size: 13px; font-weight: 500; }\n.waveform-canvas { width: 100%; height: 80px; background: #f9fafb; border-radius: 6px; margin-bottom: 8px; }\n.audio-controls { display: flex; align-items: center; gap: 8px; }\n.play-btn { width: 32px; height: 32px; border-radius: 50%; border: none; background: #f97316; color: white; cursor: pointer; font-size: 14px; }\n.play-btn:hover { opacity: 0.8; }\n.time-display { font-size: 12px; color: #6b7280; }",
173
+ "js_on_load": "const audioItems = element.querySelectorAll('.audio-item');\naudioItems.forEach((item, index) => {\n const canvas = item.querySelector('.waveform-canvas');\n const audio = item.querySelector('audio');\n const playBtn = item.querySelector('.play-btn');\n const timeDisplay = item.querySelector('.time-display');\n const ctx = canvas.getContext('2d');\n drawWaveform(canvas, ctx);\n item.addEventListener('click', (e) => {\n if (e.target === playBtn) return;\n audioItems.forEach(i => i.removeAttribute('data-selected'));\n item.setAttribute('data-selected', 'true');\n props.value = audio.src;\n });\n playBtn.addEventListener('click', (e) => {\n e.stopPropagation();\n if (audio.paused) {\n element.querySelectorAll('audio').forEach(a => a.pause());\n element.querySelectorAll('.play-btn').forEach(b => b.textContent = '\u25b6');\n audio.play();\n playBtn.textContent = '\u23f8';\n } else {\n audio.pause();\n playBtn.textContent = '\u25b6';\n }\n });\n audio.addEventListener('timeupdate', () => {\n const currentTime = Math.floor(audio.currentTime);\n const minutes = Math.floor(currentTime / 60);\n const seconds = currentTime % 60;\n timeDisplay.textContent = minutes + ':' + seconds.toString().padStart(2, '0');\n const progress = audio.currentTime / audio.duration;\n drawWaveform(canvas, ctx, progress);\n });\n audio.addEventListener('ended', () => {\n playBtn.textContent = '\u25b6';\n drawWaveform(canvas, ctx, 0);\n });\n});\nfunction drawWaveform(canvas, ctx, progress) {\n progress = progress || 0;\n const width = canvas.width;\n const height = canvas.height;\n const bars = 50;\n const barWidth = width / bars;\n ctx.clearRect(0, 0, width, height);\n for (let i = 0; i < bars; i++) {\n const barHeight = (Math.sin(i * 0.5) * 0.3 + 0.5) * height * 0.8;\n const x = i * barWidth;\n const y = (height - barHeight) / 2;\n ctx.fillStyle = i / bars < progress ? '#f97316' : '#d1d5db';\n ctx.fillRect(x, y, barWidth - 2, barHeight);\n }\n}",
174
+ "default_props": {
175
+ "value": null,
176
+ "audio_urls": [
177
+ "https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav",
178
+ "https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample-1-4.wav",
179
+ "https://github.com/gradio-app/gradio/raw/main/gradio/media_assets/audio/cantina.wav"
180
+ ],
181
+ "labels": [
182
+ "Sample 1",
183
+ "Sample 2",
184
+ "Cantina"
185
+ ],
186
+ "columns": 3,
187
+ "label": "Select an audio file"
188
+ },
189
+ "python_code": "class AudioGallery(gr.HTML):\n def __init__(self, audio_urls, *, value=None, labels=None,\n columns=3, label=None, **kwargs):\n html_template = \"\"\"\n <div class=\"audio-gallery-container\">\n ${label ? `<label>${label}</label>` : ''}\n <div class=\"audio-gallery-grid\"\n style=\"grid-template-columns: repeat(${columns}, 1fr);\">\n ${audio_urls.map((url, i) => `\n <div class=\"audio-item\" data-index=\"${i}\">\n <div class=\"audio-label\">\n ${labels && labels[i] ? labels[i] : 'Audio ' + (i+1)}\n </div>\n <canvas class=\"waveform-canvas\" width=\"300\" height=\"80\"></canvas>\n <audio src=\"${url}\" preload=\"metadata\"></audio>\n <div class=\"audio-controls\">\n <button class=\"play-btn\">\u25b6</button>\n <div class=\"time-display\">0:00</div>\n </div>\n </div>\n `).join('')}\n </div>\n </div>\n \"\"\"\n super().__init__(\n value=value, audio_urls=audio_urls,\n labels=labels, columns=columns, label=label,\n html_template=html_template,\n css_template=CSS_TEMPLATE,\n js_on_load=JS_ON_LOAD, **kwargs\n )"
190
+ },
191
+ {
192
+ "id": "kanban-board",
193
+ "name": "Kanban Board",
194
+ "description": "Drag-and-drop Kanban board with inline editing, priority labels, and search",
195
+ "author": "gradio",
196
+ "tags": [
197
+ "input",
198
+ "kanban",
199
+ "drag-drop",
200
+ "project-management"
201
+ ],
202
+ "category": "input",
203
+ "html_template": "<div class=\"kanban-wrapper\">\n <div class=\"kanban-header\">\n <h2>${board_title}</h2>\n <div class=\"header-right\">\n <div class=\"search-box\">\n <span class=\"search-icon\">\ud83d\udd0d</span>\n <input type=\"text\" class=\"search-input\" placeholder=\"Search cards...\" />\n </div>\n <div class=\"header-stats\">\n ${(() => {\n const cols = (value && value.columns) || [];\n const total = cols.reduce((sum, col) => sum + col.cards.length, 0);\n const done = cols.find(c => c.id === 'done');\n const doneCount = done ? done.cards.length : 0;\n const pct = total > 0 ? Math.round((doneCount / total) * 100) : 0;\n return '<span class=\"stat-pill\">\ud83d\udcca ' + total + ' tasks</span>' +\n '<span class=\"stat-pill done-pill\">\u2705 ' + doneCount + ' done (' + pct + '%)</span>';\n })()}\n </div>\n </div>\n </div>\n <div class=\"kb-progress-track\">\n ${(() => {\n const cols = (value && value.columns) || [];\n const total = cols.reduce((sum, col) => sum + col.cards.length, 0);\n const done = cols.find(c => c.id === 'done');\n const doneCount = done ? done.cards.length : 0;\n const pct = total > 0 ? Math.round((doneCount / total) * 100) : 0;\n return '<div class=\"kb-progress-bar\" style=\"width: ' + pct + '%\"></div>';\n })()}\n </div>\n <div class=\"kanban-board\">\n ${((value && value.columns) || []).map((col, colIdx) => `\n <div class=\"kanban-column ${col.collapsed ? 'collapsed' : ''}\" data-col-idx=\"${colIdx}\" data-col-id=\"${col.id}\">\n <div class=\"column-header\" style=\"border-top: 3px solid ${col.color}\">\n <div class=\"col-header-left\">\n <button class=\"collapse-btn\" data-col-idx=\"${colIdx}\">${col.collapsed ? '\u25b6' : '\u25bc'}</button>\n <span class=\"col-title\">${col.title}</span>\n </div>\n <span class=\"col-count\" style=\"background: ${col.color}22; color: ${col.color}\">${col.cards.length}</span>\n </div>\n <div class=\"card-list ${col.collapsed ? 'hidden' : ''}\" data-col-idx=\"${colIdx}\">\n ${col.cards.map((card, cardIdx) => `\n <div class=\"kanban-card\" draggable=\"true\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\" data-card-id=\"${card.id}\">\n <div class=\"card-priority priority-${card.priority}\"></div>\n <div class=\"card-content\">\n <div class=\"card-text\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\">${card.text}</div>\n <div class=\"card-footer\">\n <div class=\"card-tags\">\n ${(card.tags || []).map(t => '<span class=\"kb-tag\">' + t + '</span>').join('')}\n </div>\n <div class=\"card-actions\">\n <button class=\"priority-cycle\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\" title=\"Cycle priority\">\n ${card.priority === 'high' ? '\ud83d\udd34' : card.priority === 'medium' ? '\ud83d\udfe1' : '\ud83d\udfe2'}\n </button>\n <button class=\"delete-card\" data-col-idx=\"${colIdx}\" data-card-idx=\"${cardIdx}\" title=\"Delete card\">\u2715</button>\n </div>\n </div>\n </div>\n </div>\n `).join('')}\n </div>\n <div class=\"add-card-area ${col.collapsed ? 'hidden' : ''}\">\n <input type=\"text\" class=\"add-card-input\" data-col-idx=\"${colIdx}\" placeholder=\"+ Add a card\u2026 \u23ce\" />\n </div>\n </div>\n `).join('')}\n </div>\n</div>",
204
+ "css_template": ".kanban-wrapper {\n background: linear-gradient(135deg, #0f172a 0%, #1a1a2e 100%);\n border-radius: 16px;\n padding: 24px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n color: #e2e8f0;\n overflow-x: auto;\n}\n.kanban-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 12px; }\n.kanban-header h2 { margin: 0; font-size: 22px; color: #f8fafc; letter-spacing: -0.3px; }\n.header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }\n.search-box { display: flex; align-items: center; background: rgba(255,255,255,0.06); border: 1px solid #334155; border-radius: 10px; padding: 4px 12px; transition: all 0.2s; }\n.search-box:focus-within { border-color: #6366f1; background: rgba(99, 102, 241, 0.06); }\n.search-icon { font-size: 13px; margin-right: 6px; }\n.search-input { background: none; border: none; color: #e2e8f0; font-size: 13px; outline: none; width: 140px; }\n.search-input::placeholder { color: #475569; }\n.header-stats { display: flex; gap: 8px; }\n.stat-pill { background: rgba(255,255,255,0.08); padding: 5px 14px; border-radius: 12px; font-size: 13px; color: #94a3b8; font-weight: 500; }\n.done-pill { color: #10b981; }\n.kb-progress-track { height: 4px; background: rgba(255,255,255,0.08); border-radius: 4px; margin-bottom: 20px; overflow: hidden; }\n.kb-progress-bar { height: 100%; background: linear-gradient(90deg, #6366f1, #10b981); border-radius: 4px; transition: width 0.5s ease; }\n.kanban-board { display: flex; gap: 16px; min-height: 400px; padding-bottom: 8px; }\n.kanban-column { background: #1e293b; border-radius: 12px; min-width: 270px; max-width: 310px; flex: 1; display: flex; flex-direction: column; transition: min-width 0.3s, max-width 0.3s; }\n.kanban-column.collapsed { min-width: 60px; max-width: 60px; }\n.column-header { padding: 14px 14px 10px; display: flex; justify-content: space-between; align-items: center; border-radius: 12px 12px 0 0; user-select: none; }\n.col-header-left { display: flex; align-items: center; gap: 8px; }\n.collapse-btn { background: none; border: none; color: #64748b; cursor: pointer; font-size: 10px; padding: 2px 4px; border-radius: 4px; transition: color 0.2s; }\n.collapse-btn:hover { color: #e2e8f0; }\n.col-title { font-weight: 600; font-size: 14px; white-space: nowrap; }\n.col-count { min-width: 26px; height: 26px; border-radius: 13px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }\n.card-list { flex: 1; padding: 6px 10px; min-height: 60px; transition: background 0.2s; }\n.card-list.hidden, .add-card-area.hidden { display: none; }\n.card-list.drag-over { background: rgba(99, 102, 241, 0.08); border-radius: 8px; }\n.kanban-card { background: #0f172a; border: 1px solid #334155; border-radius: 10px; padding: 12px 12px 12px 16px; margin-bottom: 8px; cursor: grab; transition: all 0.15s ease; position: relative; overflow: hidden; animation: cardIn 0.2s ease; }\n.kanban-card:hover { border-color: #6366f1; transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }\n.kanban-card.dragging { opacity: 0.4; transform: rotate(2deg) scale(0.97); }\n.kanban-card.search-hidden { display: none; }\n.kanban-card.search-highlight { border-color: #f59e0b; box-shadow: 0 0 0 1px #f59e0b44; }\n.card-priority { width: 4px; height: 100%; position: absolute; left: 0; top: 0; border-radius: 10px 0 0 10px; }\n.priority-high { background: #ef4444; }\n.priority-medium { background: #f59e0b; }\n.priority-low { background: #10b981; }\n.card-content { padding-left: 4px; }\n.card-text { font-size: 13px; line-height: 1.5; color: #e2e8f0; cursor: text; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; transition: background 0.15s; }\n.card-text:hover { background: rgba(255,255,255,0.04); }\n.card-text.editing { background: rgba(99, 102, 241, 0.1); outline: 1px solid #6366f1; min-height: 1.5em; }\n.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }\n.card-tags { display: flex; gap: 4px; flex-wrap: wrap; }\n.kb-tag { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 500; }\n.card-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }\n.kanban-card:hover .card-actions { opacity: 1; }\n.priority-cycle, .delete-card { background: none; border: none; cursor: pointer; font-size: 13px; padding: 3px 6px; border-radius: 6px; transition: all 0.15s; color: #475569; }\n.delete-card:hover { color: #ef4444; background: rgba(239, 68, 68, 0.1); }\n.priority-cycle:hover { background: rgba(255,255,255,0.08); }\n.add-card-area { padding: 6px 10px 14px; }\n.add-card-input { width: 100%; background: rgba(255,255,255,0.04); border: 1px dashed #334155; border-radius: 10px; padding: 10px 14px; color: #94a3b8; font-size: 13px; outline: none; transition: all 0.2s; box-sizing: border-box; }\n.add-card-input:focus { border-color: #6366f1; border-style: solid; background: rgba(99, 102, 241, 0.05); color: #e2e8f0; }\n.add-card-input::placeholder { color: #475569; }\n@keyframes cardIn { from { opacity: 0; transform: translateY(-8px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }",
205
+ "js_on_load": "let dragSrcColIdx = null;\nlet dragSrcCardIdx = null;\nelement.addEventListener('dragstart', (e) => {\n const card = e.target.closest('.kanban-card');\n if (!card) return;\n dragSrcColIdx = parseInt(card.dataset.colIdx);\n dragSrcCardIdx = parseInt(card.dataset.cardIdx);\n card.classList.add('dragging');\n e.dataTransfer.effectAllowed = 'move';\n});\nelement.addEventListener('dragend', (e) => {\n const card = e.target.closest('.kanban-card');\n if (card) card.classList.remove('dragging');\n element.querySelectorAll('.card-list').forEach(cl => cl.classList.remove('drag-over'));\n});\nelement.addEventListener('dragover', (e) => {\n e.preventDefault();\n const cardList = e.target.closest('.card-list');\n if (cardList) cardList.classList.add('drag-over');\n});\nelement.addEventListener('dragleave', (e) => {\n const cardList = e.target.closest('.card-list');\n if (cardList && !cardList.contains(e.relatedTarget)) {\n cardList.classList.remove('drag-over');\n }\n});\nelement.addEventListener('drop', (e) => {\n e.preventDefault();\n const cardList = e.target.closest('.card-list');\n if (!cardList || dragSrcColIdx === null) return;\n cardList.classList.remove('drag-over');\n const destColIdx = parseInt(cardList.dataset.colIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n const card = nv.columns[dragSrcColIdx].cards.splice(dragSrcCardIdx, 1)[0];\n const cardElements = cardList.querySelectorAll('.kanban-card:not(.dragging)');\n let insertIdx = nv.columns[destColIdx].cards.length;\n for (let i = 0; i < cardElements.length; i++) {\n const rect = cardElements[i].getBoundingClientRect();\n if (e.clientY < rect.top + rect.height / 2) { insertIdx = i; break; }\n }\n nv.columns[destColIdx].cards.splice(insertIdx, 0, card);\n props.value = nv;\n trigger('change');\n dragSrcColIdx = null;\n dragSrcCardIdx = null;\n});\nelement.addEventListener('click', (e) => {\n const delBtn = e.target.closest('.delete-card');\n if (!delBtn) return;\n e.stopPropagation();\n const colIdx = parseInt(delBtn.dataset.colIdx);\n const cardIdx = parseInt(delBtn.dataset.cardIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].cards.splice(cardIdx, 1);\n props.value = nv;\n trigger('change');\n});\nelement.addEventListener('click', (e) => {\n const btn = e.target.closest('.priority-cycle');\n if (!btn) return;\n e.stopPropagation();\n const colIdx = parseInt(btn.dataset.colIdx);\n const cardIdx = parseInt(btn.dataset.cardIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n const card = nv.columns[colIdx].cards[cardIdx];\n const cycle = { low: 'medium', medium: 'high', high: 'low' };\n card.priority = cycle[card.priority] || 'low';\n props.value = nv;\n trigger('change');\n});\nelement.addEventListener('click', (e) => {\n const btn = e.target.closest('.collapse-btn');\n if (!btn) return;\n const colIdx = parseInt(btn.dataset.colIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].collapsed = !nv.columns[colIdx].collapsed;\n props.value = nv;\n trigger('change');\n});\nelement.addEventListener('dblclick', (e) => {\n const textEl = e.target.closest('.card-text');\n if (!textEl) return;\n textEl.contentEditable = 'true';\n textEl.classList.add('editing');\n textEl.focus();\n const range = document.createRange();\n range.selectNodeContents(textEl);\n const sel = window.getSelection();\n sel.removeAllRanges();\n sel.addRange(range);\n});\nfunction commitEdit(textEl) {\n textEl.contentEditable = 'false';\n textEl.classList.remove('editing');\n const colIdx = parseInt(textEl.dataset.colIdx);\n const cardIdx = parseInt(textEl.dataset.cardIdx);\n const newText = textEl.innerText.trim();\n if (!newText) return;\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].cards[cardIdx].text = newText;\n props.value = nv;\n trigger('change');\n}\nelement.addEventListener('blur', (e) => {\n if (e.target.classList && e.target.classList.contains('editing')) {\n commitEdit(e.target);\n }\n}, true);\nelement.addEventListener('keydown', (e) => {\n if (e.key === 'Enter' && e.target.classList.contains('editing')) {\n e.preventDefault();\n e.target.blur();\n return;\n }\n if (e.key === 'Enter' && e.target.classList.contains('add-card-input')) {\n const text = e.target.value.trim();\n if (!text) return;\n const colIdx = parseInt(e.target.dataset.colIdx);\n const nv = JSON.parse(JSON.stringify(props.value));\n nv.columns[colIdx].cards.push({\n id: String(Date.now()),\n text: text,\n priority: 'medium',\n tags: []\n });\n props.value = nv;\n e.target.value = '';\n trigger('change');\n }\n});\nelement.addEventListener('input', (e) => {\n if (!e.target.classList.contains('search-input')) return;\n const q = e.target.value.toLowerCase().trim();\n element.querySelectorAll('.kanban-card').forEach(card => {\n const text = card.querySelector('.card-text').innerText.toLowerCase();\n const tags = Array.from(card.querySelectorAll('.kb-tag')).map(t => t.innerText.toLowerCase()).join(' ');\n const match = !q || text.includes(q) || tags.includes(q);\n card.classList.toggle('search-hidden', !match);\n card.classList.toggle('search-highlight', !!q && match);\n });\n});",
206
+ "default_props": {
207
+ "board_title": "My Board",
208
+ "value": {
209
+ "columns": [
210
+ {
211
+ "id": "todo",
212
+ "title": "\ud83d\udccb To Do",
213
+ "color": "#6366f1",
214
+ "cards": [
215
+ {
216
+ "id": "1",
217
+ "text": "Research gr.HTML component",
218
+ "priority": "high",
219
+ "tags": [
220
+ "gradio"
221
+ ]
222
+ },
223
+ {
224
+ "id": "2",
225
+ "text": "Design the UI layout",
226
+ "priority": "medium",
227
+ "tags": [
228
+ "design"
229
+ ]
230
+ },
231
+ {
232
+ "id": "3",
233
+ "text": "Write documentation",
234
+ "priority": "low",
235
+ "tags": [
236
+ "docs"
237
+ ]
238
+ }
239
+ ]
240
+ },
241
+ {
242
+ "id": "progress",
243
+ "title": "\ud83d\udd28 In Progress",
244
+ "color": "#f59e0b",
245
+ "cards": [
246
+ {
247
+ "id": "4",
248
+ "text": "Build Kanban prototype",
249
+ "priority": "high",
250
+ "tags": [
251
+ "dev"
252
+ ]
253
+ }
254
+ ]
255
+ },
256
+ {
257
+ "id": "review",
258
+ "title": "\ud83d\udc40 Review",
259
+ "color": "#8b5cf6",
260
+ "cards": []
261
+ },
262
+ {
263
+ "id": "done",
264
+ "title": "\u2705 Done",
265
+ "color": "#10b981",
266
+ "cards": [
267
+ {
268
+ "id": "5",
269
+ "text": "Set up Gradio project",
270
+ "priority": "medium",
271
+ "tags": [
272
+ "setup"
273
+ ]
274
+ }
275
+ ]
276
+ }
277
+ ]
278
+ }
279
+ },
280
+ "python_code": "class KanbanBoard(gr.HTML):\n \"\"\"A drag-and-drop Kanban board component.\"\"\"\n\n def __init__(self, value=None, board_title=\"My Board\", **kwargs):\n if value is None:\n value = {\n \"columns\": [\n {\n \"id\": \"todo\", \"title\": \"To Do\", \"color\": \"#6366f1\",\n \"cards\": [\n {\"id\": \"1\", \"text\": \"Research gr.HTML\", \"priority\": \"high\", \"tags\": [\"gradio\"]},\n {\"id\": \"2\", \"text\": \"Design UI layout\", \"priority\": \"medium\", \"tags\": [\"design\"]},\n ],\n },\n {\n \"id\": \"progress\", \"title\": \"In Progress\", \"color\": \"#f59e0b\",\n \"cards\": [\n {\"id\": \"3\", \"text\": \"Build prototype\", \"priority\": \"high\", \"tags\": [\"dev\"]},\n ],\n },\n {\"id\": \"review\", \"title\": \"Review\", \"color\": \"#8b5cf6\", \"cards\": []},\n {\n \"id\": \"done\", \"title\": \"Done\", \"color\": \"#10b981\",\n \"cards\": [\n {\"id\": \"4\", \"text\": \"Set up project\", \"priority\": \"medium\", \"tags\": [\"setup\"]},\n ],\n },\n ],\n }\n super().__init__(\n value=value, board_title=board_title,\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\": \"object\", \"description\": \"Kanban board state\"}"
281
+ }
282
+ ]