linbojunzi commited on
Commit
c256760
·
verified ·
1 Parent(s): 421514f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -30
app.py CHANGED
@@ -45,36 +45,31 @@ def load_json(file_name):
45
  # 修改 Context 渲染逻辑,添加 CSS 控制布局
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
- # 渲染表格
53
- st.write("### Table")
54
- st.markdown(data['table_html'], unsafe_allow_html=True)
55
-
56
- # 添加自定义 CSS 以避免重叠问题
57
- st.write("""
58
- <style>
59
- .context span { color: red; font-weight: bold; }
60
- .context p { margin-bottom: 15px; }
61
- </style>
62
- """, unsafe_allow_html=True)
63
-
64
- st.write("### Context")
65
- # 拼接 all_context,并用 CSS 渲染 target_context_ids 和 perturb_sentence_id 的高亮
66
- all_context = data["all_context"]
67
- highlighted_context = '<div class="context">'
68
- for idx, sentence in enumerate(all_context):
69
- if idx == data["perturb_sentence_id"]:
70
- highlighted_context += f"<span>{sentence}</span> "
71
- elif idx in data["target_context_ids"]:
72
- highlighted_context += f"<b>{sentence}</b> "
73
- else:
74
- highlighted_context += f"<p>{sentence}</p> "
75
- highlighted_context += '</div>'
76
- st.markdown(highlighted_context, unsafe_allow_html=True)
77
-
78
  st.write("### Selected Paragraphs")
79
  for paragraph in data["selected_paragraphs"]:
80
  st.write(paragraph)
@@ -85,6 +80,7 @@ def display_dict(data):
85
  st.write("**Perturbed Explanation:**")
86
  st.write(data["output"]["perturbed_explanation"])
87
 
 
88
  # 主程序
89
  def main():
90
  st.title("Perturb For Table")
 
45
  # 修改 Context 渲染逻辑,添加 CSS 控制布局
46
  def display_dict(data):
47
  st.write("### 文件信息")
48
+ st.write(f"**Path:** {data['path']} | **Table ID:** {data['table_id']} | **Section:** {data['section']}")
49
+
50
+ # 使用两个列来分隔内容
51
+ col1, col2 = st.columns(2)
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)
 
80
  st.write("**Perturbed Explanation:**")
81
  st.write(data["output"]["perturbed_explanation"])
82
 
83
+
84
  # 主程序
85
  def main():
86
  st.title("Perturb For Table")