Summary
Whenever I am selecting an attribute from selectbox, the code runs again including the code under the button. I dont want the code under the button to rerun again, what can I do? I tried implementing session state but not sure where i am making mistake. Any help would be appreciated.
Code snippet:
button=st.button("Know")
if st.session_state.get('button') != True:
st.session_state['button'] = button
if st.session_state['button'] == True and username:
try:
with st.spinner("Fetchingโณ....."):
tweets,lst = get_data(username,no_tweets)
prompt, template = start_haystack(api_key,tweets)
results = query(prompt, template)
ans = results[0]
st.markdown(f"<h4 style='font-family: Roboto; font-weight: normal;'>@{username} has been tweeting about:</h4>", unsafe_allow_html=True)
st.markdown(f"<h4 style='font-family: Lato; border: 2px solid #26C3E2; padding: 15px; font-weight: normal;'>{ans}</h4>", unsafe_allow_html=True)
st.write("")
st.write("")
st.markdown(f"<h3>Source Tweets:</h3>", unsafe_allow_html=True)
for i in lst:
st.markdown(f"<h5 style='font-family: Chirp; font-weight: normal;'>{i}</h5>",unsafe_allow_html=True)
st.divider()
except Exception as e:
st.write(e)
st.write("Kindly reduce the no. of tweets to summarize")
if st.session_state['button']==True:
keywords = get_keyword(api_key, ans)
keys = Convert(keywords[0])
print(keys)
st.markdown(f"<h3>Select a topic to know more</h3>", unsafe_allow_html=True)
box = st.selectbox("", keys)
articles=get_latest_articles(box)
for article in articles:
st.write('Title:', article['title'])
st.write('Link:', article['link'])
st.write('Snippet:', article['snippet'])
st.divider()
elif button and not username:
st.warning("Please enter a twitter handle")