clement-pages commited on
Commit
44a4a1b
·
1 Parent(s): 5a6fb8b

update component meta info

Browse files
Files changed (2) hide show
  1. sourceviewer/README.md +405 -3
  2. sourceviewer/pyproject.toml +10 -6
sourceviewer/README.md CHANGED
@@ -1,10 +1,412 @@
1
 
2
- # gradio_sourceviewer
3
- A Custom Gradio component.
4
 
5
- ## Example usage
 
 
 
 
 
 
 
 
6
 
7
  ```python
8
  import gradio as gr
9
  from gradio_sourceviewer import SourceViewer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ```
 
1
 
2
+ # `gradio_sourceviewer`
3
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%201.0.0%20-%20orange">
4
 
5
+ Python library for easily interacting with trained machine learning models
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install gradio_sourceviewer
11
+ ```
12
+
13
+ ## Usage
14
 
15
  ```python
16
  import gradio as gr
17
  from gradio_sourceviewer import SourceViewer
18
+ from pyannote.audio import Pipeline
19
+ import os
20
+
21
+
22
+ def apply_pipeline(audio: str) -> tuple:
23
+ pipeline = Pipeline.from_pretrained(
24
+ "pyannote/speech-separation-ami-1.0", use_auth_token=os.environ["HF_TOKEN"]
25
+ )
26
+ return pipeline(audio)
27
+
28
+
29
+ with gr.Blocks() as demo:
30
+ audio = gr.Audio(type="filepath")
31
+ btn = gr.Button("Apply separation pipeline")
32
+ source_viewer = SourceViewer(interactive=False)
33
+
34
+ btn.click(fn=apply_pipeline, inputs=[audio], outputs=[source_viewer])
35
+
36
+
37
+ if __name__ == "__main__":
38
+ demo.launch()
39
+
40
+ ```
41
+
42
+ ## `SourceViewer`
43
+
44
+ ### Initialization
45
+
46
+ <table>
47
+ <thead>
48
+ <tr>
49
+ <th align="left">name</th>
50
+ <th align="left" style="width: 25%;">type</th>
51
+ <th align="left">default</th>
52
+ <th align="left">description</th>
53
+ </tr>
54
+ </thead>
55
+ <tbody>
56
+ <tr>
57
+ <td align="left"><code>value</code></td>
58
+ <td align="left" style="width: 25%;">
59
+
60
+ ```python
61
+ str
62
+ | pathlib.Path
63
+ | tuple[int, numpy.ndarray]
64
+ | Callable
65
+ | None
66
+ ```
67
+
68
+ </td>
69
+ <td align="left"><code>None</code></td>
70
+ <td align="left">A path, URL, or [sample_rate, numpy array] tuple (sample rate in Hz, audio data as a float or int numpy array) for the default value that SourceViewer component is going to take. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
71
+ </tr>
72
+
73
+ <tr>
74
+ <td align="left"><code>sources</code></td>
75
+ <td align="left" style="width: 25%;">
76
+
77
+ ```python
78
+ list["upload" | "microphone"] | None
79
+ ```
80
+
81
+ </td>
82
+ <td align="left"><code>None</code></td>
83
+ <td align="left">A list of sources permitted for audio. "upload" creates a box where user can drop an audio file, "microphone" creates a microphone input. The first element in the list will be used as the default source. If None, defaults to ["upload", "microphone"], or ["microphone"] if `streaming` is True.</td>
84
+ </tr>
85
+
86
+ <tr>
87
+ <td align="left"><code>type</code></td>
88
+ <td align="left" style="width: 25%;">
89
+
90
+ ```python
91
+ "numpy" | "filepath"
92
+ ```
93
+
94
+ </td>
95
+ <td align="left"><code>"numpy"</code></td>
96
+ <td align="left">The format the audio file is converted to before being passed into the prediction function. "numpy" converts the audio to a tuple consisting of: (int sample rate, numpy.array for the data), "filepath" passes a str path to a temporary file containing the audio.</td>
97
+ </tr>
98
+
99
+ <tr>
100
+ <td align="left"><code>label</code></td>
101
+ <td align="left" style="width: 25%;">
102
+
103
+ ```python
104
+ str | None
105
+ ```
106
+
107
+ </td>
108
+ <td align="left"><code>None</code></td>
109
+ <td align="left">The label for this component. Appears above the component 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 is assigned to.</td>
110
+ </tr>
111
+
112
+ <tr>
113
+ <td align="left"><code>every</code></td>
114
+ <td align="left" style="width: 25%;">
115
+
116
+ ```python
117
+ float | None
118
+ ```
119
+
120
+ </td>
121
+ <td align="left"><code>None</code></td>
122
+ <td align="left">If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.</td>
123
+ </tr>
124
+
125
+ <tr>
126
+ <td align="left"><code>show_label</code></td>
127
+ <td align="left" style="width: 25%;">
128
+
129
+ ```python
130
+ bool | None
131
+ ```
132
+
133
+ </td>
134
+ <td align="left"><code>None</code></td>
135
+ <td align="left">if True, will display label.</td>
136
+ </tr>
137
+
138
+ <tr>
139
+ <td align="left"><code>container</code></td>
140
+ <td align="left" style="width: 25%;">
141
+
142
+ ```python
143
+ bool
144
+ ```
145
+
146
+ </td>
147
+ <td align="left"><code>True</code></td>
148
+ <td align="left">If True, will place the component in a container - providing some extra padding around the border.</td>
149
+ </tr>
150
+
151
+ <tr>
152
+ <td align="left"><code>scale</code></td>
153
+ <td align="left" style="width: 25%;">
154
+
155
+ ```python
156
+ int | None
157
+ ```
158
+
159
+ </td>
160
+ <td align="left"><code>None</code></td>
161
+ <td align="left">Relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.</td>
162
+ </tr>
163
+
164
+ <tr>
165
+ <td align="left"><code>min_width</code></td>
166
+ <td align="left" style="width: 25%;">
167
+
168
+ ```python
169
+ int
170
+ ```
171
+
172
+ </td>
173
+ <td align="left"><code>160</code></td>
174
+ <td align="left">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.</td>
175
+ </tr>
176
+
177
+ <tr>
178
+ <td align="left"><code>interactive</code></td>
179
+ <td align="left" style="width: 25%;">
180
+
181
+ ```python
182
+ bool | None
183
+ ```
184
+
185
+ </td>
186
+ <td align="left"><code>None</code></td>
187
+ <td align="left">If True, will allow users to upload and edit an audio file. If False, can only be used to play audio. If not provided, this is inferred based on whether the component is used as an input or output.</td>
188
+ </tr>
189
+
190
+ <tr>
191
+ <td align="left"><code>visible</code></td>
192
+ <td align="left" style="width: 25%;">
193
+
194
+ ```python
195
+ bool
196
+ ```
197
+
198
+ </td>
199
+ <td align="left"><code>True</code></td>
200
+ <td align="left">If False, component will be hidden.</td>
201
+ </tr>
202
+
203
+ <tr>
204
+ <td align="left"><code>streaming</code></td>
205
+ <td align="left" style="width: 25%;">
206
+
207
+ ```python
208
+ bool
209
+ ```
210
+
211
+ </td>
212
+ <td align="left"><code>False</code></td>
213
+ <td align="left">If set to True when used in a `live` interface as an input, will automatically stream webcam feed. When used set as an output, takes audio chunks yield from the backend and combines them into one streaming audio output.</td>
214
+ </tr>
215
+
216
+ <tr>
217
+ <td align="left"><code>elem_id</code></td>
218
+ <td align="left" style="width: 25%;">
219
+
220
+ ```python
221
+ str | None
222
+ ```
223
+
224
+ </td>
225
+ <td align="left"><code>None</code></td>
226
+ <td align="left">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
227
+ </tr>
228
+
229
+ <tr>
230
+ <td align="left"><code>elem_classes</code></td>
231
+ <td align="left" style="width: 25%;">
232
+
233
+ ```python
234
+ list[str] | str | None
235
+ ```
236
+
237
+ </td>
238
+ <td align="left"><code>None</code></td>
239
+ <td align="left">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.</td>
240
+ </tr>
241
+
242
+ <tr>
243
+ <td align="left"><code>render</code></td>
244
+ <td align="left" style="width: 25%;">
245
+
246
+ ```python
247
+ bool
248
+ ```
249
+
250
+ </td>
251
+ <td align="left"><code>True</code></td>
252
+ <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>
253
+ </tr>
254
+
255
+ <tr>
256
+ <td align="left"><code>format</code></td>
257
+ <td align="left" style="width: 25%;">
258
+
259
+ ```python
260
+ "wav" | "mp3"
261
+ ```
262
+
263
+ </td>
264
+ <td align="left"><code>"wav"</code></td>
265
+ <td align="left">The file format to save audio files. Either 'wav' or 'mp3'. wav files are lossless but will tend to be larger files. mp3 files tend to be smaller. Default is wav. Applies both when this component is used as an input (when `type` is "format") and when this component is used as an output.</td>
266
+ </tr>
267
+
268
+ <tr>
269
+ <td align="left"><code>autoplay</code></td>
270
+ <td align="left" style="width: 25%;">
271
+
272
+ ```python
273
+ bool
274
+ ```
275
+
276
+ </td>
277
+ <td align="left"><code>False</code></td>
278
+ <td align="left">Whether to automatically play the audio when the component is used as an output. Note: browsers will not autoplay audio files if the user has not interacted with the page yet.</td>
279
+ </tr>
280
+
281
+ <tr>
282
+ <td align="left"><code>show_download_button</code></td>
283
+ <td align="left" style="width: 25%;">
284
+
285
+ ```python
286
+ bool | None
287
+ ```
288
+
289
+ </td>
290
+ <td align="left"><code>None</code></td>
291
+ <td align="left">If True, will show a download button in the corner of the component for saving audio. If False, icon does not appear. By default, it will be True for output components and False for input components.</td>
292
+ </tr>
293
+
294
+ <tr>
295
+ <td align="left"><code>show_share_button</code></td>
296
+ <td align="left" style="width: 25%;">
297
+
298
+ ```python
299
+ bool | None
300
+ ```
301
+
302
+ </td>
303
+ <td align="left"><code>None</code></td>
304
+ <td align="left">If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.</td>
305
+ </tr>
306
+
307
+ <tr>
308
+ <td align="left"><code>editable</code></td>
309
+ <td align="left" style="width: 25%;">
310
+
311
+ ```python
312
+ bool
313
+ ```
314
+
315
+ </td>
316
+ <td align="left"><code>True</code></td>
317
+ <td align="left">If True, allows users to manipulate the audio file if the component is interactive. Defaults to True.</td>
318
+ </tr>
319
+
320
+ <tr>
321
+ <td align="left"><code>min_length</code></td>
322
+ <td align="left" style="width: 25%;">
323
+
324
+ ```python
325
+ int | None
326
+ ```
327
+
328
+ </td>
329
+ <td align="left"><code>None</code></td>
330
+ <td align="left">The minimum length of audio (in seconds) that the user can pass into the prediction function. If None, there is no minimum length.</td>
331
+ </tr>
332
+
333
+ <tr>
334
+ <td align="left"><code>max_length</code></td>
335
+ <td align="left" style="width: 25%;">
336
+
337
+ ```python
338
+ int | None
339
+ ```
340
+
341
+ </td>
342
+ <td align="left"><code>None</code></td>
343
+ <td align="left">The maximum length of audio (in seconds) that the user can pass into the prediction function. If None, there is no maximum length.</td>
344
+ </tr>
345
+
346
+ <tr>
347
+ <td align="left"><code>waveform_options</code></td>
348
+ <td align="left" style="width: 25%;">
349
+
350
+ ```python
351
+ WaveformOptions | dict | None
352
+ ```
353
+
354
+ </td>
355
+ <td align="left"><code>None</code></td>
356
+ <td align="left">A dictionary of options for the waveform display. Options include: waveform_color (str), waveform_progress_color (str), show_controls (bool), skip_length (int), trim_region_color (str). Default is None, which uses the default values for these options.</td>
357
+ </tr>
358
+ </tbody></table>
359
+
360
+
361
+ ### Events
362
+
363
+ | name | description |
364
+ |:-----|:------------|
365
+ | `stream` | This listener is triggered when the user streams the SourceViewer. |
366
+ | `change` | Triggered when the value of the SourceViewer 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. |
367
+ | `clear` | This listener is triggered when the user clears the SourceViewer using the X button for the component. |
368
+ | `play` | This listener is triggered when the user plays the media in the SourceViewer. |
369
+ | `pause` | This listener is triggered when the media in the SourceViewer stops for any reason. |
370
+ | `stop` | This listener is triggered when the user reaches the end of the media playing in the SourceViewer. |
371
+ | `start_recording` | This listener is triggered when the user starts recording with the SourceViewer. |
372
+ | `pause_recording` | This listener is triggered when the user pauses recording with the SourceViewer. |
373
+ | `stop_recording` | This listener is triggered when the user stops recording with the SourceViewer. |
374
+ | `upload` | This listener is triggered when the user uploads a file into the SourceViewer. |
375
+
376
+
377
+
378
+ ### User function
379
+
380
+ 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).
381
+
382
+ - When used as an Input, the component only impacts the input signature of the user function.
383
+ - When used as an output, the component only impacts the return signature of the user function.
384
+
385
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
386
+
387
+ - **As output:** Is passed, passes audio as one of these formats (depending on `type`): a `str` filepath, or `tuple` of (sample rate in Hz, audio data as numpy array). If the latter, the audio data is a 16-bit `int` array whose values range from -32768 to 32767 and shape of the audio data array is (samples,) for mono audio or (samples, channels) for multi-channel audio.
388
+ - **As input:** Should return, expects audio data in any of these formats: a `str` or `pathlib.Path` filepath or URL to an audio file, or a `bytes` object (recommended for streaming), or a `tuple` of (sample rate in Hz, audio data as numpy array). Note: if audio is supplied as a numpy array, the audio will be normalized by its peak value to avoid distortion or clipping in the resulting audio.
389
+
390
+ ```python
391
+ def predict(
392
+ value: str | tuple[int, numpy.ndarray] | None
393
+ ) -> tuple[
394
+ pyannote.core.annotation.Annotation, numpy.ndarray
395
+ ]
396
+ | None:
397
+ return value
398
+ ```
399
+
400
+
401
+ ## `WaveformOptions`
402
+ ```python
403
+ @dataclasses.dataclass
404
+ class WaveformOptions:
405
+ waveform_color: str | None = None
406
+ waveform_progress_color: str | None = None
407
+ trim_region_color: str | None = None
408
+ show_recording_waveform: bool = True
409
+ show_controls: bool = False
410
+ skip_length: int | float = 5
411
+ sample_rate: int = 44100
412
  ```
sourceviewer/pyproject.toml CHANGED
@@ -8,15 +8,21 @@ build-backend = "hatchling.build"
8
 
9
  [project]
10
  name = "gradio_sourceviewer"
11
- version = "0.0.1"
12
  description = "Python library for easily interacting with trained machine learning models"
13
  readme = "README.md"
14
  license = "Apache-2.0"
15
  requires-python = ">=3.8"
16
- authors = [{ name = "YOUR NAME", email = "YOUREMAIL@domain.com" }]
17
  keywords = [
18
  "gradio-custom-component",
19
- "gradio-template-Audio"
 
 
 
 
 
 
20
  ]
21
  # Add dependencies here
22
  dependencies = ["gradio>=4.0,<5.0"]
@@ -26,8 +32,6 @@ classifiers = [
26
  'Operating System :: OS Independent',
27
  'Programming Language :: Python :: 3',
28
  'Programming Language :: Python :: 3 :: Only',
29
- 'Programming Language :: Python :: 3.8',
30
- 'Programming Language :: Python :: 3.9',
31
  'Programming Language :: Python :: 3.10',
32
  'Programming Language :: Python :: 3.11',
33
  'Topic :: Scientific/Engineering',
@@ -39,7 +43,7 @@ classifiers = [
39
  dev = ["build", "twine"]
40
 
41
  [tool.hatch.build]
42
- artifacts = ["/backend/gradio_sourceviewer/templates", "*.pyi"]
43
 
44
  [tool.hatch.build.targets.wheel]
45
  packages = ["/backend/gradio_sourceviewer"]
 
8
 
9
  [project]
10
  name = "gradio_sourceviewer"
11
+ version = "1.0.0"
12
  description = "Python library for easily interacting with trained machine learning models"
13
  readme = "README.md"
14
  license = "Apache-2.0"
15
  requires-python = ">=3.8"
16
+ authors = [{ name = "", email = "clement.pages@irit.fr" }]
17
  keywords = [
18
  "gradio-custom-component",
19
+ "gradio-template-Audio",
20
+ "pyannote-audio",
21
+ "speech-separation",
22
+ "speaker-diarization",
23
+ "source-separation",
24
+ "pixit",
25
+ "totatonet",
26
  ]
27
  # Add dependencies here
28
  dependencies = ["gradio>=4.0,<5.0"]
 
32
  'Operating System :: OS Independent',
33
  'Programming Language :: Python :: 3',
34
  'Programming Language :: Python :: 3 :: Only',
 
 
35
  'Programming Language :: Python :: 3.10',
36
  'Programming Language :: Python :: 3.11',
37
  'Topic :: Scientific/Engineering',
 
43
  dev = ["build", "twine"]
44
 
45
  [tool.hatch.build]
46
+ artifacts = ["/backend/gradio_sourceviewer/templates", "*.pyi", "backend/gradio_sourceviewer/templates"]
47
 
48
  [tool.hatch.build.targets.wheel]
49
  packages = ["/backend/gradio_sourceviewer"]