Introducing Gradio Clients
WatchIntroducing Gradio Clients
WatchNew to Gradio? Start here: Getting Started
See the Release History
To install Gradio from main, run the following command:
pip install https://gradio-builds.s3.amazonaws.com/02798ec170be7c9e8756dec24ef29c7f46fe2060/gradio-4.41.0-py3-none-any.whl
*Note: Setting share=True
in
launch()
will not work.
gradio.FileExplorer(···)
str
path (relative to root
) or list[str}
depending on file_count
def predict(
value: list[str] | str | None
)
...
str
path to a file, or list[str]
consisting of paths to files.def predict(···) -> str | list[str] | None
...
return value
Class | Interface String Shortcut | Initialization |
---|---|---|
| "fileexplorer" | Uses default values |
import gradio as gr
from pathlib import Path
current_file_path = Path(__file__).resolve()
relative_path = "path/to/file"
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()
def get_file_content(file):
return (file,)
with gr.Blocks() as demo:
gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')
submit_btn = gr.Button("Select")
with gr.Row():
file = gr.FileExplorer(
glob="**/components/*.py",
# value=["themes/utils"],
root_dir=absolute_path,
ignore_glob="**/__init__.py",
)
file2 = gr.FileExplorer(
glob="**/components/**/*.py",
root_dir=absolute_path,
ignore_glob="**/__init__.py",
)
submit_btn.click(lambda x: x, file, file2)
gr.Markdown("---")
gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`')
with gr.Group():
with gr.Row():
file_3 = gr.FileExplorer(
scale=1,
glob="**/components/**/*.py",
value=["themes/utils"],
file_count="single",
root_dir=absolute_path,
ignore_glob="**/__init__.py",
elem_id="file",
)
code = gr.Code(lines=30, scale=2, language="python")
file_3.change(get_file_content, file_3, code)
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 FileExplorer component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below.
Listener | Description |
---|---|
|