Selaa lähdekoodia

优化OCR文件选择界面,新增页码输入功能和文件加载反馈,提升用户交互体验

zhch158_admin 2 kuukautta sitten
vanhempi
commit
db206d255e
1 muutettua tiedostoa jossa 47 lisäystä ja 19 poistoa
  1. 47 19
      streamlit_ocr_validator.py

+ 47 - 19
streamlit_ocr_validator.py

@@ -362,31 +362,59 @@ def main():
     # 页面标题
     config = st.session_state.validator.config
     st.title(config['ui']['page_title'])
-    st.markdown("---")
-    
-    # 侧边栏 - 文件选择和控制
-    with st.sidebar:
-        st.header("📁 文件选择")
-        
+    # st.markdown("---")
+
+    with st.container(height=100, horizontal=True, horizontal_alignment='left'):
+        # st.subheader("📁 文件选择")
         # 查找可用的OCR文件
-        available_files = find_available_ocr_files(config['paths']['ocr_out_dir'])
+        file_info = find_available_ocr_files(config['paths']['ocr_out_dir'])
+        # 初始化session_state中的选择索引
+        if 'selected_file_index' not in st.session_state:
+            st.session_state.selected_file_index = 0
+        if file_info:
+            # 创建显示选项列表
+            display_options = [f"{info['display_name']}" for info in file_info]
+            file_paths = [info['path'] for info in file_info]
         
-        if available_files:
-            selected_file = st.selectbox("选择OCR结果文件", available_files, index=0)
-            
-            if st.button("🔄 加载文件", type="primary") and selected_file:
+            selected_index = st.selectbox("选择OCR结果文件", 
+                range(len(display_options)),
+                format_func=lambda i: display_options[i],
+                index=st.session_state.selected_file_index,
+                key="selected_selectbox",
+                label_visibility="collapsed")
+            # 更新session_state
+            if selected_index != st.session_state.selected_file_index:
+                st.session_state.selected_file_index = selected_index
+                
+            selected_file = file_paths[selected_index]
+
+            # number_input, 范围是文件数量,默认值是1,步长是1
+            # 页码输入器
+            current_page = file_info[selected_index]['page']
+            page_input = st.number_input("输入一个数字", 
+                placeholder="输入页码", 
+                label_visibility="collapsed",
+                min_value=1, max_value=len(display_options), value=current_page, step=1,
+                key="page_input"
+            )
+            # 当页码输入改变时,更新文件选择
+            if page_input != current_page:
+                # 查找对应页码的文件索引
+                for i, info in enumerate(file_info):
+                    if info['page'] == page_input:
+                        st.session_state.selected_file_index = i
+                        selected_file = file_paths[i]
+                        st.rerun()
+                        break
+
+            if st.button("🔄 加载文件", type="secondary") and selected_file:
                 st.session_state.validator.load_ocr_data(selected_file)
-                st.success("✅ 文件加载成功!")
+                st.success(f"✅ 已加载第{file_info[selected_index]['page']}页")
                 st.rerun()
         else:
             st.warning("未找到OCR结果文件")
             st.info("请确保output目录下有OCR结果文件")
         
-        st.markdown("---")
-        
-        # 控制面板
-        st.header("🎛️ 控制面板")
-        
         if st.button("🧹 清除选择"):
             st.session_state.selected_text = None
             st.rerun()
@@ -394,7 +422,7 @@ def main():
         if st.button("❌ 清除错误标记"):
             st.session_state.marked_errors = set()
             st.rerun()
-    
+
     # 主内容区域
     validator = st.session_state.validator
     
@@ -425,7 +453,7 @@ def main():
     if stats['tool_info']:
         st.expander("🔧 OCR工具详情", expanded=False).write(stats['tool_info'])
     
-    st.markdown("---")
+    # st.markdown("---")
     
     # 创建标签页
     tab1, tab2, tab3, tab4 = st.tabs(["📄 内容校验", "📊 表格分析", "📈 数据统计", "🚀 快速导航"])