Spaces:
Build error
Build error
Commit 3: Add 6 file(s)
Browse files- demos/zip_files/run.ipynb +1 -0
- demos/zip_files/run.py +22 -0
- demos/zip_files/screenshot.png +0 -0
- image.png +0 -0
- requirements.txt +7 -0
- run.py +46 -0
demos/zip_files/run.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: zip_files"]}, {"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": ["from zipfile import ZipFile\n", "\n", "import gradio as gr\n", "\n", "def zip_files(files):\n", " with ZipFile(\"tmp.zip\", \"w\") as zip_obj:\n", " for file in files:\n", " zip_obj.write(file.name, file.name.split(\"/\")[-1])\n", " return \"tmp.zip\"\n", "\n", "demo = gr.Interface(\n", " zip_files,\n", " gr.File(file_count=\"multiple\", file_types=[\"text\", \".json\", \".csv\"]),\n", " \"file\",\n", " examples=[[[gr.get_file(\"titanic.csv\"),\n", " gr.get_file(\"titanic.csv\"),\n", " gr.get_file(\"titanic.csv\")]]],\n", " cache_examples=True\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
demos/zip_files/run.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from zipfile import ZipFile
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
def zip_files(files):
|
| 6 |
+
with ZipFile("tmp.zip", "w") as zip_obj:
|
| 7 |
+
for file in files:
|
| 8 |
+
zip_obj.write(file.name, file.name.split("/")[-1])
|
| 9 |
+
return "tmp.zip"
|
| 10 |
+
|
| 11 |
+
demo = gr.Interface(
|
| 12 |
+
zip_files,
|
| 13 |
+
gr.File(file_count="multiple", file_types=["text", ".json", ".csv"]),
|
| 14 |
+
"file",
|
| 15 |
+
examples=[[[gr.get_file("titanic.csv"),
|
| 16 |
+
gr.get_file("titanic.csv"),
|
| 17 |
+
gr.get_file("titanic.csv")]]],
|
| 18 |
+
cache_examples=True
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
demo.launch()
|
demos/zip_files/screenshot.png
ADDED
|
image.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@2aac99e453531e57dff0cb3f0c75ff28b5a7975a#subdirectory=client/python
|
| 2 |
+
https://gradio-pypi-previews.s3.amazonaws.com/2aac99e453531e57dff0cb3f0c75ff28b5a7975a/gradio-5.49.1-py3-none-any.whl
|
| 3 |
+
pypistats==1.1.0
|
| 4 |
+
plotly
|
| 5 |
+
matplotlib
|
| 6 |
+
altair
|
| 7 |
+
vega_datasets
|
run.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import copy
|
| 6 |
+
import pathlib
|
| 7 |
+
from gradio.media import MEDIA_ROOT
|
| 8 |
+
|
| 9 |
+
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
| 10 |
+
|
| 11 |
+
demo_dir = pathlib.Path(__file__).parent / "demos"
|
| 12 |
+
|
| 13 |
+
names = sorted(os.listdir("./demos"))
|
| 14 |
+
|
| 15 |
+
all_demos = []
|
| 16 |
+
demo_module = None
|
| 17 |
+
for p in sorted(os.listdir("./demos")):
|
| 18 |
+
old_path = copy.deepcopy(sys.path)
|
| 19 |
+
sys.path = [os.path.join(demo_dir, p)] + sys.path
|
| 20 |
+
try: # Some demos may not be runnable because of 429 timeouts, etc.
|
| 21 |
+
if demo_module is None:
|
| 22 |
+
demo_module = importlib.import_module("run")
|
| 23 |
+
else:
|
| 24 |
+
demo_module = importlib.reload(demo_module)
|
| 25 |
+
all_demos.append((p, demo_module.demo, False)) # type: ignore
|
| 26 |
+
except Exception as e:
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown(f"Error loading demo: {e}")
|
| 29 |
+
all_demos.append((p, demo, True))
|
| 30 |
+
|
| 31 |
+
app = gr.Blocks()
|
| 32 |
+
|
| 33 |
+
with app:
|
| 34 |
+
gr.Markdown("""
|
| 35 |
+
# Deployed Demos
|
| 36 |
+
## Click through demos to test them out!
|
| 37 |
+
""")
|
| 38 |
+
|
| 39 |
+
for demo_name, demo, _ in all_demos:
|
| 40 |
+
with app.route(demo_name):
|
| 41 |
+
demo.render()
|
| 42 |
+
|
| 43 |
+
# app = gr.mount_gradio_app(app, demo, f"/demo/{demo_name}")
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
app.launch(allowed_paths=[str(MEDIA_ROOT)])
|