gradio-pianoroll 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+
2
+ from .pianoroll import PianoRoll
3
+
4
+ __all__ = ['PianoRoll']
@@ -0,0 +1,201 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Callable, Sequence
4
+ from typing import TYPE_CHECKING, Any
5
+
6
+ from gradio.components.base import Component
7
+ from gradio.events import Events
8
+ from gradio.i18n import I18nData
9
+
10
+ if TYPE_CHECKING:
11
+ from gradio.components import Timer
12
+
13
+ class PianoRoll(Component):
14
+
15
+ EVENTS = [
16
+ Events.change,
17
+ Events.input,
18
+ ]
19
+
20
+ def __init__(
21
+ self,
22
+ value: dict | None = None,
23
+ *,
24
+ label: str | I18nData | None = None,
25
+ every: "Timer | float | None" = None,
26
+ inputs: Component | Sequence[Component] | set[Component] | None = None,
27
+ show_label: bool | None = None,
28
+ scale: int | None = None,
29
+ min_width: int = 160,
30
+ interactive: bool | None = None,
31
+ visible: bool = True,
32
+ elem_id: str | None = None,
33
+ elem_classes: list[str] | str | None = None,
34
+ render: bool = True,
35
+ key: int | str | tuple[int | str, ...] | None = None,
36
+ preserved_by_key: list[str] | str | None = "value",
37
+ width: int | None = 1000,
38
+ height: int | None = 600,
39
+ ):
40
+ """
41
+ Parameters:
42
+ value: default MIDI notes data to provide in piano roll. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
43
+ label: the label for this component, displayed above the component if `show_label` is `True` and is also 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 corresponds to.
44
+ 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.
45
+ 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.
46
+ show_label: if True, will display label.
47
+ scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
48
+ min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
49
+ interactive: if True, will be rendered as an editable piano roll; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.
50
+ visible: If False, component will be hidden.
51
+ elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
52
+ elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
53
+ 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.
54
+ 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.
55
+ 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.
56
+ width: width of the piano roll component in pixels.
57
+ height: height of the piano roll component in pixels.
58
+ """
59
+ self.width = width
60
+ self.height = height
61
+ if value is None:
62
+ self.value = {
63
+ "notes": [],
64
+ "tempo": 120,
65
+ "timeSignature": { "numerator": 4, "denominator": 4 },
66
+ "editMode": "select",
67
+ "snapSetting": "1/4"
68
+ }
69
+ else:
70
+ self.value = value
71
+
72
+ self._attrs = {
73
+ "width": width,
74
+ "height": height,
75
+ "value": self.value,
76
+ }
77
+
78
+ super().__init__(
79
+ label=label,
80
+ every=every,
81
+ inputs=inputs,
82
+ show_label=show_label,
83
+ scale=scale,
84
+ min_width=min_width,
85
+ interactive=interactive,
86
+ visible=visible,
87
+ elem_id=elem_id,
88
+ elem_classes=elem_classes,
89
+ value=value,
90
+ render=render,
91
+ key=key,
92
+ preserved_by_key=preserved_by_key,
93
+ )
94
+
95
+ def preprocess(self, payload):
96
+ """
97
+ This docstring is used to generate the docs for this custom component.
98
+ Parameters:
99
+ payload: the MIDI notes data to be preprocessed, sent from the frontend
100
+ Returns:
101
+ the data after preprocessing, sent to the user's function in the backend
102
+ """
103
+ return payload
104
+
105
+ def postprocess(self, value):
106
+ """
107
+ This docstring is used to generate the docs for this custom component.
108
+ Parameters:
109
+ value: the MIDI notes data to be postprocessed, sent from the user's function in the backend
110
+ Returns:
111
+ the data after postprocessing, sent to the frontend
112
+ """
113
+ return value
114
+
115
+ def example_payload(self):
116
+ return {
117
+ "notes": [
118
+ {
119
+ "id": "note-1",
120
+ "start": 80,
121
+ "duration": 80,
122
+ "pitch": 60,
123
+ "velocity": 100,
124
+ "lyric": "안녕"
125
+ }
126
+ ],
127
+ "tempo": 120,
128
+ "timeSignature": { "numerator": 4, "denominator": 4 },
129
+ "editMode": "select",
130
+ "snapSetting": "1/4"
131
+ }
132
+
133
+ def example_value(self):
134
+ return {
135
+ "notes": [
136
+ {
137
+ "id": "note-1",
138
+ "start": 80,
139
+ "duration": 80,
140
+ "pitch": 60,
141
+ "velocity": 100,
142
+ "lyric": "안녕"
143
+ },
144
+ {
145
+ "id": "note-2",
146
+ "start": 160,
147
+ "duration": 160,
148
+ "pitch": 64,
149
+ "velocity": 90,
150
+ "lyric": "하세요"
151
+ }
152
+ ],
153
+ "tempo": 120,
154
+ "timeSignature": { "numerator": 4, "denominator": 4 },
155
+ "editMode": "select",
156
+ "snapSetting": "1/4"
157
+ }
158
+
159
+ def api_info(self):
160
+ return {
161
+ "type": "object",
162
+ "properties": {
163
+ "notes": {
164
+ "type": "array",
165
+ "items": {
166
+ "type": "object",
167
+ "properties": {
168
+ "id": {"type": "string"},
169
+ "start": {"type": "number"},
170
+ "duration": {"type": "number"},
171
+ "pitch": {"type": "number"},
172
+ "velocity": {"type": "number"},
173
+ "lyric": {"type": "string"}
174
+ },
175
+ "required": ["id", "start", "duration", "pitch", "velocity"]
176
+ }
177
+ },
178
+ "tempo": {
179
+ "type": "number",
180
+ "description": "BPM tempo"
181
+ },
182
+ "timeSignature": {
183
+ "type": "object",
184
+ "properties": {
185
+ "numerator": {"type": "number"},
186
+ "denominator": {"type": "number"}
187
+ },
188
+ "required": ["numerator", "denominator"]
189
+ },
190
+ "editMode": {
191
+ "type": "string",
192
+ "description": "Current edit mode"
193
+ },
194
+ "snapSetting": {
195
+ "type": "string",
196
+ "description": "Note snap setting"
197
+ }
198
+ },
199
+ "required": ["notes", "tempo", "timeSignature", "editMode", "snapSetting"],
200
+ "description": "Piano roll data object containing notes array and settings"
201
+ }
@@ -0,0 +1,292 @@
1
+ from gradio.components.base import Component
2
+
3
+
4
+ class PianoRoll(Component):
5
+
6
+ EVENTS = [
7
+ Events.change,
8
+ Events.input,
9
+ ]
10
+
11
+ def __init__(
12
+ self,
13
+ value: dict | None = None,
14
+ *,
15
+ label: str | I18nData | None = None,
16
+ every: "Timer | float | None" = None,
17
+ inputs: Component | Sequence[Component] | set[Component] | None = None,
18
+ show_label: bool | None = None,
19
+ scale: int | None = None,
20
+ min_width: int = 160,
21
+ interactive: bool | None = None,
22
+ visible: bool = True,
23
+ elem_id: str | None = None,
24
+ elem_classes: list[str] | str | None = None,
25
+ render: bool = True,
26
+ key: int | str | tuple[int | str, ...] | None = None,
27
+ preserved_by_key: list[str] | str | None = "value",
28
+ width: int | None = 1000,
29
+ height: int | None = 600,
30
+ ):
31
+ """
32
+ Parameters:
33
+ value: default MIDI notes data to provide in piano roll. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
34
+ label: the label for this component, displayed above the component if `show_label` is `True` and is also 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 corresponds to.
35
+ 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.
36
+ 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.
37
+ show_label: if True, will display label.
38
+ scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
39
+ min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
40
+ interactive: if True, will be rendered as an editable piano roll; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.
41
+ visible: If False, component will be hidden.
42
+ elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
43
+ elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
44
+ 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.
45
+ 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.
46
+ 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.
47
+ width: width of the piano roll component in pixels.
48
+ height: height of the piano roll component in pixels.
49
+ """
50
+ self.width = width
51
+ self.height = height
52
+ if value is None:
53
+ self.value = {
54
+ "notes": [],
55
+ "tempo": 120,
56
+ "timeSignature": { "numerator": 4, "denominator": 4 },
57
+ "editMode": "select",
58
+ "snapSetting": "1/4"
59
+ }
60
+ else:
61
+ self.value = value
62
+
63
+ self._attrs = {
64
+ "width": width,
65
+ "height": height,
66
+ "value": self.value,
67
+ }
68
+
69
+ super().__init__(
70
+ label=label,
71
+ every=every,
72
+ inputs=inputs,
73
+ show_label=show_label,
74
+ scale=scale,
75
+ min_width=min_width,
76
+ interactive=interactive,
77
+ visible=visible,
78
+ elem_id=elem_id,
79
+ elem_classes=elem_classes,
80
+ value=value,
81
+ render=render,
82
+ key=key,
83
+ preserved_by_key=preserved_by_key,
84
+ )
85
+
86
+ def preprocess(self, payload):
87
+ """
88
+ This docstring is used to generate the docs for this custom component.
89
+ Parameters:
90
+ payload: the MIDI notes data to be preprocessed, sent from the frontend
91
+ Returns:
92
+ the data after preprocessing, sent to the user's function in the backend
93
+ """
94
+ return payload
95
+
96
+ def postprocess(self, value):
97
+ """
98
+ This docstring is used to generate the docs for this custom component.
99
+ Parameters:
100
+ value: the MIDI notes data to be postprocessed, sent from the user's function in the backend
101
+ Returns:
102
+ the data after postprocessing, sent to the frontend
103
+ """
104
+ return value
105
+
106
+ def example_payload(self):
107
+ return {
108
+ "notes": [
109
+ {
110
+ "id": "note-1",
111
+ "start": 80,
112
+ "duration": 80,
113
+ "pitch": 60,
114
+ "velocity": 100,
115
+ "lyric": "안녕"
116
+ }
117
+ ],
118
+ "tempo": 120,
119
+ "timeSignature": { "numerator": 4, "denominator": 4 },
120
+ "editMode": "select",
121
+ "snapSetting": "1/4"
122
+ }
123
+
124
+ def example_value(self):
125
+ return {
126
+ "notes": [
127
+ {
128
+ "id": "note-1",
129
+ "start": 80,
130
+ "duration": 80,
131
+ "pitch": 60,
132
+ "velocity": 100,
133
+ "lyric": "안녕"
134
+ },
135
+ {
136
+ "id": "note-2",
137
+ "start": 160,
138
+ "duration": 160,
139
+ "pitch": 64,
140
+ "velocity": 90,
141
+ "lyric": "하세요"
142
+ }
143
+ ],
144
+ "tempo": 120,
145
+ "timeSignature": { "numerator": 4, "denominator": 4 },
146
+ "editMode": "select",
147
+ "snapSetting": "1/4"
148
+ }
149
+
150
+ def api_info(self):
151
+ return {
152
+ "type": "object",
153
+ "properties": {
154
+ "notes": {
155
+ "type": "array",
156
+ "items": {
157
+ "type": "object",
158
+ "properties": {
159
+ "id": {"type": "string"},
160
+ "start": {"type": "number"},
161
+ "duration": {"type": "number"},
162
+ "pitch": {"type": "number"},
163
+ "velocity": {"type": "number"},
164
+ "lyric": {"type": "string"}
165
+ },
166
+ "required": ["id", "start", "duration", "pitch", "velocity"]
167
+ }
168
+ },
169
+ "tempo": {
170
+ "type": "number",
171
+ "description": "BPM tempo"
172
+ },
173
+ "timeSignature": {
174
+ "type": "object",
175
+ "properties": {
176
+ "numerator": {"type": "number"},
177
+ "denominator": {"type": "number"}
178
+ },
179
+ "required": ["numerator", "denominator"]
180
+ },
181
+ "editMode": {
182
+ "type": "string",
183
+ "description": "Current edit mode"
184
+ },
185
+ "snapSetting": {
186
+ "type": "string",
187
+ "description": "Note snap setting"
188
+ }
189
+ },
190
+ "required": ["notes", "tempo", "timeSignature", "editMode", "snapSetting"],
191
+ "description": "Piano roll data object containing notes array and settings"
192
+ }
193
+ from typing import Callable, Literal, Sequence, Any, TYPE_CHECKING
194
+ from gradio.blocks import Block
195
+ if TYPE_CHECKING:
196
+ from gradio.components import Timer
197
+ from gradio.components.base import Component
198
+
199
+
200
+ def change(self,
201
+ fn: Callable[..., Any] | None = None,
202
+ inputs: Block | Sequence[Block] | set[Block] | None = None,
203
+ outputs: Block | Sequence[Block] | None = None,
204
+ api_name: str | None | Literal[False] = None,
205
+ scroll_to_output: bool = False,
206
+ show_progress: Literal["full", "minimal", "hidden"] = "full",
207
+ show_progress_on: Component | Sequence[Component] | None = None,
208
+ queue: bool | None = None,
209
+ batch: bool = False,
210
+ max_batch_size: int = 4,
211
+ preprocess: bool = True,
212
+ postprocess: bool = True,
213
+ cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
214
+ every: Timer | float | None = None,
215
+ trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
216
+ js: str | Literal[True] | None = None,
217
+ concurrency_limit: int | None | Literal["default"] = "default",
218
+ concurrency_id: str | None = None,
219
+ show_api: bool = True,
220
+
221
+ ) -> Dependency:
222
+ """
223
+ Parameters:
224
+ fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
225
+ inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
226
+ outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
227
+ api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, will use the functions name as the endpoint route. If set to a string, the endpoint will be exposed in the api docs with the given name.
228
+ scroll_to_output: if True, will scroll to output component on completion
229
+ show_progress: how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all
230
+ show_progress_on: Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components.
231
+ queue: if True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app.
232
+ batch: if True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component.
233
+ max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
234
+ preprocess: if False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component).
235
+ postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
236
+ cancels: a list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish.
237
+ 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.
238
+ trigger_mode: if "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete.
239
+ js: optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
240
+ concurrency_limit: if set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
241
+ concurrency_id: if set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
242
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps as well as the Clients to use this event. If fn is None, show_api will automatically be set to False.
243
+
244
+ """
245
+ ...
246
+
247
+ def input(self,
248
+ fn: Callable[..., Any] | None = None,
249
+ inputs: Block | Sequence[Block] | set[Block] | None = None,
250
+ outputs: Block | Sequence[Block] | None = None,
251
+ api_name: str | None | Literal[False] = None,
252
+ scroll_to_output: bool = False,
253
+ show_progress: Literal["full", "minimal", "hidden"] = "full",
254
+ show_progress_on: Component | Sequence[Component] | None = None,
255
+ queue: bool | None = None,
256
+ batch: bool = False,
257
+ max_batch_size: int = 4,
258
+ preprocess: bool = True,
259
+ postprocess: bool = True,
260
+ cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
261
+ every: Timer | float | None = None,
262
+ trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
263
+ js: str | Literal[True] | None = None,
264
+ concurrency_limit: int | None | Literal["default"] = "default",
265
+ concurrency_id: str | None = None,
266
+ show_api: bool = True,
267
+
268
+ ) -> Dependency:
269
+ """
270
+ Parameters:
271
+ fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
272
+ inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
273
+ outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
274
+ api_name: defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, will use the functions name as the endpoint route. If set to a string, the endpoint will be exposed in the api docs with the given name.
275
+ scroll_to_output: if True, will scroll to output component on completion
276
+ show_progress: how to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all
277
+ show_progress_on: Component or list of components to show the progress animation on. If None, will show the progress animation on all of the output components.
278
+ queue: if True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app.
279
+ batch: if True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component.
280
+ max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
281
+ preprocess: if False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component).
282
+ postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
283
+ cancels: a list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish.
284
+ 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.
285
+ trigger_mode: if "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` and `.key_up()` events) would allow a second submission after the pending event is complete.
286
+ js: optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
287
+ concurrency_limit: if set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
288
+ concurrency_id: if set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
289
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps as well as the Clients to use this event. If fn is None, show_api will automatically be set to False.
290
+
291
+ """
292
+ ...