我有最简单的streamlit程序
# import module
import streamlit as st
# Title
st.title("Hello GeeksForGeeks !!!")
Run Code Online (Sandbox Code Playgroud)
当我使用运行代码时
streamlit run main.py, I get the following errors:
SDRRAZAVIPOUR-MAC:[~/PycharmProjects/tool]$ streamlit run main.py
Traceback (most recent call last):
File "/opt/miniconda3/envs/tool/bin/streamlit", line 8, in <module>
sys.exit(main())
File "/opt/miniconda3/envs/tool/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/opt/miniconda3/envs/tool/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/opt/miniconda3/envs/tool/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/miniconda3/envs/tool/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/miniconda3/envs/tool/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return …Run Code Online (Sandbox Code Playgroud) Streamlit 服务器(例如使用 运行streamlit run app-name.py)在每个用户首次运行时需要与她进行交互 - 接受或拒绝此介绍消息:
Welcome to Streamlit!
If you are one of our development partners or are interested in
getting personal technical support, please enter your email address
below. Otherwise, you may leave the field blank.
Email:
Run Code Online (Sandbox Code Playgroud)
然后 Streamlit 等待输入,无法守护进程(在后台运行),这很快会导致 Kubernetes 或 Openshift 中的 docker 容器崩溃(进入著名的崩溃循环后退程序)。
如何通过在无头/非交互模式下运行 Streamlit 来避免此类崩溃?
我正在尝试使用 Streamlit 中的会话状态来创建两个嵌套按钮,其中第一个按钮单击显示推荐的电影,第二个提交按钮提交用户的评论,其中情绪分析模型正在运行。但嵌套按钮需要会话状态,所以我尝试了会话状态,但总是出错。下面是代码。
if 'rec_btn' not in st.session_state:
st.session_state.rec_btn= False
def callback():
st.session_state.rec_btn = True
if st.button('RECOMMEND',key = 'rec_btn'):
col1, col2, col3 = st.columns(3)
with col1:
st.image(output_images[0])
st.markdown(output_names[0].upper())
review = st.text_input(f"How much you liked the movie {output_names[0]}")
if st.button('submit',on_click=callback):
review = re.sub('[^a-zA-Z0-9 ]','',review)
review = tf_idf_vectorizer.transform([review])
ans = model_sentiment.predict(review)
if ans == 0:
review = 'Thanks for your positive review'
else:
review = 'Sorry for your negative review'
st.write(review)
Run Code Online (Sandbox Code Playgroud)
我总是收到错误:
StreamlitAPIException: Values for st.button, st.download_button, st.file_uploader,
and st.form cannot be …Run Code Online (Sandbox Code Playgroud) 我正在寻找制作可滚动元素列表的方法,甚至是修复列或容器的高度并使其可滚动的方法,以便一长串元素将保留在视口中,并且用户不必滚动到页面底部。
如何在 Streamlit 中制作垂直可滚动的元素列表?
我建立了一个爱彼迎机器学习模型来预测新加坡的价格。使用 pickle,我在 python 3.9 中序列化了经过训练的模型并将其推送到 github。
位于此处的 Streamlit Web 应用程序 - https://just4jc-singapore-airbnb-new-streamlit-app-khwftb.streamlit.app/工作了一段时间,最近抛出了一个错误。
Traceback (most recent call last):
File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
exec(code, module.__dict__)
File "/app/singapore-airbnb/new.py", line 119, in <module>
rf = pickle.load(file)
File "sklearn/tree/_tree.pyx", line 714, in sklearn.tree._tree.Tree.__setstate__
File "sklearn/tree/_tree.pyx", line 1418, in sklearn.tree._tree._check_node_ndarray
ValueError: node array from the pickle has an incompatible dtype:
- expected: {'names': ['left_child', 'right_child', 'feature', 'threshold', 'impurity', 'n_node_samples', 'weighted_n_node_samples', 'missing_go_to_left'], 'formats': ['<i8', '<i8', '<i8', '<f8', '<f8', '<i8', '<f8', 'u1'], 'offsets': [0, 8, …Run Code Online (Sandbox Code Playgroud) 我有一个流式聊天机器人,它工作得很好,但不记得以前的聊天历史记录。我试图用 langchain ConversationBufferMemory 添加它,但它似乎不起作用。
这是我创建的聊天机器人的示例:
import streamlit as st
from streamlit_chat import message
from langchain.chains import ConversationChain
from langchain.llms import OpenAI
from langchain.chat_models import AzureChatOpenAI
from langchain.memory import ConversationBufferMemory
from langchain.prompts import (
ChatPromptTemplate,
MessagesPlaceholder,
SystemMessagePromptTemplate,
HumanMessagePromptTemplate
)
prompt = ChatPromptTemplate.from_messages([
SystemMessagePromptTemplate.from_template("The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says …Run Code Online (Sandbox Code Playgroud) 我想创建一个简单的流线型应用程序,当您按下按钮时,它会增加 x 并显示 x 的新值。
但是,它仅适用于第一次“x 仅显示值 2 且不增加”
import streamlit as st
x = 1
if st.button("Increment x"):
x=x+1
st.text(x)
Run Code Online (Sandbox Code Playgroud) 我是 heroku 的新手该应用程序在 python 3.7 中,并使用流光、散景和熊猫我已经成功部署了一个 python 流光应用程序,但是当我尝试打开它时,我收到以下错误。我无法理解 255 错误和以下行:
Found invalid character in key name: '['. Try quoting the key name.
Run Code Online (Sandbox Code Playgroud)
如果有人可以提供帮助,我会很高兴。这是日志文件:
C:\Users\imall\Desktop\projects\app>heroku logs --tail
2020-06-05T17:31:11.476321+00:00 app[api]: Release v1 created by user xxx@gmail.com
2020-06-05T17:31:11.476321+00:00 app[api]: Initial release by user xxx@gmail.com
2020-06-05T17:31:11.710688+00:00 app[api]: Release v2 created by user xxx@gmail.com
2020-06-05T17:31:11.710688+00:00 app[api]: Enable Logplex by user xxx@gmail.com
2020-06-05T17:31:44.000000+00:00 app[api]: Build started by user xxx@gmail.com
2020-06-05T17:33:09.232663+00:00 app[api]: Release v3 created by user xxx@gmail.com
2020-06-05T17:33:09.232663+00:00 app[api]: Deploy 5e76f3fe by user xxx@gmail.com
2020-06-05T17:33:09.252408+00:00 app[api]: …Run Code Online (Sandbox Code Playgroud) 我是 Streamlit 的新手。我试图为 sidebar.selectbox 设置一个默认值。代码如下。我感谢您的帮助!先感谢您。
st.sidebar.header('Settings')
fichier = st.sidebar.selectbox('Dataset', ('djia', 'msci', 'nyse_n', 'nyse_o', 'sp500', 'tse'))
window_ANTICOR = st.sidebar.selectbox('Window ANTICOR', ['<select>',3, 5, 10, 15, 20, 30])
if window_ANTICOR == '<select>':
window_ANTICOR == 30
window_OLMAR = st.sidebar.selectbox('Window OLMAR', ['<select>',3, 5, 10, 15, 20, 30])
if window_OLMAR == '<select>':
window_OLMAR == 5
eps_OLMAR = st.sidebar.selectbox('Eps OLMAR', ['<select>', 3, 5, 10, 15, 20, 30])
if eps_OLMAR == '<select>':
eps_OLMAR == 10
eps_PAMR = st.sidebar.selectbox('Eps PAMR', ['<select>',0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, …Run Code Online (Sandbox Code Playgroud) streamlit ×10
python ×6
docker ×1
frameworks ×1
heroku ×1
kubernetes ×1
langchain ×1
openshift ×1
pickle ×1
python-3.x ×1