Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
| """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 | |