Color invert conversion error

Hi lasttt request hehehe I used your code and apply with the other code but one of the image doesnt need to have β€œgray”, because i want to invert an image it stay on grayscale.
There are 4 image to display but original. invert, gray, pallete. But consequently, invert didnt invert instead it stay gray but the rest display the image correctly.

def analyze(uploaded_file):
st.set_option('deprecation.showfileUploaderEncoding', False)
realtime_update = st.sidebar.checkbox(label="Update in Real Time", value=True)

if uploaded_file:
    img = Image.open(uploaded_file)
    pil2invert = np.array(img.convert("L")) #here the image didnt invert and just stay on grayscale.
    pil2gray = ImageOps.grayscale(img)
    img_palette = img.convert("P", palette=Image.ADAPTIVE, colors=8)

    col_tuple = st.beta_columns(4)
    
    figure_contents=(
      "Original",
      "Invert",
      "Gray",
      "Palette")

    imshow_params=(
        img, 
        pil2invert,
        pil2gray, 
        img_palette)

    loop_data=list(zip(
      col_tuple,
      figure_contents,
      imshow_params))

    for loop in loop_data:
      with loop[0]:
        fig_n=plt.figure(figsize=(14, 8))
        fig_n.suptitle(loop[1])
        plt.imshow(loop[2], 'gray')
        st.pyplot(fig_n)