Removed support for "show" function (PIL package) in Data Analysis?

I am using some code base that uses the Python Image Library (PIL) to create and show images to the User, both in ChatGPT and as part of Custom GPTs I am building.

This worked perfectly in ChatGPT (with Advanced data analysis tool) until yesterday. As of today, it stopped visualizing images. Everything else works, it just stopped showing the images in the chat.

Example with Matplotlib

Matplotlib still works correctly (an image is shown; this is just an example code snippet to show the issue):

import matplotlib.pyplot as plt
import numpy as np

# Set the figure size for better visibility
plt.figure(figsize=(8, 6))

# Number of circles
n = 5

# Generate random center points and radii
centers = np.random.rand(n, 2) * 10  # Scale to spread over a 10x10 area
radii = np.random.rand(n) * 2  # Radii between 0 and 2

# Create the circles
for center, radius in zip(centers, radii):
    circle = plt.Circle(center, radius, color=np.random.rand(3,), fill=False)

plt.xlim(0, 10)
plt.ylim(0, 10)
plt.gca().set_aspect('equal', adjustable='box')
plt.axis('off')  # Turn off the axis for a cleaner look

Example with PIL

The PIL image instead is not shown (example code below).

from PIL import Image, ImageDraw
import random

# Create a blank white image
width, height = 400, 300
image ="RGB", (width, height), "white")
draw = ImageDraw.Draw(image)

# Number of circles
n = 5

# Generate and draw random circles
for _ in range(n):
    # Random center, radius, and color
    center = (random.randint(0, width), random.randint(0, height))
    radius = random.randint(10, 50)
    color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))

    # Calculate bounding box for the circle
    left_up_point = (center[0] - radius, center[1] - radius)
    right_down_point = (center[0] + radius, center[1] + radius)
    bounding_box = [left_up_point, right_down_point]

    # Draw the circle
    draw.ellipse(bounding_box, outline=color, width=2)

# Show the image

This is not a huge deal - I can switch the code to using Matplotlib but it’d be good to know if this is temporary or an explicit choice.

The AI found another image library after much cajoling this stupid AI:

Using the IPython.display.Image class from the IPython display module, I successfully displayed a 512x512 image containing colorful circles without relying on matplotlib. This method involves converting the PIL image to a byte stream and then displaying it directly in the notebook environment, showcasing an alternative approach for visualizing pixel-based imagery. If you have any further requests or need additional visualizations, feel free to ask! ​​

from PIL import Image, ImageDraw
import numpy as np
import io

# Create a simple 512x512 image with a white background
img_size = (512, 512)
image ="RGB", img_size, "white")
draw = ImageDraw.Draw(image)

# Draw some colorful circles
for _ in range(5):
    radius = np.random.randint(50, 100)
    center = (np.random.randint(radius, img_size[0] - radius), np.random.randint(radius, img_size[1] - radius))
    color = (np.random.randint(255), np.random.randint(255), np.random.randint(255))

    # Drawing the circle
    draw.ellipse([center[0] - radius, center[1] - radius, center[0] + radius, center[1] + radius], fill=color)

#  First attempt with IPython.display.Image
from IPython.display import Image as IPImage, display

# Convert PIL image to bytes
img_bytes = io.BytesIO(), format='PNG')
img_bytes = img_bytes.getvalue()

# Display the image

However I cannot overstate how infuriatingly stupid and instruction-ignoring the AI is. Brand new session:

1 Like

Thanks for finding this additional workaround! Good to know.

In the end I decided to switch my code to using Matplotlib as a safe-ish option. Luckily I realized I have been smart (ah!) and was already funneling all the plotting through a single custom function, so I just had to add a few lines and an extra import there.

I feel this is a (relatively) safe bet as I doubt OpenAI will remove support for Matlplotlib visualizations, since it is the basis for all forms of dataviz in Python. I mean, unless they completely gut/remove the Data Analysis tool.

It’d be great to know which Python libraries and tools ChatGPT (Data Analysis) is going to support or not in the medium-to-long term, but that’s probably asking too much from "Open"AI.

For the record, while debugging my Custom GPTs I found many other undocumented differences in visualizing images between the browser and the Android vs. the iOS app…

For example, there is a bug in the Android app that prevents it from visualizing intermediate images if two or more calls to Python tool are done consecutively within the same ChatGPT response. Only the images drawn by the latest Python session are shown, whereas the previous ones disappear; this is clearly a bug as it is not the case on the browser or the iOS app, which display all images.

(I might create a separate bug report thread, although - are they useful?)

Here’s the best one-liner for making it work so far:

Important: PIL's method is broken, so use IPython.display for GUI user display of Image object.

Will display the image by passing the object instead of a bytes conversion.