aliabd HF Staff commited on
Commit
30593ba
·
1 Parent(s): 212b601

Upload folder using huggingface_hub

Browse files
dir3/dir3_foo.txt ADDED
File without changes
dir3/dir4/dir5/dir5_foo.txt ADDED
File without changes
dir3/dir4/dir7/dir7_foo.txt ADDED
File without changes
dir3/dir4/dir_4_foo.txt ADDED
File without changes
requirements.txt CHANGED
@@ -1 +1 @@
1
- https://gradio-builds.s3.amazonaws.com/6a9151d5c9432c724098da7d88a539aaaf5ffe88/gradio-4.8.0-py3-none-any.whl
 
1
+ https://gradio-builds.s3.amazonaws.com/c9673cacd6470296ee01d7717e2080986e750572/gradio-4.8.0-py3-none-any.whl
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: file_explorer_component_events"]}, {"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": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('dir1')\n", "!wget -q -O dir1/bar.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/bar.txt\n", "!wget -q -O dir1/foo.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/foo.txt\n", "os.mkdir('dir2')\n", "!wget -q -O dir2/baz.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/baz.png\n", "!wget -q -O dir2/foo.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/foo.png"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "base_root = Path(__file__).parent.resolve()\n", "\n", "with gr.Blocks() as demo:\n", " dd = gr.Dropdown(\n", " label=\"Select File Explorer Root\",\n", " value=str(base_root / \"dir1\"),\n", " choices=[str(base_root / \"dir1\"), str(base_root / \"dir2\")],\n", " )\n", " fe = gr.FileExplorer(root=str(base_root / \"dir1\"), interactive=True)\n", " dd.select(lambda s: gr.FileExplorer(root=s), inputs=[dd], outputs=[fe])\n", "\n", " with gr.Row():\n", " a = gr.Textbox(elem_id=\"input-box\")\n", " a.change(lambda x: x, inputs=[a])\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: file_explorer_component_events"]}, {"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": ["# Downloading files from the demo repo\n", "import os\n", "os.mkdir('dir1')\n", "!wget -q -O dir1/bar.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/bar.txt\n", "!wget -q -O dir1/foo.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir1/foo.txt\n", "os.mkdir('dir2')\n", "!wget -q -O dir2/baz.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/baz.png\n", "!wget -q -O dir2/foo.png https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir2/foo.png\n", "os.mkdir('dir3')\n", "!wget -q -O dir3/dir3_foo.txt https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir3_foo.txt\n", "!wget -q -O dir3/dir4 https://github.com/gradio-app/gradio/raw/main/demo/file_explorer_component_events/dir3/dir4"]}, {"cell_type": "code", "execution_count": null, "id": "44380577570523278879349135829904343037", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "from pathlib import Path\n", "\n", "base_root = Path(__file__).parent.resolve()\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " dd = gr.Dropdown(label=\"Select File Explorer Root\",\n", " value=str(base_root / \"dir1\"),\n", " choices=[str(base_root / \"dir1\"), str(base_root / \"dir2\"),\n", " str(base_root / \"dir3\")])\n", " with gr.Group():\n", " dir_only_glob = gr.Checkbox(label=\"Show only directories\", value=False)\n", " ignore_dir_in_glob = gr.Checkbox(label=\"Ignore directories in glob\", value=False)\n", "\n", " fe = gr.FileExplorer(root=str(base_root / \"dir1\"),\n", " glob=\"**/*\", interactive=True)\n", " textbox = gr.Textbox(label=\"Selected Directory\")\n", " run = gr.Button(\"Run\")\n", " \n", " dir_only_glob.select(lambda s: gr.FileExplorer(glob=\"**/\" if s else \"**/*.*\",\n", " file_count=\"multiple\",\n", " root=str(base_root / \"dir3\")) ,\n", " inputs=[dir_only_glob], outputs=[fe])\n", " ignore_dir_in_glob.select(lambda s: gr.FileExplorer(glob=\"**/*\",\n", " ignore_glob=\"**/\",\n", " root=str(base_root / \"dir3\")),\n", " inputs=[ignore_dir_in_glob], outputs=[fe]) \n", "\n", " dd.select(lambda s: gr.FileExplorer(root=s), inputs=[dd], outputs=[fe])\n", " run.click(lambda s: \",\".join(s) if isinstance(s, list) else s, inputs=[fe], outputs=[textbox])\n", "\n", " with gr.Row():\n", " a = gr.Textbox(elem_id=\"input-box\")\n", " a.change(lambda x: x, inputs=[a])\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -4,13 +4,31 @@ from pathlib import Path
4
  base_root = Path(__file__).parent.resolve()
5
 
6
  with gr.Blocks() as demo:
7
- dd = gr.Dropdown(
8
- label="Select File Explorer Root",
9
- value=str(base_root / "dir1"),
10
- choices=[str(base_root / "dir1"), str(base_root / "dir2")],
11
- )
12
- fe = gr.FileExplorer(root=str(base_root / "dir1"), interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  dd.select(lambda s: gr.FileExplorer(root=s), inputs=[dd], outputs=[fe])
 
14
 
15
  with gr.Row():
16
  a = gr.Textbox(elem_id="input-box")
 
4
  base_root = Path(__file__).parent.resolve()
5
 
6
  with gr.Blocks() as demo:
7
+ with gr.Row():
8
+ dd = gr.Dropdown(label="Select File Explorer Root",
9
+ value=str(base_root / "dir1"),
10
+ choices=[str(base_root / "dir1"), str(base_root / "dir2"),
11
+ str(base_root / "dir3")])
12
+ with gr.Group():
13
+ dir_only_glob = gr.Checkbox(label="Show only directories", value=False)
14
+ ignore_dir_in_glob = gr.Checkbox(label="Ignore directories in glob", value=False)
15
+
16
+ fe = gr.FileExplorer(root=str(base_root / "dir1"),
17
+ glob="**/*", interactive=True)
18
+ textbox = gr.Textbox(label="Selected Directory")
19
+ run = gr.Button("Run")
20
+
21
+ dir_only_glob.select(lambda s: gr.FileExplorer(glob="**/" if s else "**/*.*",
22
+ file_count="multiple",
23
+ root=str(base_root / "dir3")) ,
24
+ inputs=[dir_only_glob], outputs=[fe])
25
+ ignore_dir_in_glob.select(lambda s: gr.FileExplorer(glob="**/*",
26
+ ignore_glob="**/",
27
+ root=str(base_root / "dir3")),
28
+ inputs=[ignore_dir_in_glob], outputs=[fe])
29
+
30
  dd.select(lambda s: gr.FileExplorer(root=s), inputs=[dd], outputs=[fe])
31
+ run.click(lambda s: ",".join(s) if isinstance(s, list) else s, inputs=[fe], outputs=[textbox])
32
 
33
  with gr.Row():
34
  a = gr.Textbox(elem_id="input-box")