How to delete the content of a control after it has been rendered once?

I am creating a chatbot application using a custom component:

The idea is that the user can paste an image, and then ask a question about the image using DALLE3.

The code works perfectly fine, however after the process_query returns, I have to run the rerun, and then the pbutton is rendered again, whichs is FINE, but the image is rendered again which makes no sense.


class VisionChatBotManager:
    def __init__(self, st, page_configurator):
        """
        Initialize the Vision ChatBotManager object.

        Args:
            st: Streamlit object for interaction.
            page_configurator: Instance of PageConfigurator.
        """
        self.st = st
        self.page_configurator = page_configurator
        self.user_query = None

    def setup_llm(self):
        """
        Set up the language model.
        """
        return AzureChatOpenAI(
            azure_endpoint=AZURE_OPENAI_ENDPOINT,
            openai_api_version=OPENAI_API_VERSION,
            deployment_name="gpt-4-vision-deployment",
            openai_api_key=OPENAI_API_KEY,
            openai_api_type=OPENAI_API_TYPE,
            model_name="gpt-4-vision-preview",
            temperature=0,
            max_tokens=512
        )


    def process_user_query(self, user_query):
        """
        Process the user query and update chat history.

        Args:
            user_query (str): The user's query.
        """
        img_b64 = self.img_b64
        self.st.session_state.chat_history.append(VisionMessage("human", image=img_b64, message=user_query))
     
        llm = self.setup_llm()
        with callbacks.collect_runs() as cb:
            #run_id=cb.run_id
            response = llm.invoke(
                                [
                                    HumanMessage(
                                        content=[
                                            {
                                                "type": "text", 
                                                "text": user_query
                                            },
                                            {
                                                "type": "image_url",
                                                "image_url": 
                                                {
                                                    "url": f"data:image/jpeg;base64,{img_b64}",
                                                    "detail": "auto"
                                                }
                                            },
                                        ]
                                    )
                                ]
                            )
        self.st.session_state.chat_history.append(VisionMessage("ai", image="", message=response.content))
        self.page_configurator.setup_chat()
        #self.st.rerun()
        
    def setup_paste_button(self):
        """
        Set up the paste button for image input.
        """
        container = self.st.empty()  # Create an empty container
        
        paste_result = pbutton("πŸ“‹ Paste an image")        
        if paste_result.image_data is not None:
            # Clear the container if it's not empty
            if container is not None:
                container.empty()
            
            # Display the image inside the container
            container.image(paste_result.image_data)
            
            img_bytes = io.BytesIO()
            paste_result.image_data.save(img_bytes, format='PNG')
            img_bytes = img_bytes.getvalue() 
            img_b64 =  base64.b64encode(img_bytes).decode('utf-8') # Image as base64
            self.img_b64 = img_b64
                
    def run_chatbot(self):
        """
        Run the chatbot.
        """
        self.setup_paste_button() 
        
        if user_query := self.st.chat_input(placeholder="Ask a question about the pasted image?"):
            self.process_user_query(user_query)

and in VisionPageConfiguration.py I have this:

  def setup_chat(self):
        """
        Set up the chat section of the page.
        """
        with self.chat_placeholder:    
            for chat in st.session_state.chat_history:
                if chat.origin == 'human':
                    div = f"""
                        <div class="chat-row row-reverse">
                            <img class="chat-icon-human" src="app/static/human.png" width=32 height=32>
                            <div class="chat-bubble human-bubble">
                                <p>{chat.message}<img src="data:png;base64,{chat.image}" </p>
                            </div>
                        </div>
                        """
                    st.markdown(div, unsafe_allow_html=True)
                elif chat.origin == 'ai':
                    # Display AI message with sources
                    div = f"""
                        <div class="chat-row">
                            <img class="chat-icon-ai" src="app/static/e61logoNew.png" width=32 height=32>
                            <div class="chat-bubble ai-bubble">
                                <p>{chat.message}</p>
                            </div>
                        </div>
                        """
                    st.markdown(div, unsafe_allow_html=True)

Try rendering pbutton with a new random key each run/rerun.

how?