How do i add see more button in streamlit without restarting the whole script?

At the moment given a question, I get a list of answers (dependent on the number of prediction slider),
What I would want is just for the first answer to be displayed, and on clicking the see more button , it shows the rest of the predicted answers

Here is my code

n_predictions = st.sidebar.slider(label=“Number Of Predictions”, min_value=1, max_value=10)

        prediction = cdqa_pipeline.predict(query, n_predictions=n_predictions)
        for i,value in enumerate(prediction):
            annotated_text(("Answer:", '', "#8ef"))
            title_var=title.replace(" ","%20")
            annotated_text(("Paragraph:", '', "#faa"))
            paragraph_var = st.write(paragraph)
            #paragraph_var=st.write("Paragraph: " + paragraph)
            annotated_text(("Page Number:", '', "#afa"))
            page_number = st.write( title)
            #page_number = st.write("Page Number: " + title)
            annotated_text(("Download:", '', "#fea"))
            st.markdown("Download This Report Here [link](%s)" % url)
1 Like

Hi Fatima,

Have you tried caching your function via st.cache?


1 Like

I am actually stuck at making the function work in the desired way

prediction = cdqa_pipeline.predict(query, 6)

for i, value in enumerate(prediction):
    answer, title, paragraph, predictionsss = value
    answer_var = st.write(answer) #should only print prediction 1

I want to add

if st.button("Show more"):
 #when this is clicked it shows the rest of the results (prediction 2-6)
1 Like

Thanks @Hiba_Fatima

Can you please share the full code, if possible?