我写了一个功能,用户可以提供URL,并宣传分析纽芬兰语。 在强制使用ton子方面,触发了繁琐的职能。 如果成功,则向用户提供启动聊天工作的文本箱。 当用户向聊天提交投入时,履行分析功能,产出应写到屏幕上。
import streamlit as st
from streamlit_chat import message
import logging
# Custom functions
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
st.markdown("<h1>VTest</h1>", unsafe_allow_html=True)
st.sidebar.header("Input parameter")
def do_something(url):
st.write("Calc Length")
slen = len(url)
return slen
def get_text():
input_text = st.text_area("You:")
return input_text
def ans(len,user_input):
return user_input+" Test "+str(len)
if "analyze" not in st.session_state:
st.session_state["analyze"] = False
if "submit" not in st.session_state:
st.session_state["submit"] = False
with st.sidebar.form(key="my_form"):
URL = st.text_input("Enter URL :")
analyze_button = st.form_submit_button(label="Analyze")
if str(URL) == "":
st.warning("Awaiting URL input in sidebar for chat.")
if analyze_button:
st.session_state["analyze"] = not st.session_state["analyze"]
if str(URL) != "":
with st.spinner(
"Patience ..."
):
slen = do_something(URL)
if slen>0 and st.session_state["analyze"]:
user_input = get_text()
submit = st.button("Submit")
if user_input:
with st.form(key= my_form ):
submit_button = st.form_submit_button( Submit )
if submit_button:
response = ans(len,user_input)
st.write(response)
else:
st.warning("Enter your question above")
else:
st.error(
f"The greatest teacher, failure is...
"
)
else:
st.sidebar.warning("Please provide URL ")
raise Exception("You must provide a URL !")
预期行为:
用户点击提交信标时应当执行,答复应在屏幕上打印。
实际行为:
整页的重载,屏幕上有空白。 do死再次发生,不应发生。