Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -5,7 +5,7 @@ emoji: 🔥
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
-
sdk_version: 6.
|
| 9 |
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
hf_oauth: true
|
|
|
|
| 5 |
colorFrom: indigo
|
| 6 |
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
+
sdk_version: 6.2.0
|
| 9 |
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
hf_oauth: true
|
run.ipynb
CHANGED
|
@@ -1 +1 @@
|
|
| 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", "def get_file_content(file):\n", "
|
|
|
|
| 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", "def get_file_content(file):\n", " if file is None or Path(file).is_dir():\n", " return None\n", " return Path(file).read_text()\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/*.py\",\n", " root_dir=absolute_path,\n", " ignore_glob=\"**/__init__.py\",\n", " )\n", "\n", " file2 = gr.FileExplorer(\n", " glob=\"**/components/*.py\",\n", " root_dir=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.Row():\n", " file_3 = gr.FileExplorer(\n", " scale=1,\n", " glob=\"**/components/*.py\",\n", " value=[\"components/file_explorer.py\"],\n", " file_count=\"single\",\n", " root_dir=absolute_path,\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", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
CHANGED
|
@@ -6,7 +6,9 @@ relative_path = "path/to/file"
|
|
| 6 |
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()
|
| 7 |
|
| 8 |
def get_file_content(file):
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
with gr.Blocks() as demo:
|
| 12 |
gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')
|
|
@@ -14,13 +16,12 @@ with gr.Blocks() as demo:
|
|
| 14 |
with gr.Row():
|
| 15 |
file = gr.FileExplorer(
|
| 16 |
glob="**/components/*.py",
|
| 17 |
-
# value=["themes/utils"],
|
| 18 |
root_dir=absolute_path,
|
| 19 |
ignore_glob="**/__init__.py",
|
| 20 |
)
|
| 21 |
|
| 22 |
file2 = gr.FileExplorer(
|
| 23 |
-
glob="**/components/*
|
| 24 |
root_dir=absolute_path,
|
| 25 |
ignore_glob="**/__init__.py",
|
| 26 |
)
|
|
@@ -28,19 +29,16 @@ with gr.Blocks() as demo:
|
|
| 28 |
|
| 29 |
gr.Markdown("---")
|
| 30 |
gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`')
|
| 31 |
-
with gr.
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
)
|
| 42 |
-
|
| 43 |
-
code = gr.Code(lines=30, scale=2, language="python")
|
| 44 |
|
| 45 |
file_3.change(get_file_content, file_3, code)
|
| 46 |
|
|
|
|
| 6 |
absolute_path = (current_file_path.parent / ".." / ".." / "gradio").resolve()
|
| 7 |
|
| 8 |
def get_file_content(file):
|
| 9 |
+
if file is None or Path(file).is_dir():
|
| 10 |
+
return None
|
| 11 |
+
return Path(file).read_text()
|
| 12 |
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
gr.Markdown('### `FileExplorer` to `FileExplorer` -- `file_count="multiple"`')
|
|
|
|
| 16 |
with gr.Row():
|
| 17 |
file = gr.FileExplorer(
|
| 18 |
glob="**/components/*.py",
|
|
|
|
| 19 |
root_dir=absolute_path,
|
| 20 |
ignore_glob="**/__init__.py",
|
| 21 |
)
|
| 22 |
|
| 23 |
file2 = gr.FileExplorer(
|
| 24 |
+
glob="**/components/*.py",
|
| 25 |
root_dir=absolute_path,
|
| 26 |
ignore_glob="**/__init__.py",
|
| 27 |
)
|
|
|
|
| 29 |
|
| 30 |
gr.Markdown("---")
|
| 31 |
gr.Markdown('### `FileExplorer` to `Code` -- `file_count="single"`')
|
| 32 |
+
with gr.Row():
|
| 33 |
+
file_3 = gr.FileExplorer(
|
| 34 |
+
scale=1,
|
| 35 |
+
glob="**/components/*.py",
|
| 36 |
+
value=["components/file_explorer.py"],
|
| 37 |
+
file_count="single",
|
| 38 |
+
root_dir=absolute_path,
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
code = gr.Code(lines=30, scale=2, language="python")
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
file_3.change(get_file_content, file_3, code)
|
| 44 |
|