googlecolab / colabtools

Python libraries for Google Colaboratory
Apache License 2.0
2.13k stars 696 forks source link

Image Attachments #3836

Open pbeens opened 1 year ago

pbeens commented 1 year ago

Colab is clunky when adding images

Colab is kinda clunky when adding images to Markdown, looking like this:

![image-name.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4wAAAHCCAYAAACkB0eXAAAAAXNSR0IArs4c6QAAIABJREFUeF7s3QmcjdXjx/HvzNjGvktEpT0<snip>

Callysto (https://hub.callysto.ca/) has a nice solution where the inserted image looks like this:

![image-name.png](attachment:image-name.png)

Couldn't this be done in Colab?

EvanWiederspan commented 1 year ago

Thanks for filing, tracking internally as b/291092682

MohamedHaarishSherieff commented 6 months ago

Colab is clunky when adding images

Colab is kinda clunky when adding images to Markdown, looking like this:

![image-name.png](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4wAAAHCCAYAAACkB0eXAAAAAXNSR0IArs4c6QAAIABJREFUeF7s3QmcjdXjx/HvzNjGvktEpT0<snip>

Callysto (https://hub.callysto.ca/) has a nice solution where the inserted image looks like this:

![image-name.png](attachment:image-name.png)

Couldn't this be done in Colab?

did you get the solution?

seppestas commented 1 month ago

I'm also interested in this.

Note that Google Colab does not even rendering "markdown attachments" of existing documents. This is a feature of Jupyter notebooks added in version 5.0. It is not a feature of Callysto.

E.g. when using VSCode to modify a Jupyter notebook stored on Google Drive, it also by default inserts images as cell attachments. These do not get rendered in Google Colab. image

It looks like Google Colab uses jupyter_core 5.7, so I expected this to be supported, and as @pbeens mentioned, to be the default behaviour. Anything but the smallest image results in a massive base64 texts, and I had even relatively small screenshots crash Google Colab...

!jupyter --version

Selected Jupyter core packages...
IPython          : 7.34.0
ipykernel        : 5.5.6
ipywidgets       : 7.7.1
jupyter_client   : 6.1.12
jupyter_core     : 5.7.2
jupyter_server   : 1.24.0
jupyterlab       : not installed
nbclient         : 0.10.0
nbconvert        : 6.5.4
nbformat         : 5.10.4
notebook         : 6.5.5
qtconsole        : not installed
traitlets        : 5.7.1
seppestas commented 1 month ago

Even more problematic is that Google Colab breaks attached images added by other editors like VSCode Jupyter and Jupyter lab.

Both the VSCode Jupyter plugin and Jupyter lab by default add pasted images as attachments. Jupyter hub also adds dragged and dropped images as attachments. The VSCode plugin allows adding pasted images as "markdown images" using paste options, i.e. adding them as an image file next to the notebook in the FS and create a markdown image with a relative path pointing to the image, which seems to be the default behaviour on drag-and-drop (though a new copy of the image file will be created).

As soon as the notebook is edited in Google Colab, any attached images break, it looks like Google Colab just removes the "attachments" field of all cells.

In VSCode: image

In Jupyter Lab: image

{
 "cells": [
...
  {
   "cell_type": "markdown",
   "metadata": {
    "editable": true,
    "id": "H5--hJrjIsn3",
    "tags": []
   },
   "source": [
    "Image pasted in Google Colab\n",
    "\n",
    "![image.png](data:image/png;base64,iVBO...gg==)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "zaZ1LttVIrVk"
   },
   "source": [
    "Image pasted in VSCode Jupyter as attachement\n",
    "\n",
    "![image.png](attachment:image.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "KZOuTNg8ReDJ"
   },
   "source": [
    "Image pasted in VSCode Jupyter as markdown image\n",
    "\n",
    "![alt text](image-1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "-CCzaXbwReDJ"
   },
   "source": [
    "Image pasted in JupyterLab\n",
    "\n",
    "![image.png](attachment:8ffe6187-8bba-47b7-81ae-926c74fa1e9a.png)\n"
   ]
  },
...
}

The "markdown images" also do not work in Google Colab.

image

On top of that, pasting in large images causes Google Colab to hang, not to mention the rather painful user experience of dealing with massive base64 encoded images.