linbojunzi commited on
Commit
7360ce1
1 Parent(s): a0d318f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+ import os
4
+
5
+ # 设置JSON文件的目录
6
+ JSON_DIR = "paper_content"
7
+
8
+ # 加载指定的JSON文件
9
+ def load_json(file_name):
10
+ file_path = os.path.join(JSON_DIR, file_name)
11
+ with open(file_path, "r", encoding="utf-8") as f:
12
+ return json.load(f)
13
+
14
+ # 显示单个字典的信息
15
+ def display_dict(data):
16
+ st.write("### 文件信息")
17
+ st.write(f"**Path:** {data['path']}")
18
+ st.write(f"**Table ID:** {data['table_id']}")
19
+ st.write(f"**Section:** {data['section']}")
20
+ st.write("### Table")
21
+ st.markdown(data['table'], unsafe_allow_html=True)
22
+
23
+ st.write("### Context")
24
+ # 拼接 all_context 并高亮 target_context_ids 的句子
25
+ all_context = data["all_context"]
26
+ highlighted_context = ""
27
+ for idx, sentence in enumerate(all_context):
28
+ if idx == data["perturb_sentence_id"]:
29
+ highlighted_context += f"<span style='color:red;'>{sentence}</span> "
30
+ elif idx in data["target_context_ids"]:
31
+ highlighted_context += f"**{sentence}** "
32
+ else:
33
+ highlighted_context += sentence + " "
34
+ st.markdown(highlighted_context, unsafe_allow_html=True)
35
+
36
+ st.write("### Selected Paragraphs")
37
+ for paragraph in data["selected_paragraphs"]:
38
+ st.write(paragraph)
39
+
40
+ st.write("### Output")
41
+ st.write("**Perturbed Statement:**")
42
+ st.write(data["output"]["perturbed_statement"])
43
+ st.write("**Perturbed Explanation:**")
44
+ st.write(data["output"]["perturbed_explanation"])
45
+
46
+ # 主程序
47
+ def main():
48
+ st.title("JSON文件查看器")
49
+
50
+ # 获取文件列表
51
+ file_list = [f for f in os.listdir(JSON_DIR) if f.endswith(".json")]
52
+
53
+ # 搜索框选择文件
54
+ selected_file = st.selectbox("选择一个文件", file_list)
55
+
56
+ # 加载并展示JSON内容
57
+ if selected_file:
58
+ st.write(f"当前选择文件: **{selected_file}**")
59
+ json_data = load_json(selected_file)
60
+
61
+ # 展示每个字典的信息
62
+ for idx, single_dict in enumerate(json_data):
63
+ st.write(f"## 数据 {idx + 1}")
64
+ display_dict(single_dict)
65
+
66
+ if __name__ == "__main__":
67
+ main()