Streamlit code loop

Hello can I make a request hehehe can you make my code a loop. BTW, this community is the best for helping us student who struggles in coding. Thank youuu!

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:
        
        col1, col2, col3, col4 = st.beta_columns(4)
        #Original
        with col1:
            img = Image.open(uploaded_file)
            fig0 = plt.figure(figsize=(5,5))
            plt.imshow(img)        
            st.pyplot(fig0)
        
        #Invert
        with col2:
            pil2invert = np.array(img.convert("L"))
            fig1 = plt.figure(figsize=(5,5))
            plt.imshow(pil2invert)        
            st.pyplot(fig1)
        
        #Gray
        with col3:
            pil2gray = ImageOps.grayscale(img)
            fig2 = plt.figure(figsize=(5,5))
            plt.imshow(pil2gray, 'gray')        
            st.pyplot(fig2)

        with col4:
            img_palette = img.convert("P", palette=Image.ADAPTIVE, colors=8)
            fig3 = plt.figure(figsize=(5,5))
            plt.imshow(img_palette, 'gray')        
            st.pyplot(fig3)