Skip to content

Commit dec0b9c

Browse files
Replace token by hugging face button (#34)
* update `gryannote_pipeline` demo app * do not display token textbox if a token was set * bump to version 0.2.0
1 parent 0087a8f commit dec0b9c

File tree

6 files changed

+75
-39
lines changed

6 files changed

+75
-39
lines changed

gryannote/pipeline/README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# `gryannote_pipeline`
3-
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.1.3%20-%20orange">
3+
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.2.0%20-%20orange">
44

55
A component allowing a user to select a pipeline from a drop-down list
66

@@ -10,7 +10,14 @@ A component allowing a user to select a pipeline from a drop-down list
1010
import gradio as gr
1111
from gryannote_pipeline import PipelineSelector
1212

13+
14+
def update_token(oauth_token: gr.OAuthToken | None = None):
15+
token = oauth_token.token if oauth_token else None
16+
return PipelineSelector(show_config=True, token=token)
17+
18+
1319
with gr.Blocks() as demo:
20+
login_button = gr.LoginButton()
1421
pipeline_selector = PipelineSelector(show_config=True)
1522

1623
pipeline_selector.select(
@@ -20,7 +27,6 @@ with gr.Blocks() as demo:
2027
preprocess=False,
2128
postprocess=False,
2229
)
23-
2430
pipeline_selector.change(
2531
fn=pipeline_selector.on_change,
2632
inputs=pipeline_selector,
@@ -148,7 +154,20 @@ bool
148154

149155
</td>
150156
<td align="left"><code>True</code></td>
151-
<td align="left">optional</td>
157+
<td align="left">bool, optional</td>
158+
</tr>
159+
160+
<tr>
161+
<td align="left"><code>show_token_textbox</code></td>
162+
<td align="left" style="width: 25%;">
163+
164+
```python
165+
bool
166+
```
167+
168+
</td>
169+
<td align="left"><code>True</code></td>
170+
<td align="left">bool, optional</td>
152171
</tr>
153172

154173
<tr>

gryannote/pipeline/backend/gryannote_pipeline/pipelineselector.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(
5656
info: str | None = None,
5757
every: float | None = None,
5858
show_label: bool = True,
59+
show_token_textbox: bool = True,
5960
show_config: bool = False,
6061
enable_edition: bool = False,
6162
container: bool = True,
@@ -93,8 +94,11 @@ def __init__(
9394
If `value` is a callable, run the function 'every' number of seconds while the client
9495
connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel it)
9596
via this component's .load_event attribute.
96-
show_label: optional
97+
show_label: bool, optional
9798
If True, will display label.
99+
show_token_textbox: bool, optional
100+
If True, will display texbox to type a HuggingFace token. Automatically set to False if
101+
a `token` is provided.
98102
show_config: bool, optional
99103
If True, will display pipeline hyperparameters configuration interface as soon as a pipeline
100104
has been loaded. Has no effect if `enable_edition` is set to False. Default to False.
@@ -161,11 +165,15 @@ def __init__(
161165
)
162166

163167
self.token = token
168+
# if a token has been provided, do not display token text box in the component interface
169+
if self.token:
170+
show_token_textbox = False
171+
172+
self.show_token_textbox = show_token_textbox
164173

165174
# component is visible only if a pipeline was not already set
166175
visible = getattr(self, "_pipeline", None) is None
167176

168-
169177
self.show_config = show_config
170178
self.enable_edition = enable_edition
171179

gryannote/pipeline/demo/app.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import gradio as gr
22
from gryannote_pipeline import PipelineSelector
33

4+
5+
def update_token(oauth_token: gr.OAuthToken | None = None):
6+
token = oauth_token.token if oauth_token else None
7+
return PipelineSelector(show_config=True, token=token)
8+
9+
410
with gr.Blocks() as demo:
11+
login_button = gr.LoginButton()
512
pipeline_selector = PipelineSelector(show_config=True)
613

714
pipeline_selector.select(
@@ -11,7 +18,6 @@
1118
preprocess=False,
1219
postprocess=False,
1320
)
14-
1521
pipeline_selector.change(
1622
fn=pipeline_selector.on_change,
1723
inputs=pipeline_selector,
@@ -20,5 +26,8 @@
2026
postprocess=False,
2127
)
2228

29+
demo.load(update_token, inputs=None, outputs=pipeline_selector)
30+
31+
2332
if __name__ == "__main__":
2433
demo.launch()

gryannote/pipeline/frontend/Index.svelte

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
export let value_is_output = false;
2323
export let pipelines: [string, string | number][];
2424
export let show_label: boolean;
25+
export let show_token_textbox: boolean;
2526
export let show_config: boolean = false;
2627
export let enable_edition: boolean = false;
2728
export let container = true;
@@ -232,21 +233,21 @@
232233
/>
233234

234235
{#if visible}
235-
236-
<div class="form">
237-
<label for="token" class="label"> Enter your Hugging Face token:</label>
238-
<input
239-
data-testid="textbox"
240-
type="text"
241-
class="text-area"
242-
name="token"
243-
id="token"
244-
placeholder="hf_xxxxxxx..."
245-
aria-label="Enter your Hugging Face token"
246-
maxlength="50"
247-
disabled={!interactive}
248-
bind:value={value.token}
249-
/>
236+
{#if show_token_textbox}
237+
<label for="token" class="label"> Enter your Hugging Face token:</label>
238+
<input
239+
data-testid="textbox"
240+
type="text"
241+
class="text-area"
242+
name="token"
243+
id="token"
244+
placeholder="hf_xxxxxxx..."
245+
aria-label="Enter your Hugging Face token"
246+
maxlength="50"
247+
disabled={!interactive}
248+
bind:value={value.token}
249+
/>
250+
{/if}
250251
<Dropdown
251252
bind:value_is_output
252253
choices={pipelines}
@@ -282,21 +283,20 @@
282283
</div>
283284
{/if}
284285
<div class="params-control" id="params-control"></div>
285-
{#if value.name !== ""}
286-
<div class="validation">
287-
<BaseButton
288-
{elem_id}
289-
{elem_classes}
290-
{scale}
291-
{min_width}
292-
visible={show_config}
293-
on:click={() => gradio.dispatch("change", value)}
294-
>
295-
Update parameters
296-
</BaseButton>
297-
</div>
298-
{/if}
299-
</div>
286+
{#if value.name !== ""}
287+
<div class="validation">
288+
<BaseButton
289+
{elem_id}
290+
{elem_classes}
291+
{scale}
292+
{min_width}
293+
visible={show_config}
294+
on:click={() => gradio.dispatch("change", value)}
295+
>
296+
Update parameters
297+
</BaseButton>
298+
</div>
299+
{/if}
300300
{/if}
301301
</Block>
302302

gryannote/pipeline/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gryannote_pipeline",
3-
"version": "0.6.2",
3+
"version": "0.2.0",
44
"description": "Gradio UI packages",
55
"type": "module",
66
"author": "Clément Pagés [[email protected]]",

gryannote/pipeline/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
88

99
[project]
1010
name = "gryannote_pipeline"
11-
version = "0.1.3"
11+
version = "0.2.0"
1212
description = "A component allowing a user to select a pipeline from a drop-down list"
1313
readme = "README.md"
1414
license = "MIT"
@@ -34,7 +34,7 @@ classifiers = [
3434
dev = ["build", "twine"]
3535

3636
[tool.hatch.build]
37-
artifacts = ["/backend/gryannote_pipeline/templates", "*.pyi"]
37+
artifacts = ["/backend/gryannote_pipeline/templates", "*.pyi", "backend/gryannote_pipeline/templates"]
3838

3939
[tool.hatch.build.targets.wheel]
4040
packages = ["/backend/gryannote_pipeline"]

0 commit comments

Comments
 (0)