prathje commited on
Commit
22074d9
·
verified ·
1 Parent(s): 2cfdea5

Upload folder using huggingface_hub

Browse files
.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .eggs/
2
+ dist/
3
+ *.pyc
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+ __tmp/*
8
+ *.pyi
9
+ .mypycache
10
+ .ruff_cache
11
+ node_modules
12
+ backend/**/templates/
README.md CHANGED
@@ -1,12 +1,353 @@
1
  ---
2
- title: Gradio Motioncanvasplayer
3
- emoji: 🌍
4
- colorFrom: indigo
5
- colorTo: green
 
6
  sdk: gradio
7
- sdk_version: 5.33.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ tags: [gradio-custom-component, HTML, Motion Canvas, Animation, Player, custom-component-track]
3
+ title: gradio_motioncanvasplayer
4
+ short_description: Motion Canvas Player to render Motion Canvas projects
5
+ colorFrom: blue
6
+ colorTo: yellow
7
  sdk: gradio
 
 
8
  pinned: false
9
+ app_file: space.py
10
  ---
11
 
12
+ # `gradio_motioncanvasplayer`
13
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
14
+
15
+ Motion Canvas Player to render Motion Canvas projects
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install gradio_motioncanvasplayer
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+
27
+ import gradio as gr
28
+ from pathlib import Path
29
+ import uvicorn
30
+
31
+ from gradio_motioncanvasplayer import MotionCanvasPlayer
32
+
33
+ project_path = "/gradio_api/file=demo/public/project-3.17.2.js"
34
+
35
+
36
+ gr.set_static_paths(paths=[Path.cwd().absolute()/"demo/public"])
37
+
38
+ demo = gr.Interface(
39
+ lambda x:x,
40
+ None, # interactive version of your component, not relevant for this demo
41
+ MotionCanvasPlayer(project_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}"), # static version of your component
42
+ clear_btn=None
43
+
44
+ )
45
+
46
+ if __name__ == '__main__':
47
+ demo.launch(server_name="0.0.0.0", server_port=7860)
48
+ ```
49
+
50
+ ## `MotionCanvasPlayer`
51
+
52
+ ### Initialization
53
+
54
+ <table>
55
+ <thead>
56
+ <tr>
57
+ <th align="left">name</th>
58
+ <th align="left" style="width: 25%;">type</th>
59
+ <th align="left">default</th>
60
+ <th align="left">description</th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <tr>
65
+ <td align="left"><code>value</code></td>
66
+ <td align="left" style="width: 25%;">
67
+
68
+ ```python
69
+ str | Callable | None
70
+ ```
71
+
72
+ </td>
73
+ <td align="left"><code>None</code></td>
74
+ <td align="left">The MotionCanvasPlayer content to display. Only static MotionCanvasPlayer is rendered (e.g. no JavaScript. To render JavaScript, use the `js` or `head` parameters in the `Blocks` constructor). If a function is provided, the function will be called each time the app loads to set the initial value of this component.</td>
75
+ </tr>
76
+
77
+ <tr>
78
+ <td align="left"><code>label</code></td>
79
+ <td align="left" style="width: 25%;">
80
+
81
+ ```python
82
+ str | I18nData | None
83
+ ```
84
+
85
+ </td>
86
+ <td align="left"><code>None</code></td>
87
+ <td align="left">The label for this component. Is used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.</td>
88
+ </tr>
89
+
90
+ <tr>
91
+ <td align="left"><code>every</code></td>
92
+ <td align="left" style="width: 25%;">
93
+
94
+ ```python
95
+ Timer | float | None
96
+ ```
97
+
98
+ </td>
99
+ <td align="left"><code>None</code></td>
100
+ <td align="left">Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.</td>
101
+ </tr>
102
+
103
+ <tr>
104
+ <td align="left"><code>inputs</code></td>
105
+ <td align="left" style="width: 25%;">
106
+
107
+ ```python
108
+ Component | Sequence[Component] | set[Component] | None
109
+ ```
110
+
111
+ </td>
112
+ <td align="left"><code>None</code></td>
113
+ <td align="left">Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.</td>
114
+ </tr>
115
+
116
+ <tr>
117
+ <td align="left"><code>show_label</code></td>
118
+ <td align="left" style="width: 25%;">
119
+
120
+ ```python
121
+ bool
122
+ ```
123
+
124
+ </td>
125
+ <td align="left"><code>False</code></td>
126
+ <td align="left">If True, the label will be displayed. If False, the label will be hidden.</td>
127
+ </tr>
128
+
129
+ <tr>
130
+ <td align="left"><code>visible</code></td>
131
+ <td align="left" style="width: 25%;">
132
+
133
+ ```python
134
+ bool
135
+ ```
136
+
137
+ </td>
138
+ <td align="left"><code>True</code></td>
139
+ <td align="left">If False, component will be hidden.</td>
140
+ </tr>
141
+
142
+ <tr>
143
+ <td align="left"><code>elem_id</code></td>
144
+ <td align="left" style="width: 25%;">
145
+
146
+ ```python
147
+ str | None
148
+ ```
149
+
150
+ </td>
151
+ <td align="left"><code>None</code></td>
152
+ <td align="left">An optional string that is assigned as the id of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.</td>
153
+ </tr>
154
+
155
+ <tr>
156
+ <td align="left"><code>elem_classes</code></td>
157
+ <td align="left" style="width: 25%;">
158
+
159
+ ```python
160
+ list[str] | str | None
161
+ ```
162
+
163
+ </td>
164
+ <td align="left"><code>None</code></td>
165
+ <td align="left">An optional list of strings that are assigned as the classes of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.</td>
166
+ </tr>
167
+
168
+ <tr>
169
+ <td align="left"><code>render</code></td>
170
+ <td align="left" style="width: 25%;">
171
+
172
+ ```python
173
+ bool
174
+ ```
175
+
176
+ </td>
177
+ <td align="left"><code>True</code></td>
178
+ <td align="left">If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
179
+ </tr>
180
+
181
+ <tr>
182
+ <td align="left"><code>key</code></td>
183
+ <td align="left" style="width: 25%;">
184
+
185
+ ```python
186
+ int | str | tuple[int | str, ...] | None
187
+ ```
188
+
189
+ </td>
190
+ <td align="left"><code>None</code></td>
191
+ <td align="left">in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.</td>
192
+ </tr>
193
+
194
+ <tr>
195
+ <td align="left"><code>preserved_by_key</code></td>
196
+ <td align="left" style="width: 25%;">
197
+
198
+ ```python
199
+ list[str] | str | None
200
+ ```
201
+
202
+ </td>
203
+ <td align="left"><code>"value"</code></td>
204
+ <td align="left">A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.</td>
205
+ </tr>
206
+
207
+ <tr>
208
+ <td align="left"><code>min_height</code></td>
209
+ <td align="left" style="width: 25%;">
210
+
211
+ ```python
212
+ int | None
213
+ ```
214
+
215
+ </td>
216
+ <td align="left"><code>None</code></td>
217
+ <td align="left">The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If MotionCanvasPlayer content exceeds the height, the component will expand to fit the content.</td>
218
+ </tr>
219
+
220
+ <tr>
221
+ <td align="left"><code>max_height</code></td>
222
+ <td align="left" style="width: 25%;">
223
+
224
+ ```python
225
+ int | None
226
+ ```
227
+
228
+ </td>
229
+ <td align="left"><code>None</code></td>
230
+ <td align="left">The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the component will scroll.</td>
231
+ </tr>
232
+
233
+ <tr>
234
+ <td align="left"><code>container</code></td>
235
+ <td align="left" style="width: 25%;">
236
+
237
+ ```python
238
+ bool
239
+ ```
240
+
241
+ </td>
242
+ <td align="left"><code>False</code></td>
243
+ <td align="left">If True, the MotionCanvasPlayer component will be displayed in a container. Default is False.</td>
244
+ </tr>
245
+
246
+ <tr>
247
+ <td align="left"><code>padding</code></td>
248
+ <td align="left" style="width: 25%;">
249
+
250
+ ```python
251
+ bool
252
+ ```
253
+
254
+ </td>
255
+ <td align="left"><code>True</code></td>
256
+ <td align="left">If True, the MotionCanvasPlayer component will have a certain padding (set by the `--block-padding` CSS variable) in all directions. Default is True.</td>
257
+ </tr>
258
+
259
+ <tr>
260
+ <td align="left"><code>auto</code></td>
261
+ <td align="left" style="width: 25%;">
262
+
263
+ ```python
264
+ bool | None
265
+ ```
266
+
267
+ </td>
268
+ <td align="left"><code>False</code></td>
269
+ <td align="left">If True, the MotionCanvasPlayer component will automatically play the animation. Default is False.</td>
270
+ </tr>
271
+
272
+ <tr>
273
+ <td align="left"><code>quality</code></td>
274
+ <td align="left" style="width: 25%;">
275
+
276
+ ```python
277
+ number | None
278
+ ```
279
+
280
+ </td>
281
+ <td align="left"><code>None</code></td>
282
+ <td align="left">The quality of the MotionCanvasPlayer component. Default is None which uses the project's default settings.</td>
283
+ </tr>
284
+
285
+ <tr>
286
+ <td align="left"><code>width</code></td>
287
+ <td align="left" style="width: 25%;">
288
+
289
+ ```python
290
+ int | None
291
+ ```
292
+
293
+ </td>
294
+ <td align="left"><code>None</code></td>
295
+ <td align="left">The width of the MotionCanvasPlayer component. Default is None which uses the project's default settings.</td>
296
+ </tr>
297
+
298
+ <tr>
299
+ <td align="left"><code>height</code></td>
300
+ <td align="left" style="width: 25%;">
301
+
302
+ ```python
303
+ int | None
304
+ ```
305
+
306
+ </td>
307
+ <td align="left"><code>None</code></td>
308
+ <td align="left">The height of the MotionCanvasPlayer component. Default is None which uses the project's default settings.</td>
309
+ </tr>
310
+
311
+ <tr>
312
+ <td align="left"><code>variables</code></td>
313
+ <td align="left" style="width: 25%;">
314
+
315
+ ```python
316
+ str | None
317
+ ```
318
+
319
+ </td>
320
+ <td align="left"><code>None</code></td>
321
+ <td align="left">The variables of the MotionCanvasPlayer component as a JSON string. Default is None.</td>
322
+ </tr>
323
+ </tbody></table>
324
+
325
+
326
+ ### Events
327
+
328
+ | name | description |
329
+ |:-----|:------------|
330
+ | `change` | Triggered when the value of the MotionCanvasPlayer changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. |
331
+ | `click` | Triggered when the MotionCanvasPlayer is clicked. |
332
+
333
+
334
+
335
+ ### User function
336
+
337
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
338
+
339
+ - When used as an Input, the component only impacts the input signature of the user function.
340
+ - When used as an output, the component only impacts the return signature of the user function.
341
+
342
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
343
+
344
+ - **As output:** Is passed, (Rarely used) passes the MotionCanvasPlayer as a `str`.
345
+ - **As input:** Should return, expects a `str` consisting of valid MotionCanvasPlayer.
346
+
347
+ ```python
348
+ def predict(
349
+ value: str | None
350
+ ) -> str | None:
351
+ return value
352
+ ```
353
+
__init__.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from pathlib import Path
4
+ import uvicorn
5
+
6
+ from gradio_motioncanvasplayer import MotionCanvasPlayer
7
+
8
+ project_path = "/gradio_api/file=demo/public/project-3.17.2.js"
9
+
10
+
11
+ gr.set_static_paths(paths=[Path.cwd().absolute()/"demo/public"])
12
+
13
+ demo = gr.Interface(
14
+ lambda x:x,
15
+ None, # interactive version of your component, not relevant for this demo
16
+ MotionCanvasPlayer(project_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}"), # static version of your component
17
+ clear_btn=None
18
+
19
+ )
20
+
21
+ if __name__ == '__main__':
22
+ demo.launch(server_name="0.0.0.0", server_port=7860)
css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
public/project-3.17.2.js ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio_motioncanvasplayer
space.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'MotionCanvasPlayer': {'description': 'Creates a component to display arbitrary MotionCanvasPlayer output. As this component does not accept user input, it is rarely used as an input component.\n', 'members': {'__init__': {'value': {'type': 'str | Callable | None', 'default': 'None', 'description': 'The MotionCanvasPlayer content to display. Only static MotionCanvasPlayer is rendered (e.g. no JavaScript. To render JavaScript, use the `js` or `head` parameters in the `Blocks` constructor). If a function is provided, the function will be called each time the app loads to set the initial value of this component.'}, 'label': {'type': 'str | I18nData | None', 'default': 'None', 'description': 'The label for this component. Is used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.'}, 'every': {'type': 'Timer | float | None', 'default': 'None', 'description': 'Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.'}, 'inputs': {'type': 'Component | Sequence[Component] | set[Component] | None', 'default': 'None', 'description': 'Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.'}, 'show_label': {'type': 'bool', 'default': 'False', 'description': 'If True, the label will be displayed. If False, the label will be hidden.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': 'An optional string that is assigned as the id of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.'}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': 'An optional list of strings that are assigned as the classes of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.'}, 'render': {'type': 'bool', 'default': 'True', 'description': 'If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.'}, 'key': {'type': 'int | str | tuple[int | str, ...] | None', 'default': 'None', 'description': "in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render."}, 'preserved_by_key': {'type': 'list[str] | str | None', 'default': '"value"', 'description': "A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor."}, 'min_height': {'type': 'int | None', 'default': 'None', 'description': 'The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If MotionCanvasPlayer content exceeds the height, the component will expand to fit the content.'}, 'max_height': {'type': 'int | None', 'default': 'None', 'description': 'The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the component will scroll.'}, 'container': {'type': 'bool', 'default': 'False', 'description': 'If True, the MotionCanvasPlayer component will be displayed in a container. Default is False.'}, 'padding': {'type': 'bool', 'default': 'True', 'description': 'If True, the MotionCanvasPlayer component will have a certain padding (set by the `--block-padding` CSS variable) in all directions. Default is True.'}, 'auto': {'type': 'bool | None', 'default': 'False', 'description': 'If True, the MotionCanvasPlayer component will automatically play the animation. Default is False.'}, 'quality': {'type': 'number | None', 'default': 'None', 'description': "The quality of the MotionCanvasPlayer component. Default is None which uses the project's default settings."}, 'width': {'type': 'int | None', 'default': 'None', 'description': "The width of the MotionCanvasPlayer component. Default is None which uses the project's default settings."}, 'height': {'type': 'int | None', 'default': 'None', 'description': "The height of the MotionCanvasPlayer component. Default is None which uses the project's default settings."}, 'variables': {'type': 'str | None', 'default': 'None', 'description': 'The variables of the MotionCanvasPlayer component as a JSON string. Default is None.'}}, 'postprocess': {'value': {'type': 'str | None', 'description': 'Expects a `str` consisting of valid MotionCanvasPlayer.'}}, 'preprocess': {'return': {'type': 'str | None', 'description': '(Rarely used) passes the MotionCanvasPlayer as a `str`.'}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the MotionCanvasPlayer changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'click': {'type': None, 'default': None, 'description': 'Triggered when the MotionCanvasPlayer is clicked.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'MotionCanvasPlayer': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_motioncanvasplayer`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
25
+ </div>
26
+
27
+ Motion Canvas Player to render Motion Canvas projects
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_motioncanvasplayer
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+
42
+ import gradio as gr
43
+ from pathlib import Path
44
+ import uvicorn
45
+
46
+ from gradio_motioncanvasplayer import MotionCanvasPlayer
47
+
48
+ project_path = "/gradio_api/file=demo/public/project-3.17.2.js"
49
+
50
+
51
+ gr.set_static_paths(paths=[Path.cwd().absolute()/"demo/public"])
52
+
53
+ demo = gr.Interface(
54
+ lambda x:x,
55
+ None, # interactive version of your component, not relevant for this demo
56
+ MotionCanvasPlayer(project_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}"), # static version of your component
57
+ clear_btn=None
58
+
59
+ )
60
+
61
+ if __name__ == '__main__':
62
+ demo.launch(server_name="0.0.0.0", server_port=7860)
63
+ ```
64
+ """, elem_classes=["md-custom"], header_links=True)
65
+
66
+
67
+ gr.Markdown("""
68
+ ## `MotionCanvasPlayer`
69
+
70
+ ### Initialization
71
+ """, elem_classes=["md-custom"], header_links=True)
72
+
73
+ gr.ParamViewer(value=_docs["MotionCanvasPlayer"]["members"]["__init__"], linkify=[])
74
+
75
+
76
+ gr.Markdown("### Events")
77
+ gr.ParamViewer(value=_docs["MotionCanvasPlayer"]["events"], linkify=['Event'])
78
+
79
+
80
+
81
+
82
+ gr.Markdown("""
83
+
84
+ ### User function
85
+
86
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
87
+
88
+ - When used as an Input, the component only impacts the input signature of the user function.
89
+ - When used as an output, the component only impacts the return signature of the user function.
90
+
91
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
92
+
93
+ - **As input:** Is passed, (Rarely used) passes the MotionCanvasPlayer as a `str`.
94
+ - **As output:** Should return, expects a `str` consisting of valid MotionCanvasPlayer.
95
+
96
+ ```python
97
+ def predict(
98
+ value: str | None
99
+ ) -> str | None:
100
+ return value
101
+ ```
102
+ """, elem_classes=["md-custom", "MotionCanvasPlayer-user-fn"], header_links=True)
103
+
104
+
105
+
106
+
107
+ demo.load(None, js=r"""function() {
108
+ const refs = {};
109
+ const user_fn_refs = {
110
+ MotionCanvasPlayer: [], };
111
+ requestAnimationFrame(() => {
112
+
113
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
114
+ if (refs.length > 0) {
115
+ const el = document.querySelector(`.${key}-user-fn`);
116
+ if (!el) return;
117
+ refs.forEach(ref => {
118
+ el.innerHTML = el.innerHTML.replace(
119
+ new RegExp("\\b"+ref+"\\b", "g"),
120
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
121
+ );
122
+ })
123
+ }
124
+ })
125
+
126
+ Object.entries(refs).forEach(([key, refs]) => {
127
+ if (refs.length > 0) {
128
+ const el = document.querySelector(`.${key}`);
129
+ if (!el) return;
130
+ refs.forEach(ref => {
131
+ el.innerHTML = el.innerHTML.replace(
132
+ new RegExp("\\b"+ref+"\\b", "g"),
133
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
134
+ );
135
+ })
136
+ }
137
+ })
138
+ })
139
+ }
140
+
141
+ """)
142
+
143
+ demo.launch()
src/.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .eggs/
2
+ dist/
3
+ *.pyc
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+ __tmp/*
8
+ *.pyi
9
+ .mypycache
10
+ .ruff_cache
11
+ node_modules
12
+ backend/**/templates/
src/README.md ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags: [gradio-custom-component, HTML, Motion Canvas, Animation, Player, custom-component-track]
3
+ title: gradio_motioncanvasplayer
4
+ short_description: Motion Canvas Player to render Motion Canvas projects
5
+ colorFrom: blue
6
+ colorTo: yellow
7
+ sdk: gradio
8
+ pinned: false
9
+ app_file: space.py
10
+ ---
11
+
12
+ # `gradio_motioncanvasplayer`
13
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
14
+
15
+ Motion Canvas Player to render Motion Canvas projects
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install gradio_motioncanvasplayer
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+
27
+ import gradio as gr
28
+ from pathlib import Path
29
+ import uvicorn
30
+
31
+ from gradio_motioncanvasplayer import MotionCanvasPlayer
32
+
33
+ project_path = "/gradio_api/file=demo/public/project-3.17.2.js"
34
+
35
+
36
+ gr.set_static_paths(paths=[Path.cwd().absolute()/"demo/public"])
37
+
38
+ demo = gr.Interface(
39
+ lambda x:x,
40
+ None, # interactive version of your component, not relevant for this demo
41
+ MotionCanvasPlayer(project_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}"), # static version of your component
42
+ clear_btn=None
43
+
44
+ )
45
+
46
+ if __name__ == '__main__':
47
+ demo.launch(server_name="0.0.0.0", server_port=7860)
48
+ ```
49
+
50
+ ## `MotionCanvasPlayer`
51
+
52
+ ### Initialization
53
+
54
+ <table>
55
+ <thead>
56
+ <tr>
57
+ <th align="left">name</th>
58
+ <th align="left" style="width: 25%;">type</th>
59
+ <th align="left">default</th>
60
+ <th align="left">description</th>
61
+ </tr>
62
+ </thead>
63
+ <tbody>
64
+ <tr>
65
+ <td align="left"><code>value</code></td>
66
+ <td align="left" style="width: 25%;">
67
+
68
+ ```python
69
+ str | Callable | None
70
+ ```
71
+
72
+ </td>
73
+ <td align="left"><code>None</code></td>
74
+ <td align="left">The MotionCanvasPlayer content to display. Only static MotionCanvasPlayer is rendered (e.g. no JavaScript. To render JavaScript, use the `js` or `head` parameters in the `Blocks` constructor). If a function is provided, the function will be called each time the app loads to set the initial value of this component.</td>
75
+ </tr>
76
+
77
+ <tr>
78
+ <td align="left"><code>label</code></td>
79
+ <td align="left" style="width: 25%;">
80
+
81
+ ```python
82
+ str | I18nData | None
83
+ ```
84
+
85
+ </td>
86
+ <td align="left"><code>None</code></td>
87
+ <td align="left">The label for this component. Is used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.</td>
88
+ </tr>
89
+
90
+ <tr>
91
+ <td align="left"><code>every</code></td>
92
+ <td align="left" style="width: 25%;">
93
+
94
+ ```python
95
+ Timer | float | None
96
+ ```
97
+
98
+ </td>
99
+ <td align="left"><code>None</code></td>
100
+ <td align="left">Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.</td>
101
+ </tr>
102
+
103
+ <tr>
104
+ <td align="left"><code>inputs</code></td>
105
+ <td align="left" style="width: 25%;">
106
+
107
+ ```python
108
+ Component | Sequence[Component] | set[Component] | None
109
+ ```
110
+
111
+ </td>
112
+ <td align="left"><code>None</code></td>
113
+ <td align="left">Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.</td>
114
+ </tr>
115
+
116
+ <tr>
117
+ <td align="left"><code>show_label</code></td>
118
+ <td align="left" style="width: 25%;">
119
+
120
+ ```python
121
+ bool
122
+ ```
123
+
124
+ </td>
125
+ <td align="left"><code>False</code></td>
126
+ <td align="left">If True, the label will be displayed. If False, the label will be hidden.</td>
127
+ </tr>
128
+
129
+ <tr>
130
+ <td align="left"><code>visible</code></td>
131
+ <td align="left" style="width: 25%;">
132
+
133
+ ```python
134
+ bool
135
+ ```
136
+
137
+ </td>
138
+ <td align="left"><code>True</code></td>
139
+ <td align="left">If False, component will be hidden.</td>
140
+ </tr>
141
+
142
+ <tr>
143
+ <td align="left"><code>elem_id</code></td>
144
+ <td align="left" style="width: 25%;">
145
+
146
+ ```python
147
+ str | None
148
+ ```
149
+
150
+ </td>
151
+ <td align="left"><code>None</code></td>
152
+ <td align="left">An optional string that is assigned as the id of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.</td>
153
+ </tr>
154
+
155
+ <tr>
156
+ <td align="left"><code>elem_classes</code></td>
157
+ <td align="left" style="width: 25%;">
158
+
159
+ ```python
160
+ list[str] | str | None
161
+ ```
162
+
163
+ </td>
164
+ <td align="left"><code>None</code></td>
165
+ <td align="left">An optional list of strings that are assigned as the classes of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.</td>
166
+ </tr>
167
+
168
+ <tr>
169
+ <td align="left"><code>render</code></td>
170
+ <td align="left" style="width: 25%;">
171
+
172
+ ```python
173
+ bool
174
+ ```
175
+
176
+ </td>
177
+ <td align="left"><code>True</code></td>
178
+ <td align="left">If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
179
+ </tr>
180
+
181
+ <tr>
182
+ <td align="left"><code>key</code></td>
183
+ <td align="left" style="width: 25%;">
184
+
185
+ ```python
186
+ int | str | tuple[int | str, ...] | None
187
+ ```
188
+
189
+ </td>
190
+ <td align="left"><code>None</code></td>
191
+ <td align="left">in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.</td>
192
+ </tr>
193
+
194
+ <tr>
195
+ <td align="left"><code>preserved_by_key</code></td>
196
+ <td align="left" style="width: 25%;">
197
+
198
+ ```python
199
+ list[str] | str | None
200
+ ```
201
+
202
+ </td>
203
+ <td align="left"><code>"value"</code></td>
204
+ <td align="left">A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.</td>
205
+ </tr>
206
+
207
+ <tr>
208
+ <td align="left"><code>min_height</code></td>
209
+ <td align="left" style="width: 25%;">
210
+
211
+ ```python
212
+ int | None
213
+ ```
214
+
215
+ </td>
216
+ <td align="left"><code>None</code></td>
217
+ <td align="left">The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If MotionCanvasPlayer content exceeds the height, the component will expand to fit the content.</td>
218
+ </tr>
219
+
220
+ <tr>
221
+ <td align="left"><code>max_height</code></td>
222
+ <td align="left" style="width: 25%;">
223
+
224
+ ```python
225
+ int | None
226
+ ```
227
+
228
+ </td>
229
+ <td align="left"><code>None</code></td>
230
+ <td align="left">The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the component will scroll.</td>
231
+ </tr>
232
+
233
+ <tr>
234
+ <td align="left"><code>container</code></td>
235
+ <td align="left" style="width: 25%;">
236
+
237
+ ```python
238
+ bool
239
+ ```
240
+
241
+ </td>
242
+ <td align="left"><code>False</code></td>
243
+ <td align="left">If True, the MotionCanvasPlayer component will be displayed in a container. Default is False.</td>
244
+ </tr>
245
+
246
+ <tr>
247
+ <td align="left"><code>padding</code></td>
248
+ <td align="left" style="width: 25%;">
249
+
250
+ ```python
251
+ bool
252
+ ```
253
+
254
+ </td>
255
+ <td align="left"><code>True</code></td>
256
+ <td align="left">If True, the MotionCanvasPlayer component will have a certain padding (set by the `--block-padding` CSS variable) in all directions. Default is True.</td>
257
+ </tr>
258
+
259
+ <tr>
260
+ <td align="left"><code>auto</code></td>
261
+ <td align="left" style="width: 25%;">
262
+
263
+ ```python
264
+ bool | None
265
+ ```
266
+
267
+ </td>
268
+ <td align="left"><code>False</code></td>
269
+ <td align="left">If True, the MotionCanvasPlayer component will automatically play the animation. Default is False.</td>
270
+ </tr>
271
+
272
+ <tr>
273
+ <td align="left"><code>quality</code></td>
274
+ <td align="left" style="width: 25%;">
275
+
276
+ ```python
277
+ number | None
278
+ ```
279
+
280
+ </td>
281
+ <td align="left"><code>None</code></td>
282
+ <td align="left">The quality of the MotionCanvasPlayer component. Default is None which uses the project's default settings.</td>
283
+ </tr>
284
+
285
+ <tr>
286
+ <td align="left"><code>width</code></td>
287
+ <td align="left" style="width: 25%;">
288
+
289
+ ```python
290
+ int | None
291
+ ```
292
+
293
+ </td>
294
+ <td align="left"><code>None</code></td>
295
+ <td align="left">The width of the MotionCanvasPlayer component. Default is None which uses the project's default settings.</td>
296
+ </tr>
297
+
298
+ <tr>
299
+ <td align="left"><code>height</code></td>
300
+ <td align="left" style="width: 25%;">
301
+
302
+ ```python
303
+ int | None
304
+ ```
305
+
306
+ </td>
307
+ <td align="left"><code>None</code></td>
308
+ <td align="left">The height of the MotionCanvasPlayer component. Default is None which uses the project's default settings.</td>
309
+ </tr>
310
+
311
+ <tr>
312
+ <td align="left"><code>variables</code></td>
313
+ <td align="left" style="width: 25%;">
314
+
315
+ ```python
316
+ str | None
317
+ ```
318
+
319
+ </td>
320
+ <td align="left"><code>None</code></td>
321
+ <td align="left">The variables of the MotionCanvasPlayer component as a JSON string. Default is None.</td>
322
+ </tr>
323
+ </tbody></table>
324
+
325
+
326
+ ### Events
327
+
328
+ | name | description |
329
+ |:-----|:------------|
330
+ | `change` | Triggered when the value of the MotionCanvasPlayer changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. |
331
+ | `click` | Triggered when the MotionCanvasPlayer is clicked. |
332
+
333
+
334
+
335
+ ### User function
336
+
337
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
338
+
339
+ - When used as an Input, the component only impacts the input signature of the user function.
340
+ - When used as an output, the component only impacts the return signature of the user function.
341
+
342
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
343
+
344
+ - **As output:** Is passed, (Rarely used) passes the MotionCanvasPlayer as a `str`.
345
+ - **As input:** Should return, expects a `str` consisting of valid MotionCanvasPlayer.
346
+
347
+ ```python
348
+ def predict(
349
+ value: str | None
350
+ ) -> str | None:
351
+ return value
352
+ ```
353
+
src/backend/gradio_motioncanvasplayer/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ from .motioncanvasplayer import MotionCanvasPlayer
3
+
4
+ __all__ = ['MotionCanvasPlayer']
src/backend/gradio_motioncanvasplayer/motioncanvasplayer.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """gr.HTML() component."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Callable, Sequence
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ from gradio_client.documentation import document
9
+
10
+ from gradio.components.base import Component
11
+ from gradio.events import Events
12
+ from gradio.i18n import I18nData
13
+
14
+ if TYPE_CHECKING:
15
+ from gradio.components import Timer
16
+
17
+
18
+ class MotionCanvasPlayer(Component):
19
+ """
20
+ Creates a component to display arbitrary MotionCanvasPlayer output. As this component does not accept user input, it is rarely used as an input component.
21
+
22
+ Demos: blocks_scroll
23
+ Guides: key-features
24
+ """
25
+
26
+ EVENTS = [Events.change, Events.click]
27
+
28
+ def __init__(
29
+ self,
30
+ value: str | Callable | None = None,
31
+ *,
32
+ label: str | I18nData | None = None,
33
+ every: Timer | float | None = None,
34
+ inputs: Component | Sequence[Component] | set[Component] | None = None,
35
+ show_label: bool = False,
36
+ visible: bool = True,
37
+ elem_id: str | None = None,
38
+ elem_classes: list[str] | str | None = None,
39
+ render: bool = True,
40
+ key: int | str | tuple[int | str, ...] | None = None,
41
+ preserved_by_key: list[str] | str | None = "value",
42
+ min_height: int | None = None,
43
+ max_height: int | None = None,
44
+ container: bool = False,
45
+ padding: bool = True,
46
+ auto: bool | None = False,
47
+ quality: number | None = None,
48
+ width: int | None = None,
49
+ height: int | None = None,
50
+ variables: str | None = None,
51
+ ):
52
+ """
53
+ Parameters:
54
+ value: The MotionCanvasPlayer content to display. Only static MotionCanvasPlayer is rendered (e.g. no JavaScript. To render JavaScript, use the `js` or `head` parameters in the `Blocks` constructor). If a function is provided, the function will be called each time the app loads to set the initial value of this component.
55
+ label: The label for this component. Is used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
56
+ every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
57
+ inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
58
+ show_label: If True, the label will be displayed. If False, the label will be hidden.
59
+ visible: If False, component will be hidden.
60
+ elem_id: An optional string that is assigned as the id of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.
61
+ elem_classes: An optional list of strings that are assigned as the classes of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.
62
+ render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
63
+ key: in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.
64
+ preserved_by_key: A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
65
+ min_height: The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If MotionCanvasPlayer content exceeds the height, the component will expand to fit the content.
66
+ max_height: The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the component will scroll.
67
+ container: If True, the MotionCanvasPlayer component will be displayed in a container. Default is False.
68
+ padding: If True, the MotionCanvasPlayer component will have a certain padding (set by the `--block-padding` CSS variable) in all directions. Default is True.
69
+ auto: If True, the MotionCanvasPlayer component will automatically play the animation. Default is False.
70
+ quality: The quality of the MotionCanvasPlayer component. Default is None which uses the project's default settings.
71
+ width: The width of the MotionCanvasPlayer component. Default is None which uses the project's default settings.
72
+ height: The height of the MotionCanvasPlayer component. Default is None which uses the project's default settings.
73
+ variables: The variables of the MotionCanvasPlayer component as a JSON string. Default is None.
74
+ """
75
+ self.min_height = min_height
76
+ self.max_height = max_height
77
+ self.padding = padding
78
+
79
+ self.auto = auto
80
+ self.quality = quality
81
+ self.width = width
82
+ self.height = height
83
+ self.variables = variables
84
+
85
+
86
+ super().__init__(
87
+ label=label,
88
+ every=every,
89
+ inputs=inputs,
90
+ show_label=show_label,
91
+ visible=visible,
92
+ elem_id=elem_id,
93
+ elem_classes=elem_classes,
94
+ render=render,
95
+ key=key,
96
+ preserved_by_key=preserved_by_key,
97
+ value=value,
98
+ container=container,
99
+ )
100
+
101
+ def example_payload(self) -> Any:
102
+ return "<p>Hello</p>"
103
+
104
+ def example_value(self) -> Any:
105
+ return "<p>Hello</p>"
106
+
107
+ def preprocess(self, payload: str | None) -> str | None:
108
+ """
109
+ Parameters:
110
+ payload: string corresponding to the MotionCanvasPlayer
111
+ Returns:
112
+ (Rarely used) passes the MotionCanvasPlayer as a `str`.
113
+ """
114
+ return payload
115
+
116
+ def postprocess(self, value: str | None) -> str | None:
117
+ """
118
+ Parameters:
119
+ value: Expects a `str` consisting of valid MotionCanvasPlayer.
120
+ Returns:
121
+ Returns the MotionCanvasPlayer string.
122
+ """
123
+ return value
124
+
125
+ def api_info(self) -> dict[str, Any]:
126
+ return {"type": "string"}
src/backend/gradio_motioncanvasplayer/templates/component/index.js ADDED
The diff for this file is too large to render. See raw diff
 
src/backend/gradio_motioncanvasplayer/templates/component/style.css ADDED
The diff for this file is too large to render. See raw diff
 
src/backend/gradio_motioncanvasplayer/templates/example/index.js ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const {
2
+ HtmlTagHydration: r,
3
+ SvelteComponent: d,
4
+ attr: u,
5
+ children: o,
6
+ claim_element: h,
7
+ claim_html_tag: m,
8
+ detach: c,
9
+ element: g,
10
+ init: v,
11
+ insert_hydration: y,
12
+ noop: _,
13
+ safe_not_equal: b,
14
+ toggle_class: i
15
+ } = window.__gradio__svelte__internal;
16
+ function q(n) {
17
+ let e, a;
18
+ return {
19
+ c() {
20
+ e = g("div"), a = new r(!1), this.h();
21
+ },
22
+ l(l) {
23
+ e = h(l, "DIV", { class: !0 });
24
+ var t = o(e);
25
+ a = m(t, !1), t.forEach(c), this.h();
26
+ },
27
+ h() {
28
+ a.a = null, u(e, "class", "prose svelte-180qqaf"), i(
29
+ e,
30
+ "table",
31
+ /*type*/
32
+ n[1] === "table"
33
+ ), i(
34
+ e,
35
+ "gallery",
36
+ /*type*/
37
+ n[1] === "gallery"
38
+ ), i(
39
+ e,
40
+ "selected",
41
+ /*selected*/
42
+ n[2]
43
+ );
44
+ },
45
+ m(l, t) {
46
+ y(l, e, t), a.m(
47
+ /*value*/
48
+ n[0],
49
+ e
50
+ );
51
+ },
52
+ p(l, [t]) {
53
+ t & /*value*/
54
+ 1 && a.p(
55
+ /*value*/
56
+ l[0]
57
+ ), t & /*type*/
58
+ 2 && i(
59
+ e,
60
+ "table",
61
+ /*type*/
62
+ l[1] === "table"
63
+ ), t & /*type*/
64
+ 2 && i(
65
+ e,
66
+ "gallery",
67
+ /*type*/
68
+ l[1] === "gallery"
69
+ ), t & /*selected*/
70
+ 4 && i(
71
+ e,
72
+ "selected",
73
+ /*selected*/
74
+ l[2]
75
+ );
76
+ },
77
+ i: _,
78
+ o: _,
79
+ d(l) {
80
+ l && c(e);
81
+ }
82
+ };
83
+ }
84
+ function w(n, e, a) {
85
+ let { value: l } = e, { type: t } = e, { selected: f = !1 } = e;
86
+ return n.$$set = (s) => {
87
+ "value" in s && a(0, l = s.value), "type" in s && a(1, t = s.type), "selected" in s && a(2, f = s.selected);
88
+ }, [l, t, f];
89
+ }
90
+ class E extends d {
91
+ constructor(e) {
92
+ super(), v(this, e, w, q, b, { value: 0, type: 1, selected: 2 });
93
+ }
94
+ }
95
+ export {
96
+ E as default
97
+ };
src/backend/gradio_motioncanvasplayer/templates/example/style.css ADDED
@@ -0,0 +1 @@
 
 
1
+ .gallery.svelte-180qqaf{padding:var(--size-2)}
src/demo/__init__.py ADDED
File without changes
src/demo/app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from pathlib import Path
4
+ import uvicorn
5
+
6
+ from gradio_motioncanvasplayer import MotionCanvasPlayer
7
+
8
+ project_path = "/gradio_api/file=demo/public/project-3.17.2.js"
9
+
10
+
11
+ gr.set_static_paths(paths=[Path.cwd().absolute()/"demo/public"])
12
+
13
+ demo = gr.Interface(
14
+ lambda x:x,
15
+ None, # interactive version of your component, not relevant for this demo
16
+ MotionCanvasPlayer(project_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}"), # static version of your component
17
+ clear_btn=None
18
+
19
+ )
20
+
21
+ if __name__ == '__main__':
22
+ demo.launch(server_name="0.0.0.0", server_port=7860)
src/demo/css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
src/demo/public/project-3.17.2.js ADDED
The diff for this file is too large to render. See raw diff
 
src/demo/requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio_motioncanvasplayer
src/demo/space.py ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'MotionCanvasPlayer': {'description': 'Creates a component to display arbitrary MotionCanvasPlayer output. As this component does not accept user input, it is rarely used as an input component.\n', 'members': {'__init__': {'value': {'type': 'str | Callable | None', 'default': 'None', 'description': 'The MotionCanvasPlayer content to display. Only static MotionCanvasPlayer is rendered (e.g. no JavaScript. To render JavaScript, use the `js` or `head` parameters in the `Blocks` constructor). If a function is provided, the function will be called each time the app loads to set the initial value of this component.'}, 'label': {'type': 'str | I18nData | None', 'default': 'None', 'description': 'The label for this component. Is used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.'}, 'every': {'type': 'Timer | float | None', 'default': 'None', 'description': 'Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.'}, 'inputs': {'type': 'Component | Sequence[Component] | set[Component] | None', 'default': 'None', 'description': 'Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.'}, 'show_label': {'type': 'bool', 'default': 'False', 'description': 'If True, the label will be displayed. If False, the label will be hidden.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': 'An optional string that is assigned as the id of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.'}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': 'An optional list of strings that are assigned as the classes of this component in the MotionCanvasPlayer DOM. Can be used for targeting CSS styles.'}, 'render': {'type': 'bool', 'default': 'True', 'description': 'If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.'}, 'key': {'type': 'int | str | tuple[int | str, ...] | None', 'default': 'None', 'description': "in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render."}, 'preserved_by_key': {'type': 'list[str] | str | None', 'default': '"value"', 'description': "A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor."}, 'min_height': {'type': 'int | None', 'default': 'None', 'description': 'The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If MotionCanvasPlayer content exceeds the height, the component will expand to fit the content.'}, 'max_height': {'type': 'int | None', 'default': 'None', 'description': 'The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If content exceeds the height, the component will scroll.'}, 'container': {'type': 'bool', 'default': 'False', 'description': 'If True, the MotionCanvasPlayer component will be displayed in a container. Default is False.'}, 'padding': {'type': 'bool', 'default': 'True', 'description': 'If True, the MotionCanvasPlayer component will have a certain padding (set by the `--block-padding` CSS variable) in all directions. Default is True.'}, 'auto': {'type': 'bool | None', 'default': 'False', 'description': 'If True, the MotionCanvasPlayer component will automatically play the animation. Default is False.'}, 'quality': {'type': 'number | None', 'default': 'None', 'description': "The quality of the MotionCanvasPlayer component. Default is None which uses the project's default settings."}, 'width': {'type': 'int | None', 'default': 'None', 'description': "The width of the MotionCanvasPlayer component. Default is None which uses the project's default settings."}, 'height': {'type': 'int | None', 'default': 'None', 'description': "The height of the MotionCanvasPlayer component. Default is None which uses the project's default settings."}, 'variables': {'type': 'str | None', 'default': 'None', 'description': 'The variables of the MotionCanvasPlayer component as a JSON string. Default is None.'}}, 'postprocess': {'value': {'type': 'str | None', 'description': 'Expects a `str` consisting of valid MotionCanvasPlayer.'}}, 'preprocess': {'return': {'type': 'str | None', 'description': '(Rarely used) passes the MotionCanvasPlayer as a `str`.'}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the MotionCanvasPlayer changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'click': {'type': None, 'default': None, 'description': 'Triggered when the MotionCanvasPlayer is clicked.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'MotionCanvasPlayer': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_motioncanvasplayer`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
25
+ </div>
26
+
27
+ Motion Canvas Player to render Motion Canvas projects
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_motioncanvasplayer
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+
42
+ import gradio as gr
43
+ from pathlib import Path
44
+ import uvicorn
45
+
46
+ from gradio_motioncanvasplayer import MotionCanvasPlayer
47
+
48
+ project_path = "/gradio_api/file=demo/public/project-3.17.2.js"
49
+
50
+
51
+ gr.set_static_paths(paths=[Path.cwd().absolute()/"demo/public"])
52
+
53
+ demo = gr.Interface(
54
+ lambda x:x,
55
+ None, # interactive version of your component, not relevant for this demo
56
+ MotionCanvasPlayer(project_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}"), # static version of your component
57
+ clear_btn=None
58
+
59
+ )
60
+
61
+ if __name__ == '__main__':
62
+ demo.launch(server_name="0.0.0.0", server_port=7860)
63
+ ```
64
+ """, elem_classes=["md-custom"], header_links=True)
65
+
66
+
67
+ gr.Markdown("""
68
+ ## `MotionCanvasPlayer`
69
+
70
+ ### Initialization
71
+ """, elem_classes=["md-custom"], header_links=True)
72
+
73
+ gr.ParamViewer(value=_docs["MotionCanvasPlayer"]["members"]["__init__"], linkify=[])
74
+
75
+
76
+ gr.Markdown("### Events")
77
+ gr.ParamViewer(value=_docs["MotionCanvasPlayer"]["events"], linkify=['Event'])
78
+
79
+
80
+
81
+
82
+ gr.Markdown("""
83
+
84
+ ### User function
85
+
86
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
87
+
88
+ - When used as an Input, the component only impacts the input signature of the user function.
89
+ - When used as an output, the component only impacts the return signature of the user function.
90
+
91
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
92
+
93
+ - **As input:** Is passed, (Rarely used) passes the MotionCanvasPlayer as a `str`.
94
+ - **As output:** Should return, expects a `str` consisting of valid MotionCanvasPlayer.
95
+
96
+ ```python
97
+ def predict(
98
+ value: str | None
99
+ ) -> str | None:
100
+ return value
101
+ ```
102
+ """, elem_classes=["md-custom", "MotionCanvasPlayer-user-fn"], header_links=True)
103
+
104
+
105
+
106
+
107
+ demo.load(None, js=r"""function() {
108
+ const refs = {};
109
+ const user_fn_refs = {
110
+ MotionCanvasPlayer: [], };
111
+ requestAnimationFrame(() => {
112
+
113
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
114
+ if (refs.length > 0) {
115
+ const el = document.querySelector(`.${key}-user-fn`);
116
+ if (!el) return;
117
+ refs.forEach(ref => {
118
+ el.innerHTML = el.innerHTML.replace(
119
+ new RegExp("\\b"+ref+"\\b", "g"),
120
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
121
+ );
122
+ })
123
+ }
124
+ })
125
+
126
+ Object.entries(refs).forEach(([key, refs]) => {
127
+ if (refs.length > 0) {
128
+ const el = document.querySelector(`.${key}`);
129
+ if (!el) return;
130
+ refs.forEach(ref => {
131
+ el.innerHTML = el.innerHTML.replace(
132
+ new RegExp("\\b"+ref+"\\b", "g"),
133
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
134
+ );
135
+ })
136
+ }
137
+ })
138
+ })
139
+ }
140
+
141
+ """)
142
+
143
+ demo.launch()
src/frontend/Example.svelte ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ export let value: string;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+ </script>
6
+
7
+ <div
8
+ class:table={type === "table"}
9
+ class:gallery={type === "gallery"}
10
+ class:selected
11
+ class="prose"
12
+ >
13
+ {@html value}
14
+ </div>
15
+
16
+ <style>
17
+ .gallery {
18
+ padding: var(--size-2);
19
+ }
20
+ </style>
src/frontend/Index.svelte ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import type { Gradio } from "@gradio/utils";
3
+ import MCPlayer from "./shared/MCPlayer.svelte";
4
+ import { StatusTracker } from "@gradio/statustracker";
5
+ import type { LoadingStatus } from "@gradio/statustracker";
6
+ import { Block, BlockLabel } from "@gradio/atoms";
7
+ import { Code as CodeIcon } from "@gradio/icons";
8
+
9
+ export let label = "Motion Canvas Player";
10
+ export let elem_id = "";
11
+ export let elem_classes: string[] = [];
12
+ export let visible = true;
13
+ export let loading_status: LoadingStatus;
14
+ export let gradio: Gradio<{
15
+ change: never;
16
+ click: never;
17
+ clear_status: LoadingStatus;
18
+ }>;
19
+ export let show_label = false;
20
+ export let min_height: number | undefined = undefined;
21
+ export let max_height: number | undefined = undefined;
22
+ export let container = false;
23
+ export let padding = true;
24
+ export let value = "";
25
+
26
+ export let auto: bool | undefined = undefined;
27
+ export let quality: number | undefined = undefined;
28
+ export let width: int | undefined = undefined;
29
+ export let height: int | undefined = undefined;
30
+ export let variables: str | undefined = undefined;
31
+ </script>
32
+
33
+ <Block {visible} {elem_id} {elem_classes} {container} padding={false}>
34
+ {#if show_label}
35
+ <BlockLabel Icon={CodeIcon} {show_label} {label} float={false} />
36
+ {/if}
37
+
38
+ <StatusTracker
39
+ autoscroll={gradio.autoscroll}
40
+ i18n={gradio.i18n}
41
+ {...loading_status}
42
+ variant="center"
43
+ on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
44
+ />
45
+ <div
46
+ class="html-container"
47
+ class:padding
48
+ class:pending={loading_status?.status === "pending"}
49
+ style:min-height={min_height && loading_status?.status !== "pending"
50
+ ? css_units(min_height)
51
+ : undefined}
52
+ style:max-height={max_height ? css_units(max_height) : undefined}
53
+ >
54
+ <MCPlayer
55
+ min_height={loading_status && loading_status?.status !== "complete"}
56
+ {value}
57
+ {auto}
58
+ {quality}
59
+ {width}
60
+ {height}
61
+ {variables}
62
+
63
+ {elem_classes}
64
+ {visible}
65
+ on:change={() => gradio.dispatch("change")}
66
+ on:click={() => gradio.dispatch("click")}
67
+ />
68
+ </div>
69
+ </Block>
70
+
71
+ <style>
72
+ .padding {
73
+ padding: var(--block-padding);
74
+ }
75
+
76
+ div {
77
+ transition: 150ms;
78
+ }
79
+
80
+ .pending {
81
+ opacity: 0.2;
82
+ }
83
+ </style>
src/frontend/gradio.config.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ export default {
2
+ plugins: [],
3
+ svelte: {
4
+ preprocess: [],
5
+ },
6
+ build: {
7
+ target: "modules",
8
+ },
9
+ };
src/frontend/package-lock.json ADDED
The diff for this file is too large to render. See raw diff
 
src/frontend/package.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "gradio_motioncanvasplayer",
3
+ "version": "0.6.14",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "dependencies": {
11
+ "@gradio/atoms": "0.16.1",
12
+ "@gradio/icons": "0.12.0",
13
+ "@gradio/statustracker": "0.10.12",
14
+ "@gradio/utils": "0.10.2",
15
+ "@motion-canvas/core": "^3.17.2",
16
+ "@motion-canvas/player": "^3.17.2"
17
+ },
18
+ "devDependencies": {
19
+ "@gradio/preview": "0.13.1"
20
+ },
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "gradio": "./Index.svelte",
25
+ "svelte": "./dist/Index.svelte",
26
+ "types": "./dist/Index.svelte.d.ts"
27
+ },
28
+ "./example": {
29
+ "gradio": "./Example.svelte",
30
+ "svelte": "./dist/Example.svelte",
31
+ "types": "./dist/Example.svelte.d.ts"
32
+ },
33
+ "./base": {
34
+ "gradio": "./Index.svelte",
35
+ "svelte": "./dist/Index.svelte",
36
+ "types": "./dist/Index.svelte.d.ts"
37
+ }
38
+ },
39
+ "peerDependencies": {
40
+ "svelte": "^4.0.0"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/gradio-app/gradio.git",
45
+ "directory": "js/html"
46
+ }
47
+ }
src/frontend/shared/MCPlayer.svelte ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher } from "svelte";
3
+ import '@motion-canvas/player';
4
+ export let elem_classes: string[] = [];
5
+ export let value: string;
6
+ export let width: number | undefined;
7
+ export let height: number | undefined;
8
+ export let auto: boolean | undefined;
9
+ export let quality: number | undefined;
10
+ export let variables: string | undefined;
11
+
12
+ export let visible = true;
13
+
14
+ const dispatch = createEventDispatcher<{
15
+ change: undefined;
16
+ click: undefined;
17
+ }>();
18
+
19
+ $: value, dispatch("change");
20
+
21
+ let mcPlayerAdditionalAttributes = {};
22
+ if (width) mcPlayerAdditionalAttributes.width = width;
23
+ if (height) mcPlayerAdditionalAttributes.height = height;
24
+ if (auto) mcPlayerAdditionalAttributes.auto = auto;
25
+ if (quality) mcPlayerAdditionalAttributes.quality = quality;
26
+ if (variables) mcPlayerAdditionalAttributes.variables = variables;
27
+
28
+ </script>
29
+
30
+ <!-- svelte-ignore a11y-click-events-have-key-events a11y-no-static-element-interactions -->
31
+ <div
32
+ class="prose {elem_classes.join(' ')}"
33
+ class:hide={!visible}
34
+ on:click={() => dispatch("click")}
35
+ >
36
+ <!-- See https://github.com/motion-canvas/motion-canvas/blob/main/packages/player/types/main.d.ts for supported props -->
37
+ {#if value}
38
+ <motion-canvas-player
39
+ src={value}
40
+ {...mcPlayerAdditionalAttributes}
41
+ ></motion-canvas-player>
42
+ {/if}
43
+ </div>
44
+
45
+ <style>
46
+ .hide {
47
+ display: none;
48
+ }
49
+ </style>
src/frontend/tsconfig.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "esModuleInterop": true,
6
+ "forceConsistentCasingInFileNames": true,
7
+ "resolveJsonModule": true,
8
+ "skipLibCheck": true,
9
+ "sourceMap": true,
10
+ "strict": true,
11
+ "verbatimModuleSyntax": true
12
+ },
13
+ "exclude": ["node_modules", "dist", "./gradio.config.js"]
14
+ }
src/pyproject.toml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = [
3
+ "hatchling",
4
+ "hatch-requirements-txt",
5
+ "hatch-fancy-pypi-readme>=22.5.0",
6
+ ]
7
+ build-backend = "hatchling.build"
8
+
9
+ [project]
10
+ name = "gradio_motioncanvasplayer"
11
+ version = "0.0.1"
12
+ description = "Motion Canvas Player to render Motion Canvas projects"
13
+ readme = "README.md"
14
+ license = "mit"
15
+ requires-python = ">=3.10"
16
+ authors = [{ name = "YOUR NAME", email = "[email protected]" }]
17
+ keywords = ["gradio-custom-component", "gradio-template-HTML", "Motion Canvas", "Animation", "Player"]
18
+ # Add dependencies here
19
+ dependencies = ["gradio>=4.0,<6.0"]
20
+ classifiers = [
21
+ 'Development Status :: 3 - Alpha',
22
+ 'Operating System :: OS Independent',
23
+ 'Programming Language :: Python :: 3',
24
+ 'Programming Language :: Python :: 3 :: Only',
25
+ 'Programming Language :: Python :: 3.8',
26
+ 'Programming Language :: Python :: 3.9',
27
+ 'Programming Language :: Python :: 3.10',
28
+ 'Programming Language :: Python :: 3.11',
29
+ 'Topic :: Scientific/Engineering',
30
+ 'Topic :: Scientific/Engineering :: Artificial Intelligence',
31
+ 'Topic :: Scientific/Engineering :: Visualization',
32
+ ]
33
+
34
+ # The repository and space URLs are optional, but recommended.
35
+ # Adding a repository URL will create a badge in the auto-generated README that links to the repository.
36
+ # Adding a space URL will create a badge in the auto-generated README that links to the space.
37
+ # This will make it easy for people to find your deployed demo or source code when they
38
+ # encounter your project in the wild.
39
+
40
+ # [project.urls]
41
+ # repository = "your github repository"
42
+ # space = "your space url"
43
+
44
+ [project.optional-dependencies]
45
+ dev = ["build", "twine"]
46
+
47
+ [tool.hatch.build]
48
+ artifacts = ["/backend/gradio_motioncanvasplayer/templates", "*.pyi", "/Users/pr/.pyenv/versions/3.10.17/lib/python3.10/site-packages/gradio_motioncanvasplayer/templates"]
49
+
50
+ [tool.hatch.build.targets.wheel]
51
+ packages = ["/backend/gradio_motioncanvasplayer"]