Hi, im having a problem with the text_inpts in a while loop, the inputs are like null strings that are making a infinite loop, heres the part of the code that is makking me problems
st.write("ChatBot: Hola este es el chatbot de la cafetería ¿En qué puedo ayudarte?")
while True:
inp = st.text_input("Tú: ", key=llave, autocomplete=None)
llave += 1
tag, maxscore = instancer(inp, model_NI, NI)
if maxscore > 0.8 or inp == 'salir':
break
else:
st.write("ChatBot: Lo siento, pero no entendí tu petición, ¿Podrías decirlo de otra forma?")
Streamlit works with a reactive model, which means that every time an input changes, the whole script reruns. This is probably why you are experiencing an infinite loop.
Can you try this code instead:
import streamlit as st
st.write("ChatBot: Hola, este es el chatbot de la cafetería ¿En qué puedo ayudarte?")
if 'input_history' not in st.session_state:
st.session_state.input_history = []
inp = st.text_input("Tú: ", autocomplete=None)
if inp and (len(st.session_state.input_history) == 0 or inp != st.session_state.input_history[-1]):
st.session_state.input_history.append(inp)
tag, maxscore = instancer(inp, model_NI, NI)
if maxscore > 0.8 or inp == 'salir':
st.write(f"ChatBot: {tag}") # or however you want to respond
else:
st.write("ChatBot: Lo siento, pero no entendí tu petición, ¿Podrías decirlo de otra forma?")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.