-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add component <-> server direct communication support, as well as a "…
…file explorer" component (#5672) * changes * changes * add changeset * add changeset * Server fns ext (#5760) * start changes * changes * changes * fix arrows * add changeset * rename demo * fix some ci * add changeset * add changeset * fix * remove configs * fix * fix * add changeset * fixes * linting * Update gradio/components/file_explorer.py * notebook * typing * tweaks * fixed class method problem * fix test * file explorer * gr.load * format * tweaks * fix * fix * fix * fix * final tweaks + changelog * changelog * changelog * changelog * lint --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: pngwn <hello@pngwn.io> Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
- Loading branch information
1 parent
caeee8b
commit e4a307e
Showing
40 changed files
with
1,460 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
"@gradio/app": minor | ||
"@gradio/client": minor | ||
"@gradio/file": minor | ||
"@gradio/fileexplorer": minor | ||
"@gradio/theme": minor | ||
"gradio": minor | ||
"gradio_client": minor | ||
--- | ||
|
||
highlight: | ||
|
||
#### new `FileExplorer` component | ||
|
||
Thanks to a new capability that allows components to communicate directly with the server _without_ passing data via the value, we have created a new `FileExplorer` component. | ||
|
||
This component allows you to populate the explorer by passing a glob, but only provides the selected file(s) in your prediction function. | ||
|
||
Users can then navigate the virtual filesystem and select files which will be accessible in your predict function. This component will allow developers to build more complex spaces, with more flexible input options. | ||
|
||
 | ||
|
||
For more information check the [`FileExplorer` documentation](https://gradio.app/docs/fileexplorer). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: file_explorer"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "current_file_path = Path(__file__).resolve()\n", "relative_path = \"path/to/file\"\n", "absolute_path = (current_file_path.parent / \"..\" / \"..\" / \"gradio\").resolve()\n", "\n", "\n", "def get_file_content(file):\n", " return (file,)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count=\"multiple\"`')\n", " submit_btn = gr.Button(\"Select\")\n", " with gr.Row():\n", " file = gr.FileExplorer(\n", " glob=\"**/{components,themes}/*.py\",\n", " # value=[\"themes/utils\"],\n", " root=absolute_path,\n", " ignore_glob=\"**/__init__.py\",\n", " )\n", "\n", " file2 = gr.FileExplorer(\n", " glob=\"**/{components,themes}/**/*.py\",\n", " root=absolute_path,\n", " ignore_glob=\"**/__init__.py\",\n", " )\n", " submit_btn.click(lambda x: x, file, file2)\n", "\n", " gr.Markdown(\"---\")\n", " gr.Markdown('### `FileExplorer` to `Code` -- `file_count=\"single\"`')\n", " with gr.Group():\n", " with gr.Row():\n", " file_3 = gr.FileExplorer(\n", " scale=1,\n", " glob=\"**/{components,themes}/**/*.py\",\n", " value=[\"themes/utils\"],\n", " file_count=\"single\",\n", " root=absolute_path,\n", " ignore_glob=\"**/__init__.py\",\n", " elem_id=\"file\",\n", " )\n", "\n", " code = gr.Code(lines=30, scale=2, language=\"python\")\n", "\n", " file_3.change(get_file_content, file_3, code)\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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,themes}/*.py", | ||
# value=["themes/utils"], | ||
root=absolute_path, | ||
ignore_glob="**/__init__.py", | ||
) | ||
|
||
file2 = gr.FileExplorer( | ||
glob="**/{components,themes}/**/*.py", | ||
root=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,themes}/**/*.py", | ||
value=["themes/utils"], | ||
file_count="single", | ||
root=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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
Dropdown, | ||
DuplicateButton, | ||
File, | ||
FileExplorer, | ||
Gallery, | ||
Highlight, | ||
HighlightedText, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.