From b1eaf5886756eea7a5c03af5c395fde65d3c59e2 Mon Sep 17 00:00:00 2001 From: Pete Blois Date: Fri, 2 Feb 2024 14:27:23 -0800 Subject: [PATCH] No public description PiperOrigin-RevId: 603788112 --- google/colab/_reprs.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/google/colab/_reprs.py b/google/colab/_reprs.py index 4b9f5901..e96321bf 100644 --- a/google/colab/_reprs.py +++ b/google/colab/_reprs.py @@ -5,6 +5,7 @@ import io import json import types +import uuid import warnings from google.colab import _inspector # pytype: disable=import-error @@ -359,8 +360,42 @@ def _image_repr(ndarray: np.ndarray): encoded = base64.b64encode(buffered.getvalue()).decode('utf-8') uri = 'data:image/png;base64,' + encoded - result = f'
ndarray shape: {ndarray.shape} dtype: {ndarray.dtype}
' - result += f'' + result = """ + """ + html_id = f'id-{uuid.uuid4()}' + result += f'
' + + result += f'
ndarray {ndarray.shape} show data
' + result += f'' + + result += ( + f'
{html.escape(ndarray.__repr__())}
' + ) + result += '
' + + result += f"""""" return result except Exception: # pylint: disable=broad-except return None