linbojunzi commited on
Commit
db12aed
·
verified ·
1 Parent(s): ddc841e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -45
app.py CHANGED
@@ -11,58 +11,26 @@ def load_json(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_html'], 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
  def display_dict(data):
47
  st.write("### 文件信息")
48
  st.write(f"**Path:** {data['path']}")
49
  st.write(f"**Table ID:** {data['table_id']}")
50
  st.write(f"**Section:** {data['section']}")
51
 
52
- st.write("### Table")
53
- st.markdown(data['table_html'], unsafe_allow_html=True)
54
 
55
- with st.expander("Context Details"):
56
- all_context = data["all_context"]
57
- highlighted_context = ""
58
- for idx, sentence in enumerate(all_context):
59
- if idx == data["perturb_sentence_id"]:
60
- highlighted_context += f"<span style='color:red;'>{sentence}</span> "
61
- elif idx in data["target_context_ids"]:
62
- highlighted_context += f"**{sentence}** "
63
- else:
64
- highlighted_context += sentence + " "
65
- st.markdown(highlighted_context, unsafe_allow_html=True)
 
66
 
67
  st.write("### Selected Paragraphs")
68
  for paragraph in data["selected_paragraphs"]:
@@ -73,6 +41,10 @@ def display_dict(data):
73
  st.write(data["output"]["perturbed_statement"])
74
  st.write("**Perturbed Explanation:**")
75
  st.write(data["output"]["perturbed_explanation"])
 
 
 
 
76
 
77
 
78
  # 主程序
 
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
 
 
 
21
 
22
+ st.write("### Context")
23
+ # 拼接 all_context 并高亮 target_context_ids 的句子
24
+ all_context = data["all_context"]
25
+ highlighted_context = ""
26
+ for idx, sentence in enumerate(all_context):
27
+ if idx == data["perturb_sentence_id"]:
28
+ highlighted_context += f"<span style='color:red;'>{sentence}</span> "
29
+ elif idx in data["target_context_ids"]:
30
+ highlighted_context += f"**{sentence}** "
31
+ else:
32
+ highlighted_context += sentence + " "
33
+ st.markdown(highlighted_context, unsafe_allow_html=True)
34
 
35
  st.write("### Selected Paragraphs")
36
  for paragraph in data["selected_paragraphs"]:
 
41
  st.write(data["output"]["perturbed_statement"])
42
  st.write("**Perturbed Explanation:**")
43
  st.write(data["output"]["perturbed_explanation"])
44
+ st.write("### Table")
45
+ st.markdown(data['table_html'], unsafe_allow_html=True)
46
+
47
+
48
 
49
 
50
  # 主程序