Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 1,210 Bytes
13170f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | """EULA tab for Gradio demos.
Displays the End User License Agreement as a read-only Markdown tab.
The EULA text is loaded from ``shared/assets/EULA.md`` so it can be
updated without changing any Python code.
Usage::
with gr.Blocks() as demo:
with gr.Tabs():
build_eula_tab()
"""
from pathlib import Path
import gradio as gr
_ASSETS_DIR = Path(__file__).resolve().parent / "assets"
_DEFAULT_EULA_PATH = _ASSETS_DIR / "EULA.md"
def build_eula_tab(
eula_path: str | Path | None = None,
tab_label: str = "EULA",
) -> gr.TabItem:
"""Create a tab displaying the EULA as Markdown.
Must be called inside a ``gr.Tabs()`` context.
Args:
eula_path: Path to a Markdown file. Defaults to ``shared/assets/EULA.md``.
tab_label: Label shown on the tab. Defaults to ``"EULA"``.
Returns:
The ``gr.TabItem`` component.
"""
path = Path(eula_path) if eula_path is not None else _DEFAULT_EULA_PATH
if path.is_file():
content = path.read_text(encoding="utf-8")
else:
content = f"_EULA file not found. Expected location:_ `{path}`"
with gr.TabItem(tab_label) as tab:
gr.Markdown(content)
return tab
|