Help: Streamlit remembers past inputs, despite clearing cache?


I have a LLM for summarization task. I provide an URL and a question and the model returns a summary of the text in the URL. I get weird behaviour when i provide the second URL, because streamlit somehow remembers my past questions/inputs and includes them (i speculate - because i cannot reproduce the error by running the program via CLI).

Steps to reproduce

first inquiry:
URL “Hannah Arendt - Wikipedia”, question: “who was she?”

returns summary: Hannah Arendt was … (Im happy with the result)

Second inquiry:
URL “Francisco Goya - Wikipedia”, question: “who was she?”

returns summary: Hannah Arendt was… (Im NOT happy, since the text is about fransisco goya and his wife! hence, she should be “wife”. I tried to run this inquiry first, and then everything works as expected: “she” is then understood as Goyas Wife.)

I do not understand what causes the problem, I have tried to clear caches and resources as seen in the code, but nothing works. (i have also tried to do it via the menu bar at the site, the only thing that works for me is to shut down the server and the start it again).

Code snippet:

import streamlit as st
from summarizer import llama_summarizer

# title of the app
st.title("Open source Llama for text summarization")

with st.sidebar:
    retriever_opt = st.selectbox("Retriever", ("default", "SVM", "MultiQuery"))
    device_opt = st.selectbox("Device", ("mps", "cpu", "cuda"))
    model_opt = st.selectbox("Llama", ("summarizev2", "summarizev"))
    embedding_opt = st.selectbox("Embedding model", ("large", "small"))

#with col1:
url = st.text_input("Enter URL to the text you want to summarize", placeholder="")
question = st.text_input("Enter a question to ask the model", placeholder="Summarize this text:")

if st.button("Summarize"):   
    # button trigger summarization
    with st.spinner("Summarizing..."):
        summarizer = llama_summarizer(url=url,
        summarizer = (summarizer.scrape_text()
        summary = summarizer.answ['result'].strip()
    box_height = int(len(summary) * 0.55)    
    st.text_area("Summary", value=summary, height=box_height, max_chars=None, key=None)

if st.button("Show text"):
    with st.spinner("showing text"):
            text = url
            text = "No text scraped yet."
    box_height = int(len(text) * 0.55)
    st.text_area("Text", value=text, height=box_height, max_chars=None, key=None)
# Button to rerun the app (start from fresh)
if st.button("Start from Fresh"):

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Debug info

  • Streamlit version: 1.26.0
  • Python version: 3.11.4
  • OS version: MacOS

Hi @Ernst-hub

Perhaps you can use the following code snippet (from the Llama 2 chatbot that I’ve recently built) as an idea for implementing chat history removal button:

def clear_chat_history():
    st.session_state.messages = [{"role": "assistant", "content": "How may I assist you today?"}]
st.sidebar.button('Clear Chat History', on_click=clear_chat_history)

Hope this helps!