From 5262a4a8f9280966368d0c899397d63784bc405e Mon Sep 17 00:00:00 2001 From: freddyaboulton Date: Tue, 5 Mar 2024 19:38:02 -0500 Subject: [PATCH] Add documentation --- client/python/gradio_client/documentation.py | 1 + gradio/data_classes.py | 28 ++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/client/python/gradio_client/documentation.py b/client/python/gradio_client/documentation.py index 17d505491f753..f95ba492f21d8 100644 --- a/client/python/gradio_client/documentation.py +++ b/client/python/gradio_client/documentation.py @@ -57,6 +57,7 @@ def extract_instance_attr_doc(cls, attr): ("gradio.route", "routes"), ("gradio.theme", "themes"), ("gradio_client.", "py-client"), + ("gradio.data_classes", "helpers"), ] diff --git a/gradio/data_classes.py b/gradio/data_classes.py index c8cce10806458..e98934c1a3610 100644 --- a/gradio/data_classes.py +++ b/gradio/data_classes.py @@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Any, List, Optional, Union from fastapi import Request +from gradio_client.documentation import document from gradio_client.utils import traverse from . import wasm_utils @@ -212,7 +213,34 @@ def __iter__(self): return iter(self.root) +@document() class StaticFiles: + """ + Static files to be served by the gradio app. + + Static files are not moved to the gradio cache and are served directly from the file system. + This class is useful when you want to serve files that you know will not be modified during the lifetime of the gradio app (like examples). + By using StaticFilesm your app will launch faster and it will consume less disk space. + + Example: + import gradio as gr + + # Paths can be a list of strings or pathlib.Path objects + # corresponding to filenames or directories. + gr.StaticFiles(paths=["test/test_files/"]) + + # The example files and the default value of the input + # will not be copied to the gradio cache and will be served directly. + demo = gr.Interface( + lambda s: s.rotate(45), + gr.Image(value="test/test_files/cheetah1.jpg", type="pil"), + gr.Image(), + examples=["test/test_files/bus.png"], + ) + + demo.launch() + """ + all_paths = [] def __init__(self, paths: list[str | pathlib.Path]) -> None: