【发布时间】:2023-02-17 00:21:47
【问题描述】:
我正在尝试使用 streamlit 构建注释界面。
在我的数据集中,每个数据点可能有多个标签(即下面代码中的labels)。但是,我只能使用st.multiselect() 选择一个标签,而不是预期的“多选”。具体来说,每次我单击其中一个选项时,页面都会更新并弹出下一个数据点。
陷入其中数小时后,我不确定出了什么问题。谁能为我提供任何指示?
import pandas as pd
import streamlit as st
df = pd.read_pickle("unlabeled.pkl")
records = df.to_dict("records")
if "annotations" not in st.session_state:
st.session_state.records = records
st.session_state.current_record = records[0]
annotated_data = list()
if st.session_state.records:
labels = st.session_state.current_record["labels"]
example = st.session_state.current_record["example"]
text = st.session_state.current_record["text"]
demo = "\n".join(["- {}".format(ee) for ee in example])
text = "- {}".format(text)
st.write(f"# Example\n{demo}\n# Output\n{text}")
labels = st.multiselect(
label="Select Labels",
options=labels
)
st.write('You Selected:', labels)
if st.button("Save"):
st.session_state.records.remove(st.session_state.current_record)
st.session_state.current_record = st.session_state.records[0]
annotated_data.append(
{
**st.session_state.current_record,
"label": labels
}
)
if len(annotated_data) % 50 == 0:
save_data(annotated_data)
save_data(annotated_data)
【问题讨论】: