Spaces:
Sleeping
Sleeping
linbojunzi
commited on
Commit
•
143890b
1
Parent(s):
c256760
Update app.py
Browse files
app.py
CHANGED
@@ -12,64 +12,27 @@ def load_json(file_name):
|
|
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 |
-
# 修改 Context 渲染逻辑,添加 CSS 控制布局
|
46 |
def display_dict(data):
|
47 |
st.write("### 文件信息")
|
48 |
-
st.write(f"**Path:** {data['path']}
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
with col1:
|
54 |
-
st.write("### Table")
|
55 |
-
st.markdown(data['table_html'], unsafe_allow_html=True)
|
56 |
-
|
57 |
-
with col2:
|
58 |
-
st.write("### Context")
|
59 |
-
# 拼接 all_context,并高亮特定部分
|
60 |
-
all_context = data["all_context"]
|
61 |
-
highlighted_context = '<div class="context">'
|
62 |
-
for idx, sentence in enumerate(all_context):
|
63 |
-
if idx == data["perturb_sentence_id"]:
|
64 |
-
highlighted_context += f"<span style='color:red;'>{sentence}</span> "
|
65 |
-
elif idx in data["target_context_ids"]:
|
66 |
-
highlighted_context += f"<b>{sentence}</b> "
|
67 |
-
else:
|
68 |
-
highlighted_context += sentence + " "
|
69 |
-
highlighted_context += '</div>'
|
70 |
-
st.markdown(highlighted_context, unsafe_allow_html=True)
|
71 |
-
|
72 |
-
# 单独分离的内容
|
73 |
st.write("### Selected Paragraphs")
|
74 |
for paragraph in data["selected_paragraphs"]:
|
75 |
st.write(paragraph)
|
@@ -81,6 +44,7 @@ def display_dict(data):
|
|
81 |
st.write(data["output"]["perturbed_explanation"])
|
82 |
|
83 |
|
|
|
84 |
# 主程序
|
85 |
def main():
|
86 |
st.title("Perturb For Table")
|
|
|
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)
|
|
|
44 |
st.write(data["output"]["perturbed_explanation"])
|
45 |
|
46 |
|
47 |
+
|
48 |
# 主程序
|
49 |
def main():
|
50 |
st.title("Perturb For Table")
|