diff --git a/tools/label_tool.py b/tools/label_tool.py index de5bf57..05b0d9e 100644 --- a/tools/label_tool.py +++ b/tools/label_tool.py @@ -1,8 +1,7 @@ ''' -This script is used to read the table data from the jsonl file and display it in a streamlit app. - -命令行输入: -streamlit run WebMainBench/webmainbench/utils/Data_Modification_Tools.py -- WebMainBench/data/WebMainBench_test_0814_llm-webkit_filtered_table_results.jsonl +本脚本用于从jsonl文件读取表格数据,并在streamlit应用中展示和编辑。 +命令行输入示例: +streamlit run /home/zhangshuo/Desktop/vscodeworkspace/WebMainBench/tools/label_tool.py -- WebMainBench/data/WebMainBench_test_0814_llm-webkit_filtered_table_results.jsonl 注意:-- 后面有个空格,否则会报错,然后再接数据文件路径 ''' @@ -33,12 +32,18 @@ def load_data(): data.append(json.loads(line)) return data -# 保存所有数据 -def save_data(data): - with open(DATA_FILE, "w", encoding="utf-8") as f: - for item in data: - print(item) - f.write(json.dumps(item, ensure_ascii=False) + "\n") +# 只更新单条数据,避免全文件重写 +def update_single_item(index, new_item): + lines = [] + if not os.path.exists(DATA_FILE): + return + with open(DATA_FILE, "r", encoding="utf-8") as f: + lines = f.readlines() + if 0 <= index < len(lines): + # 保证只替换对应行 + lines[index] = json.dumps(new_item, ensure_ascii=False) + "\n" + with open(DATA_FILE, "w", encoding="utf-8") as f: + f.writelines(lines) # Streamlit页面布局 st.set_page_config(layout="wide") @@ -58,30 +63,48 @@ def save_data(data): with col1: st.subheader("HTML 渲染") - st.markdown( - f'