gradio-pianoroll 0.0.1__py3-none-any.whl → 0.0.2__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.
- gradio_pianoroll/pianoroll.py +559 -201
- gradio_pianoroll/pianoroll.pyi +475 -38
- gradio_pianoroll/templates/component/index.js +7593 -7077
- gradio_pianoroll/templates/component/style.css +1 -1
- gradio_pianoroll-0.0.2.dist-info/METADATA +1015 -0
- gradio_pianoroll-0.0.2.dist-info/RECORD +10 -0
- gradio_pianoroll-0.0.1.dist-info/METADATA +0 -337
- gradio_pianoroll-0.0.1.dist-info/RECORD +0 -10
- {gradio_pianoroll-0.0.1.dist-info → gradio_pianoroll-0.0.2.dist-info}/WHEEL +0 -0
gradio_pianoroll/pianoroll.pyi
CHANGED
@@ -6,12 +6,20 @@ class PianoRoll(Component):
|
|
6
6
|
EVENTS = [
|
7
7
|
Events.change,
|
8
8
|
Events.input,
|
9
|
+
Events.play,
|
10
|
+
Events.pause,
|
11
|
+
Events.stop,
|
12
|
+
Events.clear,
|
9
13
|
]
|
10
14
|
|
11
15
|
def __init__(
|
12
16
|
self,
|
13
17
|
value: dict | None = None,
|
14
18
|
*,
|
19
|
+
audio_data: str | None = None,
|
20
|
+
curve_data: dict | None = None,
|
21
|
+
segment_data: list | None = None,
|
22
|
+
use_backend_audio: bool = False,
|
15
23
|
label: str | I18nData | None = None,
|
16
24
|
every: "Timer | float | None" = None,
|
17
25
|
inputs: Component | Sequence[Component] | set[Component] | None = None,
|
@@ -31,6 +39,10 @@ class PianoRoll(Component):
|
|
31
39
|
"""
|
32
40
|
Parameters:
|
33
41
|
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.
|
42
|
+
audio_data: 백엔드에서 전달받은 오디오 데이터 (base64 인코딩된 오디오 또는 URL)
|
43
|
+
curve_data: 백엔드에서 전달받은 선형 데이터 (피치 곡선, loudness 곡선 등)
|
44
|
+
segment_data: 백엔드에서 전달받은 구간 데이터 (발음 타이밍 등)
|
45
|
+
use_backend_audio: 백엔드 오디오를 사용할지 여부 (True시 프론트엔드 오디오 엔진 비활성화)
|
34
46
|
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
47
|
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
48
|
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.
|
@@ -49,21 +61,65 @@ class PianoRoll(Component):
|
|
49
61
|
"""
|
50
62
|
self.width = width
|
51
63
|
self.height = height
|
64
|
+
|
65
|
+
# Default settings for flicks calculation
|
66
|
+
default_pixels_per_beat = 80
|
67
|
+
default_tempo = 120
|
68
|
+
default_sample_rate = 44100
|
69
|
+
default_ppqn = 480
|
70
|
+
|
71
|
+
default_notes = [
|
72
|
+
create_note_with_timing(generate_note_id(), 80, 80, 60, 100, "안녕",
|
73
|
+
default_pixels_per_beat, default_tempo, default_sample_rate, default_ppqn), # 1st beat of measure 1
|
74
|
+
create_note_with_timing(generate_note_id(), 160, 160, 64, 90, "하세요",
|
75
|
+
default_pixels_per_beat, default_tempo, default_sample_rate, default_ppqn), # 1st beat of measure 2
|
76
|
+
create_note_with_timing(generate_note_id(), 320, 80, 67, 95, "반가워요",
|
77
|
+
default_pixels_per_beat, default_tempo, default_sample_rate, default_ppqn) # 1st beat of measure 3
|
78
|
+
]
|
79
|
+
|
52
80
|
if value is None:
|
53
81
|
self.value = {
|
54
|
-
"notes":
|
55
|
-
"tempo":
|
82
|
+
"notes": default_notes,
|
83
|
+
"tempo": default_tempo,
|
56
84
|
"timeSignature": { "numerator": 4, "denominator": 4 },
|
57
85
|
"editMode": "select",
|
58
|
-
"snapSetting": "1/4"
|
86
|
+
"snapSetting": "1/4",
|
87
|
+
"pixelsPerBeat": default_pixels_per_beat,
|
88
|
+
"sampleRate": default_sample_rate,
|
89
|
+
"ppqn": default_ppqn
|
59
90
|
}
|
60
91
|
else:
|
92
|
+
# Ensure all notes have IDs and flicks values, generate them if missing
|
93
|
+
if "notes" in value and value["notes"]:
|
94
|
+
pixels_per_beat = value.get("pixelsPerBeat", default_pixels_per_beat)
|
95
|
+
tempo = value.get("tempo", default_tempo)
|
96
|
+
|
97
|
+
for note in value["notes"]:
|
98
|
+
if "id" not in note or not note["id"]:
|
99
|
+
note["id"] = generate_note_id()
|
100
|
+
|
101
|
+
# Add flicks values if missing
|
102
|
+
if "startFlicks" not in note:
|
103
|
+
note["startFlicks"] = pixels_to_flicks(note["start"], pixels_per_beat, tempo)
|
104
|
+
if "durationFlicks" not in note:
|
105
|
+
note["durationFlicks"] = pixels_to_flicks(note["duration"], pixels_per_beat, tempo)
|
106
|
+
|
61
107
|
self.value = value
|
62
108
|
|
109
|
+
# 백엔드 데이터 속성들
|
110
|
+
self.audio_data = audio_data
|
111
|
+
self.curve_data = curve_data or {}
|
112
|
+
self.segment_data = segment_data or []
|
113
|
+
self.use_backend_audio = use_backend_audio
|
114
|
+
|
63
115
|
self._attrs = {
|
64
116
|
"width": width,
|
65
117
|
"height": height,
|
66
118
|
"value": self.value,
|
119
|
+
"audio_data": self.audio_data,
|
120
|
+
"curve_data": self.curve_data,
|
121
|
+
"segment_data": self.segment_data,
|
122
|
+
"use_backend_audio": self.use_backend_audio,
|
67
123
|
}
|
68
124
|
|
69
125
|
super().__init__(
|
@@ -101,50 +157,114 @@ class PianoRoll(Component):
|
|
101
157
|
Returns:
|
102
158
|
the data after postprocessing, sent to the frontend
|
103
159
|
"""
|
160
|
+
# Ensure all notes have IDs and all timing values when sending to frontend
|
161
|
+
if value and "notes" in value and value["notes"]:
|
162
|
+
pixels_per_beat = value.get("pixelsPerBeat", 80)
|
163
|
+
tempo = value.get("tempo", 120)
|
164
|
+
sample_rate = value.get("sampleRate", 44100)
|
165
|
+
ppqn = value.get("ppqn", 480)
|
166
|
+
|
167
|
+
for note in value["notes"]:
|
168
|
+
if "id" not in note or not note["id"]:
|
169
|
+
note["id"] = generate_note_id()
|
170
|
+
|
171
|
+
# Add all timing values if missing
|
172
|
+
if "startFlicks" not in note or "startSeconds" not in note:
|
173
|
+
start_timing = calculate_all_timing_data(note["start"], pixels_per_beat, tempo, sample_rate, ppqn)
|
174
|
+
note.update({
|
175
|
+
"startFlicks": start_timing['flicks'],
|
176
|
+
"startSeconds": start_timing['seconds'],
|
177
|
+
"startBeats": start_timing['beats'],
|
178
|
+
"startTicks": start_timing['ticks'],
|
179
|
+
"startSample": start_timing['samples']
|
180
|
+
})
|
181
|
+
|
182
|
+
if "durationFlicks" not in note or "durationSeconds" not in note:
|
183
|
+
duration_timing = calculate_all_timing_data(note["duration"], pixels_per_beat, tempo, sample_rate, ppqn)
|
184
|
+
note.update({
|
185
|
+
"durationFlicks": duration_timing['flicks'],
|
186
|
+
"durationSeconds": duration_timing['seconds'],
|
187
|
+
"durationBeats": duration_timing['beats'],
|
188
|
+
"durationTicks": duration_timing['ticks'],
|
189
|
+
"durationSamples": duration_timing['samples']
|
190
|
+
})
|
191
|
+
|
192
|
+
# Calculate end time if missing
|
193
|
+
if "endSeconds" not in note:
|
194
|
+
note["endSeconds"] = note.get("startSeconds", 0) + note.get("durationSeconds", 0)
|
195
|
+
|
196
|
+
# 백엔드 데이터 속성들도 함께 전달
|
197
|
+
if value and isinstance(value, dict):
|
198
|
+
# value에 이미 있는 백엔드 데이터를 우선하고, 없으면 컴포넌트 속성에서 가져옴
|
199
|
+
# 이렇게 하면 컴포넌트 인스턴스별로 독립적인 백엔드 설정이 가능함
|
200
|
+
|
201
|
+
if "audio_data" not in value or value["audio_data"] is None:
|
202
|
+
if hasattr(self, 'audio_data') and self.audio_data:
|
203
|
+
value["audio_data"] = self.audio_data
|
204
|
+
|
205
|
+
if "curve_data" not in value or value["curve_data"] is None:
|
206
|
+
if hasattr(self, 'curve_data') and self.curve_data:
|
207
|
+
value["curve_data"] = self.curve_data
|
208
|
+
|
209
|
+
if "segment_data" not in value or value["segment_data"] is None:
|
210
|
+
if hasattr(self, 'segment_data') and self.segment_data:
|
211
|
+
value["segment_data"] = self.segment_data
|
212
|
+
|
213
|
+
if "use_backend_audio" not in value:
|
214
|
+
if hasattr(self, 'use_backend_audio'):
|
215
|
+
value["use_backend_audio"] = self.use_backend_audio
|
216
|
+
else:
|
217
|
+
value["use_backend_audio"] = False
|
218
|
+
|
219
|
+
# 디버깅용 로그 추가
|
220
|
+
print(f"🔊 [postprocess] Backend audio data processed:")
|
221
|
+
print(f" - audio_data present: {bool(value.get('audio_data'))}")
|
222
|
+
print(f" - use_backend_audio: {value.get('use_backend_audio', False)}")
|
223
|
+
print(f" - curve_data present: {bool(value.get('curve_data'))}")
|
224
|
+
print(f" - segment_data present: {bool(value.get('segment_data'))}")
|
225
|
+
|
104
226
|
return value
|
105
227
|
|
106
228
|
def example_payload(self):
|
229
|
+
pixels_per_beat = 80
|
230
|
+
tempo = 120
|
231
|
+
sample_rate = 44100
|
232
|
+
ppqn = 480
|
233
|
+
|
107
234
|
return {
|
108
235
|
"notes": [
|
109
|
-
|
110
|
-
|
111
|
-
"start": 80,
|
112
|
-
"duration": 80,
|
113
|
-
"pitch": 60,
|
114
|
-
"velocity": 100,
|
115
|
-
"lyric": "안녕"
|
116
|
-
}
|
236
|
+
create_note_with_timing(generate_note_id(), 80, 80, 60, 100, "안녕",
|
237
|
+
pixels_per_beat, tempo, sample_rate, ppqn)
|
117
238
|
],
|
118
|
-
"tempo":
|
239
|
+
"tempo": tempo,
|
119
240
|
"timeSignature": { "numerator": 4, "denominator": 4 },
|
120
241
|
"editMode": "select",
|
121
|
-
"snapSetting": "1/4"
|
242
|
+
"snapSetting": "1/4",
|
243
|
+
"pixelsPerBeat": pixels_per_beat,
|
244
|
+
"sampleRate": sample_rate,
|
245
|
+
"ppqn": ppqn
|
122
246
|
}
|
123
247
|
|
124
248
|
def example_value(self):
|
249
|
+
pixels_per_beat = 80
|
250
|
+
tempo = 120
|
251
|
+
sample_rate = 44100
|
252
|
+
ppqn = 480
|
253
|
+
|
125
254
|
return {
|
126
255
|
"notes": [
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
}
|
256
|
+
create_note_with_timing(generate_note_id(), 80, 80, 60, 100, "안녕",
|
257
|
+
pixels_per_beat, tempo, sample_rate, ppqn),
|
258
|
+
create_note_with_timing(generate_note_id(), 160, 160, 64, 90, "하세요",
|
259
|
+
pixels_per_beat, tempo, sample_rate, ppqn)
|
143
260
|
],
|
144
|
-
"tempo":
|
261
|
+
"tempo": tempo,
|
145
262
|
"timeSignature": { "numerator": 4, "denominator": 4 },
|
146
263
|
"editMode": "select",
|
147
|
-
"snapSetting": "1/4"
|
264
|
+
"snapSetting": "1/4",
|
265
|
+
"pixelsPerBeat": pixels_per_beat,
|
266
|
+
"sampleRate": sample_rate,
|
267
|
+
"ppqn": ppqn
|
148
268
|
}
|
149
269
|
|
150
270
|
def api_info(self):
|
@@ -157,13 +277,26 @@ class PianoRoll(Component):
|
|
157
277
|
"type": "object",
|
158
278
|
"properties": {
|
159
279
|
"id": {"type": "string"},
|
160
|
-
"start": {"type": "number"},
|
161
|
-
"duration": {"type": "number"},
|
162
|
-
"
|
163
|
-
"
|
164
|
-
"
|
280
|
+
"start": {"type": "number", "description": "Start position in pixels"},
|
281
|
+
"duration": {"type": "number", "description": "Duration in pixels"},
|
282
|
+
"startFlicks": {"type": "number", "description": "Start position in flicks (precise timing)"},
|
283
|
+
"durationFlicks": {"type": "number", "description": "Duration in flicks (precise timing)"},
|
284
|
+
"startSeconds": {"type": "number", "description": "Start time in seconds (for audio processing)"},
|
285
|
+
"durationSeconds": {"type": "number", "description": "Duration in seconds (for audio processing)"},
|
286
|
+
"endSeconds": {"type": "number", "description": "End time in seconds (startSeconds + durationSeconds)"},
|
287
|
+
"startBeats": {"type": "number", "description": "Start position in musical beats"},
|
288
|
+
"durationBeats": {"type": "number", "description": "Duration in musical beats"},
|
289
|
+
"startTicks": {"type": "integer", "description": "Start position in MIDI ticks"},
|
290
|
+
"durationTicks": {"type": "integer", "description": "Duration in MIDI ticks"},
|
291
|
+
"startSample": {"type": "integer", "description": "Start position in audio samples"},
|
292
|
+
"durationSamples": {"type": "integer", "description": "Duration in audio samples"},
|
293
|
+
"pitch": {"type": "number", "description": "MIDI pitch (0-127)"},
|
294
|
+
"velocity": {"type": "number", "description": "MIDI velocity (0-127)"},
|
295
|
+
"lyric": {"type": "string", "description": "Optional lyric text"}
|
165
296
|
},
|
166
|
-
"required": ["id", "start", "duration", "
|
297
|
+
"required": ["id", "start", "duration", "startFlicks", "durationFlicks",
|
298
|
+
"startSeconds", "durationSeconds", "endSeconds", "startBeats", "durationBeats",
|
299
|
+
"startTicks", "durationTicks", "startSample", "durationSamples", "pitch", "velocity"]
|
167
300
|
}
|
168
301
|
},
|
169
302
|
"tempo": {
|
@@ -185,11 +318,127 @@ class PianoRoll(Component):
|
|
185
318
|
"snapSetting": {
|
186
319
|
"type": "string",
|
187
320
|
"description": "Note snap setting"
|
321
|
+
},
|
322
|
+
"pixelsPerBeat": {
|
323
|
+
"type": "number",
|
324
|
+
"description": "Zoom level in pixels per beat"
|
325
|
+
},
|
326
|
+
"sampleRate": {
|
327
|
+
"type": "integer",
|
328
|
+
"description": "Audio sample rate (Hz) for sample-based timing calculations",
|
329
|
+
"default": 44100
|
330
|
+
},
|
331
|
+
"ppqn": {
|
332
|
+
"type": "integer",
|
333
|
+
"description": "Pulses Per Quarter Note for MIDI tick calculations",
|
334
|
+
"default": 480
|
335
|
+
},
|
336
|
+
# 백엔드 데이터 전달용 속성들
|
337
|
+
"audio_data": {
|
338
|
+
"type": "string",
|
339
|
+
"description": "Backend audio data (base64 encoded audio or URL)",
|
340
|
+
"nullable": True
|
341
|
+
},
|
342
|
+
"curve_data": {
|
343
|
+
"type": "object",
|
344
|
+
"description": "Linear curve data (pitch curves, loudness curves, etc.)",
|
345
|
+
"properties": {
|
346
|
+
"pitch_curve": {
|
347
|
+
"type": "array",
|
348
|
+
"items": {"type": "number"},
|
349
|
+
"description": "Pitch curve data points"
|
350
|
+
},
|
351
|
+
"loudness_curve": {
|
352
|
+
"type": "array",
|
353
|
+
"items": {"type": "number"},
|
354
|
+
"description": "Loudness curve data points"
|
355
|
+
},
|
356
|
+
"formant_curves": {
|
357
|
+
"type": "object",
|
358
|
+
"description": "Formant frequency curves",
|
359
|
+
"additionalProperties": {
|
360
|
+
"type": "array",
|
361
|
+
"items": {"type": "number"}
|
362
|
+
}
|
363
|
+
}
|
364
|
+
},
|
365
|
+
"additionalProperties": True,
|
366
|
+
"nullable": True
|
367
|
+
},
|
368
|
+
"segment_data": {
|
369
|
+
"type": "array",
|
370
|
+
"items": {
|
371
|
+
"type": "object",
|
372
|
+
"properties": {
|
373
|
+
"start": {"type": "number", "description": "Segment start time (seconds)"},
|
374
|
+
"end": {"type": "number", "description": "Segment end time (seconds)"},
|
375
|
+
"type": {"type": "string", "description": "Segment type (phoneme, syllable, word, etc.)"},
|
376
|
+
"value": {"type": "string", "description": "Segment value/text"},
|
377
|
+
"confidence": {"type": "number", "description": "Confidence score (0-1)", "minimum": 0, "maximum": 1}
|
378
|
+
},
|
379
|
+
"required": ["start", "end", "type", "value"]
|
380
|
+
},
|
381
|
+
"description": "Segmentation data (pronunciation timing, etc.)",
|
382
|
+
"nullable": True
|
383
|
+
},
|
384
|
+
"use_backend_audio": {
|
385
|
+
"type": "boolean",
|
386
|
+
"description": "Whether to use backend audio (disables frontend audio engine when true)",
|
387
|
+
"default": False
|
188
388
|
}
|
189
389
|
},
|
190
390
|
"required": ["notes", "tempo", "timeSignature", "editMode", "snapSetting"],
|
191
|
-
"description": "Piano roll data object containing notes array and
|
391
|
+
"description": "Piano roll data object containing notes array, settings, and optional backend data"
|
192
392
|
}
|
393
|
+
|
394
|
+
def update_backend_data(self, audio_data=None, curve_data=None, segment_data=None, use_backend_audio=None):
|
395
|
+
"""
|
396
|
+
백엔드 데이터를 업데이트하는 메서드
|
397
|
+
"""
|
398
|
+
if audio_data is not None:
|
399
|
+
self.audio_data = audio_data
|
400
|
+
if curve_data is not None:
|
401
|
+
self.curve_data = curve_data
|
402
|
+
if segment_data is not None:
|
403
|
+
self.segment_data = segment_data
|
404
|
+
if use_backend_audio is not None:
|
405
|
+
self.use_backend_audio = use_backend_audio
|
406
|
+
|
407
|
+
# _attrs도 업데이트
|
408
|
+
self._attrs.update({
|
409
|
+
"audio_data": self.audio_data,
|
410
|
+
"curve_data": self.curve_data,
|
411
|
+
"segment_data": self.segment_data,
|
412
|
+
"use_backend_audio": self.use_backend_audio,
|
413
|
+
})
|
414
|
+
|
415
|
+
def set_audio_data(self, audio_data: str):
|
416
|
+
"""
|
417
|
+
오디오 데이터를 설정하는 메서드
|
418
|
+
"""
|
419
|
+
self.audio_data = audio_data
|
420
|
+
self._attrs["audio_data"] = audio_data
|
421
|
+
|
422
|
+
def set_curve_data(self, curve_data: dict):
|
423
|
+
"""
|
424
|
+
곡선 데이터를 설정하는 메서드 (피치 곡선, loudness 곡선 등)
|
425
|
+
"""
|
426
|
+
self.curve_data = curve_data
|
427
|
+
self._attrs["curve_data"] = curve_data
|
428
|
+
|
429
|
+
def set_segment_data(self, segment_data: list):
|
430
|
+
"""
|
431
|
+
구간 데이터를 설정하는 메서드 (발음 타이밍 등)
|
432
|
+
"""
|
433
|
+
self.segment_data = segment_data
|
434
|
+
self._attrs["segment_data"] = segment_data
|
435
|
+
|
436
|
+
def enable_backend_audio(self, enable: bool = True):
|
437
|
+
"""
|
438
|
+
백엔드 오디오 사용 여부를 설정하는 메서드
|
439
|
+
"""
|
440
|
+
self.use_backend_audio = enable
|
441
|
+
self._attrs["use_backend_audio"] = enable
|
193
442
|
from typing import Callable, Literal, Sequence, Any, TYPE_CHECKING
|
194
443
|
from gradio.blocks import Block
|
195
444
|
if TYPE_CHECKING:
|
@@ -290,3 +539,191 @@ class PianoRoll(Component):
|
|
290
539
|
|
291
540
|
"""
|
292
541
|
...
|
542
|
+
|
543
|
+
def play(self,
|
544
|
+
fn: Callable[..., Any] | None = None,
|
545
|
+
inputs: Block | Sequence[Block] | set[Block] | None = None,
|
546
|
+
outputs: Block | Sequence[Block] | None = None,
|
547
|
+
api_name: str | None | Literal[False] = None,
|
548
|
+
scroll_to_output: bool = False,
|
549
|
+
show_progress: Literal["full", "minimal", "hidden"] = "full",
|
550
|
+
show_progress_on: Component | Sequence[Component] | None = None,
|
551
|
+
queue: bool | None = None,
|
552
|
+
batch: bool = False,
|
553
|
+
max_batch_size: int = 4,
|
554
|
+
preprocess: bool = True,
|
555
|
+
postprocess: bool = True,
|
556
|
+
cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
|
557
|
+
every: Timer | float | None = None,
|
558
|
+
trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
|
559
|
+
js: str | Literal[True] | None = None,
|
560
|
+
concurrency_limit: int | None | Literal["default"] = "default",
|
561
|
+
concurrency_id: str | None = None,
|
562
|
+
show_api: bool = True,
|
563
|
+
|
564
|
+
) -> Dependency:
|
565
|
+
"""
|
566
|
+
Parameters:
|
567
|
+
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.
|
568
|
+
inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
|
569
|
+
outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
|
570
|
+
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.
|
571
|
+
scroll_to_output: if True, will scroll to output component on completion
|
572
|
+
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
|
573
|
+
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.
|
574
|
+
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.
|
575
|
+
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.
|
576
|
+
max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
|
577
|
+
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).
|
578
|
+
postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
|
579
|
+
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.
|
580
|
+
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.
|
581
|
+
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.
|
582
|
+
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.
|
583
|
+
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).
|
584
|
+
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.
|
585
|
+
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.
|
586
|
+
|
587
|
+
"""
|
588
|
+
...
|
589
|
+
|
590
|
+
def pause(self,
|
591
|
+
fn: Callable[..., Any] | None = None,
|
592
|
+
inputs: Block | Sequence[Block] | set[Block] | None = None,
|
593
|
+
outputs: Block | Sequence[Block] | None = None,
|
594
|
+
api_name: str | None | Literal[False] = None,
|
595
|
+
scroll_to_output: bool = False,
|
596
|
+
show_progress: Literal["full", "minimal", "hidden"] = "full",
|
597
|
+
show_progress_on: Component | Sequence[Component] | None = None,
|
598
|
+
queue: bool | None = None,
|
599
|
+
batch: bool = False,
|
600
|
+
max_batch_size: int = 4,
|
601
|
+
preprocess: bool = True,
|
602
|
+
postprocess: bool = True,
|
603
|
+
cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
|
604
|
+
every: Timer | float | None = None,
|
605
|
+
trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
|
606
|
+
js: str | Literal[True] | None = None,
|
607
|
+
concurrency_limit: int | None | Literal["default"] = "default",
|
608
|
+
concurrency_id: str | None = None,
|
609
|
+
show_api: bool = True,
|
610
|
+
|
611
|
+
) -> Dependency:
|
612
|
+
"""
|
613
|
+
Parameters:
|
614
|
+
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.
|
615
|
+
inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
|
616
|
+
outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
|
617
|
+
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.
|
618
|
+
scroll_to_output: if True, will scroll to output component on completion
|
619
|
+
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
|
620
|
+
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.
|
621
|
+
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.
|
622
|
+
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.
|
623
|
+
max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
|
624
|
+
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).
|
625
|
+
postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
|
626
|
+
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.
|
627
|
+
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.
|
628
|
+
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.
|
629
|
+
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.
|
630
|
+
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).
|
631
|
+
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.
|
632
|
+
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.
|
633
|
+
|
634
|
+
"""
|
635
|
+
...
|
636
|
+
|
637
|
+
def stop(self,
|
638
|
+
fn: Callable[..., Any] | None = None,
|
639
|
+
inputs: Block | Sequence[Block] | set[Block] | None = None,
|
640
|
+
outputs: Block | Sequence[Block] | None = None,
|
641
|
+
api_name: str | None | Literal[False] = None,
|
642
|
+
scroll_to_output: bool = False,
|
643
|
+
show_progress: Literal["full", "minimal", "hidden"] = "full",
|
644
|
+
show_progress_on: Component | Sequence[Component] | None = None,
|
645
|
+
queue: bool | None = None,
|
646
|
+
batch: bool = False,
|
647
|
+
max_batch_size: int = 4,
|
648
|
+
preprocess: bool = True,
|
649
|
+
postprocess: bool = True,
|
650
|
+
cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
|
651
|
+
every: Timer | float | None = None,
|
652
|
+
trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
|
653
|
+
js: str | Literal[True] | None = None,
|
654
|
+
concurrency_limit: int | None | Literal["default"] = "default",
|
655
|
+
concurrency_id: str | None = None,
|
656
|
+
show_api: bool = True,
|
657
|
+
|
658
|
+
) -> Dependency:
|
659
|
+
"""
|
660
|
+
Parameters:
|
661
|
+
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.
|
662
|
+
inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
|
663
|
+
outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
|
664
|
+
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.
|
665
|
+
scroll_to_output: if True, will scroll to output component on completion
|
666
|
+
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
|
667
|
+
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.
|
668
|
+
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.
|
669
|
+
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.
|
670
|
+
max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
|
671
|
+
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).
|
672
|
+
postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
|
673
|
+
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.
|
674
|
+
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.
|
675
|
+
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.
|
676
|
+
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.
|
677
|
+
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).
|
678
|
+
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.
|
679
|
+
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.
|
680
|
+
|
681
|
+
"""
|
682
|
+
...
|
683
|
+
|
684
|
+
def clear(self,
|
685
|
+
fn: Callable[..., Any] | None = None,
|
686
|
+
inputs: Block | Sequence[Block] | set[Block] | None = None,
|
687
|
+
outputs: Block | Sequence[Block] | None = None,
|
688
|
+
api_name: str | None | Literal[False] = None,
|
689
|
+
scroll_to_output: bool = False,
|
690
|
+
show_progress: Literal["full", "minimal", "hidden"] = "full",
|
691
|
+
show_progress_on: Component | Sequence[Component] | None = None,
|
692
|
+
queue: bool | None = None,
|
693
|
+
batch: bool = False,
|
694
|
+
max_batch_size: int = 4,
|
695
|
+
preprocess: bool = True,
|
696
|
+
postprocess: bool = True,
|
697
|
+
cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
|
698
|
+
every: Timer | float | None = None,
|
699
|
+
trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
|
700
|
+
js: str | Literal[True] | None = None,
|
701
|
+
concurrency_limit: int | None | Literal["default"] = "default",
|
702
|
+
concurrency_id: str | None = None,
|
703
|
+
show_api: bool = True,
|
704
|
+
|
705
|
+
) -> Dependency:
|
706
|
+
"""
|
707
|
+
Parameters:
|
708
|
+
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.
|
709
|
+
inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
|
710
|
+
outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
|
711
|
+
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.
|
712
|
+
scroll_to_output: if True, will scroll to output component on completion
|
713
|
+
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
|
714
|
+
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.
|
715
|
+
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.
|
716
|
+
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.
|
717
|
+
max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
|
718
|
+
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).
|
719
|
+
postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
|
720
|
+
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.
|
721
|
+
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.
|
722
|
+
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.
|
723
|
+
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.
|
724
|
+
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).
|
725
|
+
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.
|
726
|
+
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.
|
727
|
+
|
728
|
+
"""
|
729
|
+
...
|