Download minigpt2/lib/python3.10/site-packages/ray/widgets/render.py from ZTWHHH/envs_2: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/ZTWHHH/envs_2/resolve/main/minigpt2/lib/python3.10/site-packages/ray/widgets/render.py
- Command line
-
hf download hf://datasets/ZTWHHH/envs_2/minigpt2/lib/python3.10/site-packages/ray/widgets/render.py
-
curl -L -o render.py https://huggingface.co/datasets/ZTWHHH/envs_2/resolve/main/minigpt2/lib/python3.10/site-packages/ray/widgets/render.py
1.23 kB
| import pathlib | |
| from typing import List | |
| from ray.util.annotations import DeveloperAPI | |
| class Template: | |
| """Class which provides basic HTML templating.""" | |
| def __init__(self, file: str): | |
| with open(pathlib.Path(__file__).parent / "templates" / file, "r") as f: | |
| self.template = f.read() | |
| def render(self, **kwargs) -> str: | |
| """Render an HTML template with the given data. | |
| This is done by replacing instances of `{{ key }}` with `value` | |
| from the keyword arguments. | |
| Returns: | |
| HTML template with the keys of the kwargs replaced with corresponding | |
| values. | |
| """ | |
| rendered = self.template | |
| for key, value in kwargs.items(): | |
| if isinstance(value, List): | |
| value = "".join(value) | |
| rendered = rendered.replace("{{ " + key + " }}", value if value else "") | |
| return rendered | |
| def list_templates() -> List[pathlib.Path]: | |
| """List the available HTML templates. | |
| Returns: | |
| A list of files with .html.j2 extensions inside ../templates/ | |
| """ | |
| return (pathlib.Path(__file__).parent / "templates").glob("*.html.j2") | |