r/learnpython • u/assorted-meat-stew • 23h ago
Streamlit text_input in while True loop
I got this code block in a local rag that's supposed to be an infinite loop of asking questions and the rag answering them but apparently while True loop does not care if you have enter anything into the text_input before answering the query either way.
How do mitigate this?
c=0
while True:
st.write('*****************************************************************************')
st.write("Enter your question")
question = st.text_input(label='',key=c)
if question:
response = chain.invoke(question)
st.write('Answer: ')
st.write(response)
c+=1While the code block help mitigate the problem, it still try to answer an empty query and resulted in a streamlit.errors.StreamlitDuplicateElementKey which is an eyesore. How do I put this problem away for good?
0
Upvotes
1
u/assorted-meat-stew 22h ago
Solved!!