Introducing Gradio Clients
WatchIntroducing Gradio Clients
WatchNew to Gradio? Start here: Getting Started
See the Release History
gradio.JSON(···)
dict
or list
depending on the value.def predict(
value: dict | list | None
)
...
str
-- or a list
or dict
that can be serialized to a JSON string. The list
or dict
value can contain numpy arrays.def predict(···) -> dict | list | str | None
...
return value
Class | Interface String Shortcut | Initialization |
---|---|---|
| "json" | Uses default values |
from zipfile import ZipFile
import gradio as gr
def zip_to_json(file_obj):
files = []
with ZipFile(file_obj.name) as zfile:
for zinfo in zfile.infolist():
files.append(
{
"name": zinfo.filename,
"file_size": zinfo.file_size,
"compressed_size": zinfo.compress_size,
}
)
return files
demo = gr.Interface(zip_to_json, "file", "json")
if __name__ == "__main__":
demo.launch()
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.
The JSON component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below.
Listener | Description |
---|---|
| Triggered when the value of the JSON 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 |