Spaces:
Configuration error
Configuration error
PrimitiveAnythingCachedExamples / primitive_anything /michelangelo /utils /visualizers /html_util.py
Download primitive_anything/michelangelo/utils/visualizers/html_util.py from abidlabs/PrimitiveAnythingCachedExamples: direct link, hf CLI and curl.
- Browser
- Download file 886 Bytes
-
https://huggingface.co/spaces/abidlabs/PrimitiveAnythingCachedExamples/resolve/main/primitive_anything/michelangelo/utils/visualizers/html_util.py
- Command line
-
hf download hf://spaces/abidlabs/PrimitiveAnythingCachedExamples/primitive_anything/michelangelo/utils/visualizers/html_util.py
-
curl -L -o html_util.py https://huggingface.co/spaces/abidlabs/PrimitiveAnythingCachedExamples/resolve/main/primitive_anything/michelangelo/utils/visualizers/html_util.py
886 Bytes
| # -*- coding: utf-8 -*- | |
| import io | |
| import base64 | |
| import numpy as np | |
| from PIL import Image | |
| def to_html_frame(content): | |
| html_frame = f""" | |
| <html> | |
| <body> | |
| {content} | |
| </body> | |
| </html> | |
| """ | |
| return html_frame | |
| def to_single_row_table(caption: str, content: str): | |
| table_html = f""" | |
| <table border = "1"> | |
| <caption>{caption}</caption> | |
| <tr> | |
| <td>{content}</td> | |
| </tr> | |
| </table> | |
| """ | |
| return table_html | |
| def to_image_embed_tag(image: np.ndarray): | |
| # Convert np.ndarray to bytes | |
| img = Image.fromarray(image) | |
| raw_bytes = io.BytesIO() | |
| img.save(raw_bytes, "PNG") | |
| # Encode bytes to base64 | |
| image_base64 = base64.b64encode(raw_bytes.getvalue()).decode("utf-8") | |
| image_tag = f""" | |
| <img src="data:image/png;base64,{image_base64}" alt="Embedded Image"> | |
| """ | |
| return image_tag | |