gradio-themer 0.1.0__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,490 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ from pathlib import Path
6
+ from typing import Any, Dict, Callable, Sequence, Optional
7
+ from gradio.components.base import FormComponent
8
+ from gradio.events import Events
9
+
10
+ from gradio.events import Dependency
11
+
12
+ class GradioThemer(FormComponent):
13
+ """
14
+ A custom Gradio component for applying user-configurable themes to Gradio applications.
15
+
16
+ This component allows users to:
17
+ - Configure unlimited custom themes via JSON configuration files
18
+ - Preview themes with live Gradio components
19
+ - Switch between themes dynamically
20
+ - Export CSS for use in other projects
21
+ """
22
+
23
+ EVENTS = [
24
+ Events.change,
25
+ Events.input,
26
+ Events.submit,
27
+ ]
28
+
29
+ def __init__(
30
+ self,
31
+ value: Dict[str, Any] | Callable | None = None,
32
+ theme_config_path: Optional[str] = None,
33
+ *,
34
+ label: str | None = None,
35
+ every: float | None = None,
36
+ inputs: (
37
+ FormComponent | Sequence[FormComponent] | set[FormComponent] | None
38
+ ) = None,
39
+ show_label: bool | None = None,
40
+ scale: int | None = None,
41
+ min_width: int = 160,
42
+ interactive: bool | None = None,
43
+ visible: bool = True,
44
+ elem_id: str | None = None,
45
+ elem_classes: list[str] | str | None = None,
46
+ render: bool = True,
47
+ key: int | str | None = None,
48
+ ):
49
+ """
50
+ Parameters:
51
+ value: Default theme configuration. Should be a dict with 'themeInput', 'themeConfig', and 'generatedCSS' keys.
52
+ theme_config_path: Path to user themes configuration file (JSON). If None, searches for common filenames.
53
+ label: The label for this component, displayed above the component if `show_label` is `True`.
54
+ every: Continously calls `value` to recalculate it if `value` is a function.
55
+ inputs: Components that are used as inputs to calculate `value` if `value` is a function.
56
+ show_label: If True, will display label.
57
+ scale: Relative size compared to adjacent Components.
58
+ min_width: Minimum pixel width.
59
+ interactive: If True, will be rendered as an editable component.
60
+ visible: If False, component will be hidden.
61
+ elem_id: An optional string that is assigned as the id of this component in the HTML DOM.
62
+ elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM.
63
+ render: If False, component will not render be rendered in the Blocks context.
64
+ key: A unique key for this component.
65
+ """
66
+ # Load user themes from configuration before calling super().__init__
67
+ self.user_themes = self._load_user_themes(theme_config_path)
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
+ )
84
+
85
+ def _load_user_themes(self, config_path: Optional[str] = None) -> Dict[str, Any]:
86
+ """
87
+ Load themes from user configuration file
88
+
89
+ Args:
90
+ config_path: Optional path to theme configuration file
91
+
92
+ Returns:
93
+ Dictionary containing user themes, or built-in themes as fallback
94
+ """
95
+ # Default paths to search for theme config
96
+ search_paths = [
97
+ config_path,
98
+ "user_themes.json",
99
+ "themes.json",
100
+ "gradio_themes.json",
101
+ os.path.expanduser("~/.gradio/gradio_themes.json"),
102
+ # Also check in the component's directory for the example file
103
+ os.path.join(
104
+ os.path.dirname(__file__), "..", "..", "user_themes_example.json"
105
+ ),
106
+ ]
107
+
108
+ for path in search_paths:
109
+ if path and Path(path).exists():
110
+ try:
111
+ with open(path, "r") as f:
112
+ config = json.load(f)
113
+ themes = config.get("themes", {})
114
+ if themes:
115
+ print(f"✅ Loaded {len(themes)} user themes from {path}")
116
+ return themes
117
+ except Exception as e:
118
+ print(f"⚠️ Error loading theme config from {path}: {e}")
119
+ continue
120
+
121
+ # Return built-in fallback themes if no config found
122
+ print("📝 No user theme config found, using built-in themes")
123
+ return self._get_builtin_themes()
124
+
125
+ def _get_builtin_themes(self) -> Dict[str, Any]:
126
+ """Get the built-in fallback themes"""
127
+ return {
128
+ "corporate": {
129
+ "name": "Corporate",
130
+ "colors": {
131
+ "base-100": "oklch(100% 0 0)",
132
+ "base-200": "oklch(96% 0.02 276.935)",
133
+ "base-300": "oklch(90% 0.05 293.541)",
134
+ "base-content": "oklch(22.389% 0.031 278.072)",
135
+ "primary": "oklch(58% 0.158 241.966)",
136
+ "primary-content": "oklch(100% 0 0)",
137
+ "secondary": "oklch(55% 0.046 257.417)",
138
+ "secondary-content": "oklch(100% 0 0)",
139
+ "accent": "oklch(60% 0.118 184.704)",
140
+ "accent-content": "oklch(100% 0 0)",
141
+ "neutral": "oklch(0% 0 0)",
142
+ "neutral-content": "oklch(100% 0 0)",
143
+ "error": "oklch(70% 0.191 22.216)",
144
+ "error-content": "oklch(0% 0 0)",
145
+ },
146
+ "background": "#06b6d4",
147
+ },
148
+ "cupcake": {
149
+ "name": "Cupcake",
150
+ "colors": {
151
+ "base-100": "oklch(100% 0 0)",
152
+ "base-200": "oklch(96% 0.014 340.77)",
153
+ "base-300": "oklch(92% 0.021 340.77)",
154
+ "base-content": "oklch(22.389% 0.031 278.072)",
155
+ "primary": "oklch(65.69% 0.196 342.55)",
156
+ "primary-content": "oklch(100% 0 0)",
157
+ "secondary": "oklch(74.51% 0.167 183.61)",
158
+ "secondary-content": "oklch(100% 0 0)",
159
+ "accent": "oklch(74.51% 0.167 183.61)",
160
+ "accent-content": "oklch(100% 0 0)",
161
+ "neutral": "oklch(22.389% 0.031 278.072)",
162
+ "neutral-content": "oklch(100% 0 0)",
163
+ "error": "oklch(70% 0.191 22.216)",
164
+ "error-content": "oklch(0% 0 0)",
165
+ },
166
+ "background": "#faf0e6",
167
+ },
168
+ "dark": {
169
+ "name": "Dark",
170
+ "colors": {
171
+ "base-100": "oklch(25.3% 0.015 252.417)",
172
+ "base-200": "oklch(22.2% 0.013 252.417)",
173
+ "base-300": "oklch(19.1% 0.011 252.417)",
174
+ "base-content": "oklch(74.6% 0.019 83.916)",
175
+ "primary": "oklch(65.69% 0.196 275.75)",
176
+ "primary-content": "oklch(100% 0 0)",
177
+ "secondary": "oklch(74.51% 0.167 183.61)",
178
+ "secondary-content": "oklch(100% 0 0)",
179
+ "accent": "oklch(74.51% 0.167 183.61)",
180
+ "accent-content": "oklch(100% 0 0)",
181
+ "neutral": "oklch(25.3% 0.015 252.417)",
182
+ "neutral-content": "oklch(74.6% 0.019 83.916)",
183
+ "error": "oklch(70% 0.191 22.216)",
184
+ "error-content": "oklch(0% 0 0)",
185
+ },
186
+ "background": "#1f2937",
187
+ },
188
+ "emerald": {
189
+ "name": "Emerald",
190
+ "colors": {
191
+ "base-100": "oklch(100% 0 0)",
192
+ "base-200": "oklch(96% 0.014 154.77)",
193
+ "base-300": "oklch(92% 0.021 154.77)",
194
+ "base-content": "oklch(22.389% 0.031 278.072)",
195
+ "primary": "oklch(65.69% 0.196 162.55)",
196
+ "primary-content": "oklch(100% 0 0)",
197
+ "secondary": "oklch(74.51% 0.167 183.61)",
198
+ "secondary-content": "oklch(100% 0 0)",
199
+ "accent": "oklch(74.51% 0.167 183.61)",
200
+ "accent-content": "oklch(100% 0 0)",
201
+ "neutral": "oklch(22.389% 0.031 278.072)",
202
+ "neutral-content": "oklch(100% 0 0)",
203
+ "error": "oklch(70% 0.191 22.216)",
204
+ "error-content": "oklch(0% 0 0)",
205
+ },
206
+ "background": "#ecfdf5",
207
+ },
208
+ }
209
+
210
+ def preprocess(self, payload: Dict[str, Any] | None) -> Dict[str, Any] | None:
211
+ """
212
+ Parameters:
213
+ payload: The theme configuration data from the frontend.
214
+ Returns:
215
+ Passes the theme configuration as a dict into the function.
216
+ """
217
+ if payload is None:
218
+ return None
219
+
220
+ # Ensure we have the expected structure
221
+ if isinstance(payload, dict):
222
+ # Handle different input formats
223
+ result = {
224
+ "themeInput": payload.get("themeInput", ""),
225
+ "themeConfig": payload.get("themeConfig"),
226
+ "generatedCSS": payload.get("generatedCSS", ""),
227
+ }
228
+
229
+ # Include additional fields if present
230
+ if "currentTheme" in payload:
231
+ result["currentTheme"] = payload["currentTheme"]
232
+ if "type" in payload:
233
+ result["type"] = payload["type"]
234
+
235
+ return result
236
+
237
+ return None
238
+
239
+ def postprocess(self, value: Dict[str, Any] | None) -> Dict[str, Any] | None:
240
+ """
241
+ Parameters:
242
+ value: Expects a dict with theme configuration data.
243
+ Returns:
244
+ The value to display in the component, including user themes.
245
+ """
246
+ if value is None:
247
+ result = self._get_default_value()
248
+ elif isinstance(value, dict):
249
+ # Handle different input formats
250
+ if "currentTheme" in value:
251
+ # Handle theme selection format
252
+ theme_name = value.get("currentTheme", "light")
253
+ result = {
254
+ "currentTheme": theme_name,
255
+ "themeInput": value.get("themeInput", ""),
256
+ "themeConfig": value.get("themeConfig"),
257
+ "generatedCSS": value.get("generatedCSS", ""),
258
+ "type": value.get("type", "builtin"),
259
+ "font": value.get(
260
+ "font",
261
+ {"family": "Inter", "weights": ["400", "500", "600", "700"]},
262
+ ),
263
+ "removeBorders": value.get("removeBorders", True),
264
+ }
265
+ else:
266
+ # Handle raw theme configuration format
267
+ result = {
268
+ "themeInput": value.get("themeInput", ""),
269
+ "themeConfig": value.get("themeConfig"),
270
+ "generatedCSS": value.get("generatedCSS", ""),
271
+ "font": value.get(
272
+ "font",
273
+ {"family": "Inter", "weights": ["400", "500", "600", "700"]},
274
+ ),
275
+ "removeBorders": value.get("removeBorders", True),
276
+ }
277
+ else:
278
+ result = self._get_default_value()
279
+
280
+ # Inject user themes into the result for frontend consumption
281
+ result["available_themes"] = self.user_themes
282
+
283
+ return result
284
+
285
+ def _get_default_value(self) -> Dict[str, Any]:
286
+ """Get the default theme configuration"""
287
+ emerald_theme = """@theme "emerald" {
288
+ name: "emerald";
289
+ default: true;
290
+ prefersdark: false;
291
+ color-scheme: "light";
292
+ --color-base-100: oklch(100% 0 0);
293
+ --color-base-200: oklch(93% 0 0);
294
+ --color-base-300: oklch(86% 0 0);
295
+ --color-base-content: oklch(35.519% 0.032 262.988);
296
+ --color-primary: oklch(76.662% 0.135 153.45);
297
+ --color-primary-content: oklch(33.387% 0.04 162.24);
298
+ --color-secondary: oklch(61.302% 0.202 261.294);
299
+ --color-secondary-content: oklch(100% 0 0);
300
+ --color-accent: oklch(72.772% 0.149 33.2);
301
+ --color-accent-content: oklch(0% 0 0);
302
+ --color-neutral: oklch(35.519% 0.032 262.988);
303
+ --color-neutral-content: oklch(98.462% 0.001 247.838);
304
+ --color-info: oklch(72.06% 0.191 231.6);
305
+ --color-info-content: oklch(0% 0 0);
306
+ --color-success: oklch(64.8% 0.15 160);
307
+ --color-success-content: oklch(0% 0 0);
308
+ --color-warning: oklch(84.71% 0.199 83.87);
309
+ --color-warning-content: oklch(0% 0 0);
310
+ --color-error: oklch(71.76% 0.221 22.18);
311
+ --color-error-content: oklch(0% 0 0);
312
+ --radius-selector: 1rem;
313
+ --radius-field: 0.5rem;
314
+ --radius-box: 1rem;
315
+ --size-selector: 0.25rem;
316
+ --size-field: 0.25rem;
317
+ --border: 1px;
318
+ --depth: 1;
319
+ --noise: 1;
320
+ }"""
321
+
322
+ return {"themeInput": emerald_theme, "themeConfig": None, "generatedCSS": ""}
323
+
324
+ def example_payload(self) -> Any:
325
+ return {
326
+ "themeInput": "sample theme",
327
+ "generatedCSS": ":root { --color-primary: blue; }",
328
+ }
329
+
330
+ def example_value(self) -> Any:
331
+ return {
332
+ "themeInput": "sample theme",
333
+ "generatedCSS": ":root { --color-primary: blue; }",
334
+ }
335
+
336
+ def api_info(self) -> dict[str, Any]:
337
+ return {"type": {}, "description": "Gradio theme configuration object"}
338
+ from typing import Callable, Literal, Sequence, Any, TYPE_CHECKING
339
+ from gradio.blocks import Block
340
+ if TYPE_CHECKING:
341
+ from gradio.components import Timer
342
+ from gradio.components.base import Component
343
+
344
+
345
+ def change(self,
346
+ fn: Callable[..., Any] | None = None,
347
+ inputs: Block | Sequence[Block] | set[Block] | None = None,
348
+ outputs: Block | Sequence[Block] | None = None,
349
+ api_name: str | None | Literal[False] = None,
350
+ scroll_to_output: bool = False,
351
+ show_progress: Literal["full", "minimal", "hidden"] = "full",
352
+ show_progress_on: Component | Sequence[Component] | None = None,
353
+ queue: bool | None = None,
354
+ batch: bool = False,
355
+ max_batch_size: int = 4,
356
+ preprocess: bool = True,
357
+ postprocess: bool = True,
358
+ cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
359
+ every: Timer | float | None = None,
360
+ trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
361
+ js: str | Literal[True] | None = None,
362
+ concurrency_limit: int | None | Literal["default"] = "default",
363
+ concurrency_id: str | None = None,
364
+ show_api: bool = True,
365
+ key: int | str | tuple[int | str, ...] | None = None,
366
+
367
+ ) -> Dependency:
368
+ """
369
+ Parameters:
370
+ 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.
371
+ inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
372
+ outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
373
+ 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.
374
+ scroll_to_output: if True, will scroll to output component on completion
375
+ 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
376
+ 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.
377
+ 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.
378
+ 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.
379
+ max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
380
+ 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).
381
+ postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
382
+ 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.
383
+ 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.
384
+ 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.
385
+ 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.
386
+ 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).
387
+ 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.
388
+ 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.
389
+ key: A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical.
390
+
391
+ """
392
+ ...
393
+
394
+ def input(self,
395
+ fn: Callable[..., Any] | None = None,
396
+ inputs: Block | Sequence[Block] | set[Block] | None = None,
397
+ outputs: Block | Sequence[Block] | None = None,
398
+ api_name: str | None | Literal[False] = None,
399
+ scroll_to_output: bool = False,
400
+ show_progress: Literal["full", "minimal", "hidden"] = "full",
401
+ show_progress_on: Component | Sequence[Component] | None = None,
402
+ queue: bool | None = None,
403
+ batch: bool = False,
404
+ max_batch_size: int = 4,
405
+ preprocess: bool = True,
406
+ postprocess: bool = True,
407
+ cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
408
+ every: Timer | float | None = None,
409
+ trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
410
+ js: str | Literal[True] | None = None,
411
+ concurrency_limit: int | None | Literal["default"] = "default",
412
+ concurrency_id: str | None = None,
413
+ show_api: bool = True,
414
+ key: int | str | tuple[int | str, ...] | None = None,
415
+
416
+ ) -> Dependency:
417
+ """
418
+ Parameters:
419
+ 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.
420
+ inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
421
+ outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
422
+ 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.
423
+ scroll_to_output: if True, will scroll to output component on completion
424
+ 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
425
+ 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.
426
+ 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.
427
+ 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.
428
+ max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
429
+ 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).
430
+ postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
431
+ 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.
432
+ 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.
433
+ 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.
434
+ 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.
435
+ 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).
436
+ 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.
437
+ 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.
438
+ key: A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical.
439
+
440
+ """
441
+ ...
442
+
443
+ def submit(self,
444
+ fn: Callable[..., Any] | None = None,
445
+ inputs: Block | Sequence[Block] | set[Block] | None = None,
446
+ outputs: Block | Sequence[Block] | None = None,
447
+ api_name: str | None | Literal[False] = None,
448
+ scroll_to_output: bool = False,
449
+ show_progress: Literal["full", "minimal", "hidden"] = "full",
450
+ show_progress_on: Component | Sequence[Component] | None = None,
451
+ queue: bool | None = None,
452
+ batch: bool = False,
453
+ max_batch_size: int = 4,
454
+ preprocess: bool = True,
455
+ postprocess: bool = True,
456
+ cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
457
+ every: Timer | float | None = None,
458
+ trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
459
+ js: str | Literal[True] | None = None,
460
+ concurrency_limit: int | None | Literal["default"] = "default",
461
+ concurrency_id: str | None = None,
462
+ show_api: bool = True,
463
+ key: int | str | tuple[int | str, ...] | None = None,
464
+
465
+ ) -> Dependency:
466
+ """
467
+ Parameters:
468
+ 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.
469
+ inputs: list of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
470
+ outputs: list of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
471
+ 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.
472
+ scroll_to_output: if True, will scroll to output component on completion
473
+ 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
474
+ 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.
475
+ 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.
476
+ 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.
477
+ max_batch_size: maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
478
+ 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).
479
+ postprocess: if False, will not run postprocessing of component data before returning 'fn' output to the browser.
480
+ 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.
481
+ 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.
482
+ 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.
483
+ 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.
484
+ 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).
485
+ 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.
486
+ 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.
487
+ key: A unique key for this event listener to be used in @gr.render(). If set, this value identifies an event as identical across re-renders when the key is identical.
488
+
489
+ """
490
+ ...