text stringlengths 0 2k | heading1 stringlengths 3 79 | source_page_url stringclasses 189
values | source_page_title stringclasses 189
values |
|---|---|---|---|
gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and only if it
com... | Event Listeners | https://gradio.app/docs/gradio/lineplot | Gradio - Lineplot Docs |
The gr.DownloadData class is a subclass of gr.EventData that specifically
carries information about the `.download()` event. When gr.DownloadData is
added as a type hint to an argument of an event listener method, a
gr.DownloadData object will automatically be passed as the value of that
argument. The attributes of thi... | Description | https://gradio.app/docs/gradio/downloaddata | Gradio - Downloaddata Docs |
import gradio as gr
def on_download(download_data: gr.DownloadData):
return f"Downloaded file: {download_data.file.path}"
with gr.Blocks() as demo:
files = gr.File()
textbox = gr.Textbox()
files.download(on_download, None, textbox)
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/downloaddata | Gradio - Downloaddata Docs |
Parameters ▼
file: FileData
The file that was downloaded, as a FileData object.
| Attributes | https://gradio.app/docs/gradio/downloaddata | Gradio - Downloaddata Docs |
This class allows you to pass custom error messages to the user. You can do
so by raising a gr.Error("custom message") anywhere in the code, and when that
line is executed the custom message will appear in a modal on the demo.
You can control for how long the error message is displayed with the
`duration` parameter. I... | Description | https://gradio.app/docs/gradio/error | Gradio - Error Docs |
import gradio as gr
def divide(numerator, denominator):
if denominator == 0:
raise gr.Error("Cannot divide by zero!")
gr.Interface(divide, ["number", "number"], "number").launch()
| Example Usage | https://gradio.app/docs/gradio/error | Gradio - Error Docs |
Parameters ▼
message: str
default `= "Error raised."`
The error message to be displayed to the user. Can be HTML, which will be
rendered in the modal.
duration: float | None
default `= 10`
The duration in seconds to display the error message. If None or 0, the error
message will be d... | Initialization | https://gradio.app/docs/gradio/error | Gradio - Error Docs |
calculatorblocks_chained_events
[Alerts](../../guides/alerts/)
| Demos | https://gradio.app/docs/gradio/error | Gradio - Error Docs |
Sets up an API or MCP endpoint for a generic function without needing
define events listeners or components. Derives its typing from type hints in
the provided function's signature rather than the components.
| Description | https://gradio.app/docs/gradio/api | Gradio - Api Docs |
import gradio as gr
with gr.Blocks() as demo:
with gr.Row():
input = gr.Textbox()
button = gr.Button("Submit")
output = gr.Textbox()
def fn(a: int, b: int, c: list[str]) -> tuple[int, str]:
return a + b, c[a:b]
gr.api(fn, api_name="add_and_slice")
... | Example Usage | https://gradio.app/docs/gradio/api | Gradio - Api Docs |
Parameters ▼
fn: Callable | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning
model's prediction function. The function should be fully typed, and the type
hints will be used to derive the typing information for the API/MCP endpoin... | Initialization | https://gradio.app/docs/gradio/api | Gradio - Api Docs |
eue
(only relevant if batch=True)
concurrency_limit: int | None | Literal['default']
default `= "default"`
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 ... | Initialization | https://gradio.app/docs/gradio/api | Gradio - Api Docs |
Creates an audio component that can be used to upload/record audio (as an
input) or display audio (as an output).
| Description | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
**Using Audio as an input component.**
How Audio will pass its value to your function:
Type: `str | tuple[int, np.ndarray] | None`
Passes audio as one of these formats (depending on `type`):
* `str` filepath
* `tuple` of (sample rate in Hz, audio data as numpy array).
* The audio data is a 16-bit `int` ar... | Behavior | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
Parameters ▼
value: str | Path | tuple[int, np.ndarray] | Callable | None
default `= None`
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 Audio component
is going to take. If a function is provided, the function... | Initialization | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
set[Component] | None
default `= None`
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.
show_label: bool | None
default `= None`
if True, will display label.
container: boo... | Initialization | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
elem_id: str | None
default `= None`
An optional string that is assigned as the id of this component in the HTML
DOM. Can be used for targeting CSS styles.
elem_classes: list[str] | str | None
default `= None`
An optional list of strings that are assigned as the classes of this component
in... | Initialization | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
and the audio is kept as is. In the case where output audio is
returned from the prediction function as numpy array and no `format` is
provided, it will be returned as a "wav" file.
autoplay: bool
default `= False`
Whether to automatically play the audio when the component is used as an
output. Note:... | Initialization | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
phone
if the source is set to "microphone". Defaults to False.
subtitles: str | Path | list[dict[str, Any]] | None
default `= None`
A subtitle file (srt, vtt, or json) for the audio, or a list of subtitle
dictionaries in the format [{"text": str, "timestamp": [start, end]}] where
timestamps are in sec... | Initialization | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
Shortcuts
gradio.Audio
Interface String Shortcut `"audio"`
Initialization Uses default values
gradio.Microphone
Interface String Shortcut `"microphone"`
Initialization Uses sources=["microphone"]
| Shortcuts | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
generate_tonereverse_audio
| Demos | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Audio component supports the following ... | Event Listeners | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
r stops recording with the Audio.
Audio.upload(fn, ···)
This listener is triggered when the user uploads a file into the Audio.
Audio.input(fn, ···)
This listener is triggered when the user changes the value of the Audio.
Event Parameters
Parameters ▼
fn: Callable | Non... | Event Listeners | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
f False, then no description will be displayed in the
API docs.
scroll_to_output: bool
default `= False`
If True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "minimal"`
how to show the progress animation while event is ... | Event Listeners | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
with the `Image`
component).
postprocess: bool
default `= True`
If False, will not run postprocessing of component data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
A list of other events to cancel when this liste... | Event Listeners | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
= None`
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.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "publi... | Event Listeners | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
Helper Classes | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs | |
gradio.WaveformOptions(···)
Description
A dataclass for specifying options for the waveform display in the Audio
component. An instance of this class can be passed into the `waveform_options`
parameter of `gr.Audio`.
Initialization
Parameters ▼
waveform_color: str | None
default `= None`
The color... | WaveformOptions | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
Validates that the audio length is within the specified min and max length (in
seconds). You can use this to construct a validator that will check if the
user-provided audio is either too short or too long.
import gradio as gr
demo = gr.Interface(
lambda x: x,
inputs="audio",
... | is_audio_correct_length | https://gradio.app/docs/gradio/audio | Gradio - Audio Docs |
Creates a textarea for user to enter string input or display string output.
| Description | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
**Using Textbox as an input component.**
How Textbox will pass its value to your function:
Type: `str | None`
Passes text value as a `str` into the function.
Example Code
import gradio as gr
def predict(
value: str | None
):
process value from... | Behavior | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
Parameters ▼
value: str | I18nData | Callable | None
default `= None`
text to show in textbox. If a function is provided, the function will be
called each time the app loads to set the initial value of this component.
type: Literal['text', 'password', 'email']
default `= "text"`
The ... | Initialization | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
e regular interval for the reset Timer.
inputs: Component | list[Component] | set[Component] | None
default `= None`
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.
show_labe... | Initialization | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
targeting CSS styles.
autofocus: bool
default `= False`
If True, will focus on the textbox when the page loads. Use this carefully, as
it can cause usability issues for sighted and non-sighted users.
autoscroll: bool
default `= True`
If True, will automatically scroll to the bottom o... | Initialization | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
True. Can only be changed if `type` is "text".
rtl: bool
default `= False`
If True and `type` is "text", sets the direction of the text to right-to-left
(cursor appears on the left of the text). Default is False, which renders
cursor on the right.
buttons: list[Literal['copy'] | Button... | Initialization | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
InputHTMLAttributes(autocorrect="off", spellcheck=False) to disable
autocorrect and spellcheck.
| Initialization | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
Shortcuts
gradio.Textbox
Interface String Shortcut `"textbox"`
Initialization Uses default values
gradio.TextArea
Interface String Shortcut `"textarea"`
Initialization Uses lines=7
| Shortcuts | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
Multi-line text input
By default, `gr.Textbox` renders as a single-line input. For longer text such
as paragraphs or code, set `lines` to show multiple rows and optionally
`max_lines` to cap the height:
import gradio as gr
def summarize(text):
return f"Received {len(text.split())} words... | Common Patterns | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
hello_worlddiff_textssentence_builder
| Demos | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Textbox component supports the followin... | Event Listeners | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
t data gradio.CopyData to carry information about the copied content. See
EventData documentation on how to use this event data
Event Parameters
Parameters ▼
fn: Callable | None | Literal['decorator']
default `= "decorator"`
the function to call when this event is triggered. Often a machine learning... | Event Listeners | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
True, will scroll to output component on completion
show_progress: Literal['full', 'minimal', 'hidden']
default `= "full"`
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, "m... | Event Listeners | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
ent data before returning 'fn'
output to the browser.
cancels: dict[str, Any] | list[dict[str, Any]] | None
default `= None`
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 o... | Event Listeners | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
oncurrency_limit.
api_visibility: Literal['public', 'private', 'undocumented']
default `= "public"`
controls the visibility and accessibility of this endpoint. Can be "public"
(shown in API docs and callable by clients), "private" (hidden from API docs
and not callable by the Gradio client libraries),... | Event Listeners | https://gradio.app/docs/gradio/textbox | Gradio - Textbox Docs |
Load a chat interface from an OpenAI API chat compatible endpoint.
| Description | https://gradio.app/docs/gradio/load_chat | Gradio - Load_Chat Docs |
import gradio as gr
demo = gr.load_chat("http://localhost:11434/v1", model="deepseek-r1")
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/load_chat | Gradio - Load_Chat Docs |
Parameters ▼
base_url: str
The base URL of the endpoint, e.g. "http://localhost:11434/v1/"
model: str
The name of the model you are loading, e.g. "llama3.2"
token: str | None
default `= None`
The API token or a placeholder string if you are using a local model, e.g.
"... | Initialization | https://gradio.app/docs/gradio/load_chat | Gradio - Load_Chat Docs |
Creates an image component that can be used to upload images (as an input)
or display images (as an output).
| Description | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
**Using Image as an input component.**
How Image will pass its value to your function:
Type: `np.ndarray | PIL.Image.Image | str | None`
Passes the uploaded image as a `numpy.array`, `PIL.Image` or `str` filepath
depending on `type`.
Example Code
import gradio as gr
def pred... | Behavior | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
Parameters ▼
value: str | PIL.Image.Image | np.ndarray | Callable | None
default `= None`
A `PIL.Image`, `numpy.array`, `pathlib.Path`, or `str` filepath or URL for the
default value that Image component is going to take. If a function is
provided, the function will be called each time the app loads t... | Initialization | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
erred
from the image file type (e.g. "RGBA" for a .png image, "RGB" in most other
cases).
sources: list[Literal['upload', 'webcam', 'clipboard']] | Literal['upload', 'webcam', 'clipboard'] | None
default `= None`
List of sources for the image. "upload" creates a box where user can drop an
image file, ... | Initialization | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
o calculate `value` if `value` is a
function (has no effect otherwise). `value` is recalculated any time the
inputs change.
show_label: bool | None
default `= None`
if True, will display label.
buttons: list[Literal['download', 'share', 'fullscreen'] | Button] | None
default `= None`
... | Initialization | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
rovided, this is inferred based on whether the
component is used as an input or output.
visible: bool | Literal['hidden']
default `= True`
If False, component will be hidden. If "hidden", component will be visually
hidden and not take up space in the layout but still exist in the DOM
s... | Initialization | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
es
provided during constructor.
webcam_options: WebcamOptions | None
default `= None`
placeholder: str | None
default `= None`
Custom text for the upload area. Overrides default upload messages when
provided. Accepts new lines and `` to designate a heading.
watermark: ... | Initialization | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
Shortcuts
gradio.Image
Interface String Shortcut `"image"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
The `type` parameter controls the format of the data passed to your Python
function. Choosing the right type avoids unnecessary conversions in your code:
`type`| Your function receives| Shape / Format| Best for
---|---|---|---
`"numpy"` (default)| `numpy.ndarray`| `(height, width, 3)`, dtype `uint8`,
values 0–255|... | Understanding Image Types | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
The `gr.Image` component can process or display any image format that is
[supported by the PIL
library](https://pillow.readthedocs.io/en/stable/handbook/image-file-
formats.html), including animated GIFs. In addition, it also supports the SVG
image format.
When the `gr.Image` component is used as an input component, t... | `GIF` and `SVG` Image Formats | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
sepia_filterfake_diffusion
| Demos | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Image component supports the following ... | Event Listeners | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
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.
inputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List o... | Event Listeners | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
animation at all
show_progress_on: Component | list[Component] | None
default `= None`
Component or list of components to show the progress animation on. If None,
will show the progress animation on all of the output components.
queue: bool
default `= True`
If True, will place the r... | Event Listeners | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
n (or generators that are iterating) will be cancelled, but
functions that are currently running will be allowed to finish.
trigger_mode: Literal['once', 'multiple', 'always_last'] | None
default `= None`
If "once" (default for all events except `.change()`) would not allow any
submissions while an ev... | Event Listeners | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
nd via gr.load). If fn is None,
api_visibility will automatically be set to "private".
time_limit: int | None
default `= None`
stream_every: float
default `= 0.5`
key: int | str | tuple[int | str, ...] | None
default `= None`
A unique key for this event listener to be... | Event Listeners | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
Helper Classes | https://gradio.app/docs/gradio/image | Gradio - Image Docs | |
gradio.WebcamOptions(···)
Description
A dataclass for specifying options for the webcam tool in the ImageEditor
component. An instance of this class can be passed to the `webcam_options`
parameter of `gr.ImageEditor`.
Initialization
Parameters ▼
mirror: bool
default `= True`
If True, the webcam wi... | Webcam Options | https://gradio.app/docs/gradio/image | Gradio - Image Docs |
Mount a gradio.Blocks to an existing FastAPI application.
| Description | https://gradio.app/docs/gradio/mount_gradio_app | Gradio - Mount_Gradio_App Docs |
from fastapi import FastAPI
import gradio as gr
app = FastAPI()
@app.get("/")
def read_main():
return {"message": "This is your main app"}
io = gr.Interface(lambda x: "Hello, " + x + "!", "textbox", "textbox")
app = gr.mount_gradio_app(app, io, path="/gradio")
Then run `uvicorn run:app`... | Example Usage | https://gradio.app/docs/gradio/mount_gradio_app | Gradio - Mount_Gradio_App Docs |
Parameters ▼
app: fastapi.FastAPI
The parent FastAPI application.
blocks: gradio.Blocks
The blocks object we want to mount to the parent app.
path: str
The path at which the gradio application will be mounted, e.g. "/gradio".
server_name: str
default `... | Initialization | https://gradio.app/docs/gradio/mount_gradio_app | Gradio - Mount_Gradio_App Docs |
ic request, that user is not
authorized to access the gradio app (they will see a 401 Unauthorized
response). To be used with external authentication systems like OAuth. Cannot
be used with `auth`.
root_path: str | None
default `= None`
The subpath corresponding to the public deployment of this FastAP... | Initialization | https://gradio.app/docs/gradio/mount_gradio_app | Gradio - Mount_Gradio_App Docs |
browser console log. Otherwise, errors will only be visible in
the terminal session running the Gradio app.
max_file_size: str | int | None
default `= None`
The maximum file size in bytes that can be uploaded. Can be a string of the
form "<value><unit>", where value is any positive integer and unit is... | Initialization | https://gradio.app/docs/gradio/mount_gradio_app | Gradio - Mount_Gradio_App Docs |
or will attempt to
load a theme from the Hugging Face Hub (e.g. "gradio/monochrome"). If None,
will use the Default theme.
css: str | None
default `= None`
Custom css as a code string. This css will be included in the demo webpage.
css_paths: str | Path | list[str | Path] | None
defa... | Initialization | https://gradio.app/docs/gradio/mount_gradio_app | Gradio - Mount_Gradio_App Docs |
Creates a checkbox that can be set to `True` or `False`. Can be used as an
input to pass a boolean value to a function or as an output to display a
boolean value.
| Description | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
**Using Checkbox as an input component.**
How Checkbox will pass its value to your function:
Type: `bool | None`
Passes the status of the checkbox as a `bool`.
Example Code
import gradio as gr
def predict(
value: bool | None
):
process value f... | Behavior | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
Parameters ▼
value: bool | Callable
default `= False`
if True, checked by default. If a function is provided, the function will be
called each time the app loads to set the initial value of this component.
label: str | I18nData | None
default `= None`
the label for this checkbox, dis... | Initialization | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
ue results in this Component being narrower than
min_width, the min_width parameter will be respected first.
interactive: bool | None
default `= None`
if True, this checkbox can be checked; if False, checking will be disabled. If
not provided, this is inferred based on whether the component is used as... | Initialization | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
ues
provided during constructor.
buttons: list[Button] | None
default `= None`
A list of gr.Button() instances to show in the top right corner of the
component. Custom buttons will appear in the toolbar with their configured
icon and/or label, and clicking them will trigger any .click() events
registe... | Initialization | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
Shortcuts
gradio.Checkbox
Interface String Shortcut `"checkbox"`
Initialization Uses default values
| Shortcuts | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
sentence_builderhello_world_3
| Demos | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
Description
Event listeners allow you to respond to user interactions with the UI
components you've defined in a Gradio Blocks app. When a user interacts with
an element, such as changing a slider value or uploading an image, a function
is called.
Supported Event Listeners
The Checkbox component supports the followi... | Event Listeners | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
of gradio.components to use as inputs. If the function takes no inputs,
this should be an empty list.
outputs: Component | BlockContext | list[Component | BlockContext] | Set[Component | BlockContext] | None
default `= None`
List of gradio.components to use as outputs. If the function returns no
outp... | Event Listeners | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
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.
batch: bool
default `= False`
If True, then the function should process a batch of inputs, meaning that it
sh... | Event Listeners | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
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.
js: str | Literal[True] | None
default `= None`
Optional frontend js method t... | Event Listeners | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
be used in @gr.render(). If set, this
value identifies an event as identical across re-renders when the key is
identical.
validator: Callable | None
default `= None`
Optional validation function to run before the main function. If provided,
this function will be executed first with queue=False, and on... | Event Listeners | https://gradio.app/docs/gradio/checkbox | Gradio - Checkbox Docs |
The gr.UndoData class is a subclass of gr.Event data that specifically
carries information about the `.undo()` event. When gr.UndoData is added as a
type hint to an argument of an event listener method, a gr.UndoData object
will automatically be passed as the value of that argument. The attributes of
this object contai... | Description | https://gradio.app/docs/gradio/undodata | Gradio - Undodata Docs |
import gradio as gr
def undo(retry_data: gr.UndoData, history: list[gr.MessageDict]):
history_up_to_retry = history[:retry_data.index]
return history_up_to_retry
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
chatbot.undo(undo, chatbot, chatbot)
demo.launch()
| Example Usage | https://gradio.app/docs/gradio/undodata | Gradio - Undodata Docs |
Parameters ▼
index: int | tuple[int, int]
The index of the user message that should be undone.
value: Any
The value of the user message that should be undone.
| Attributes | https://gradio.app/docs/gradio/undodata | Gradio - Undodata Docs |
The FileData class is a subclass of the GradioModel class that represents a
file object within a Gradio interface. It is used to store file data and
metadata when a file is uploaded.
| Description | https://gradio.app/docs/gradio/filedata | Gradio - Filedata Docs |
from gradio_client import Client, FileData, handle_file
def get_url_on_server(data: FileData):
print(data['url'])
client = Client("gradio/gif_maker_main", download_files=False)
job = client.submit([handle_file("./cheetah.jpg")], api_name="/predict")
data = job.result()
video: FileD... | Example Usage | https://gradio.app/docs/gradio/filedata | Gradio - Filedata Docs |
Parameters ▼
path: str
The server file path where the file is stored.
url: Optional[str]
The normalized server URL pointing to the file.
size: Optional[int]
The size of the file in bytes.
orig_name: Optional[str]
The original filename before upload.
... | Attributes | https://gradio.app/docs/gradio/filedata | Gradio - Filedata Docs |
Thread-safe cache with manual get/set control, injected as a function
parameter (add as a default parameter value and Gradio will inject it
automatically). Supports per-session isolation so cached data doesn't leak
between users, content-aware hashing for ML types (numpy, PIL, pandas), and
LRU eviction with memory limi... | Description | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
import gradio as gr
def generate(prompt, c=gr.Cache(per_session=True)):
hit = c.get(prompt)
if hit is not None:
return hit["result"]
result = llm(prompt)
c.set(prompt, result=result)
return result
| Example Usage | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
Parameters ▼
max_size: int
default `= 128`
max_memory: str | int | None
default `= None`
per_session: bool
default `= False`
| Initialization | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
Methods | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs | |
%20Copyright%202022%20Fonticons,%20Inc.... | get | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20... | get | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
%20Copyright%202022%20Fonticons,%20Inc.... | set | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
3e%3c!--!%20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%2039... | set | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
%20Copyright%202022%20Fonticons,%20Inc.... | keys | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
20Font%20Awesome%20Pro%206.0.0%20by%20@fontawesome%20-%20https://fontawesome.com%20License%20-%20https://fontawesome.com/license%20\(Commercial%20License\)%20Copyright%202022%20Fonticons,%20Inc.%20--%3e%3cpath%20d='M172.5%20131.1C228.1%2075.51%20320.5%2075.51%20376.1%20131.1C426.1%20181.1%20433.5%20260.8%20392.4%20318.... | keys | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
%20Copyright%202022%20Fonticons,%20Inc.... | clear | https://gradio.app/docs/gradio/cache-class | Gradio - Cache Class Docs |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.