|
@@ -200,48 +200,37 @@ def create_table_line_editor():
|
|
|
if st.session_state.ocr_data and st.session_state.image:
|
|
if st.session_state.ocr_data and st.session_state.image:
|
|
|
st.info(f"📂 已加载: {st.session_state.loaded_json_name}")
|
|
st.info(f"📂 已加载: {st.session_state.loaded_json_name}")
|
|
|
|
|
|
|
|
- # 🔧 显示分析参数设置(统一处理)
|
|
|
|
|
- st.sidebar.subheader("🔬 分析参数")
|
|
|
|
|
-
|
|
|
|
|
- analysis_method = st.sidebar.selectbox(
|
|
|
|
|
- "分析算法",
|
|
|
|
|
- ["auto", "cluster", "mineru"],
|
|
|
|
|
- format_func=lambda x: {
|
|
|
|
|
- "auto": "🤖 自动选择(推荐)",
|
|
|
|
|
- "cluster": "📊 聚类算法(通用)",
|
|
|
|
|
- "mineru": "🎯 MinerU 索引算法"
|
|
|
|
|
- }[x]
|
|
|
|
|
|
|
+ # 使用统一的 setup_new_annotation_mode
|
|
|
|
|
+ _, structure, _, line_width, display_mode, zoom_level, show_line_numbers = setup_new_annotation_mode(
|
|
|
|
|
+ st.session_state.ocr_data,
|
|
|
|
|
+ st.session_state.image,
|
|
|
|
|
+ TABLE_EDITOR_CONFIG["display"]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- if analysis_method in ["auto", "cluster"]:
|
|
|
|
|
- y_tolerance = st.sidebar.slider("Y轴容差", 1, 20, 5)
|
|
|
|
|
- x_tolerance = st.sidebar.slider("X轴容差", 1, 30, 10)
|
|
|
|
|
- min_row_height = st.sidebar.slider("最小行高", 10, 50, 20)
|
|
|
|
|
-
|
|
|
|
|
- # 🎯 分析按钮
|
|
|
|
|
- if st.button("🔍 分析表格结构"):
|
|
|
|
|
- with st.spinner("正在分析..."):
|
|
|
|
|
- # 统一的分析流程
|
|
|
|
|
- generator = TableLineGenerator(
|
|
|
|
|
- st.session_state.image,
|
|
|
|
|
- st.session_state.ocr_data
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- if analysis_method == "auto":
|
|
|
|
|
- # 根据数据特征自动选择
|
|
|
|
|
- has_cell_index = any('row' in item for item in st.session_state.ocr_data)
|
|
|
|
|
- method = "mineru" if has_cell_index else "cluster"
|
|
|
|
|
- else:
|
|
|
|
|
- method = analysis_method
|
|
|
|
|
-
|
|
|
|
|
- st.session_state.structure = generator.analyze_table_structure(
|
|
|
|
|
- y_tolerance=y_tolerance if method == "cluster" else 5,
|
|
|
|
|
- x_tolerance=x_tolerance if method == "cluster" else 10,
|
|
|
|
|
- min_row_height=min_row_height if method == "cluster" else 20,
|
|
|
|
|
- method=method
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- st.success(f"✅ 分析完成(使用 {method} 算法)")
|
|
|
|
|
|
|
+ # 如果生成了结构(点击了分析按钮),更新 session_state
|
|
|
|
|
+ if structure:
|
|
|
|
|
+ st.session_state.structure = structure
|
|
|
|
|
+
|
|
|
|
|
+ # 渲染视图
|
|
|
|
|
+ if 'structure' in st.session_state and st.session_state.structure:
|
|
|
|
|
+ render_table_structure_view(
|
|
|
|
|
+ st.session_state.structure,
|
|
|
|
|
+ st.session_state.image,
|
|
|
|
|
+ line_width,
|
|
|
|
|
+ display_mode,
|
|
|
|
|
+ zoom_level,
|
|
|
|
|
+ show_line_numbers,
|
|
|
|
|
+ VIEWPORT_WIDTH,
|
|
|
|
|
+ VIEWPORT_HEIGHT
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ create_save_section(
|
|
|
|
|
+ "new",
|
|
|
|
|
+ st.session_state.structure,
|
|
|
|
|
+ st.session_state.image,
|
|
|
|
|
+ line_width,
|
|
|
|
|
+ TABLE_EDITOR_CONFIG["output"]
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
return
|
|
return
|
|
|
|
|
|
|
@@ -280,7 +269,7 @@ def create_table_line_editor():
|
|
|
|
|
|
|
|
render_table_structure_view(
|
|
render_table_structure_view(
|
|
|
st.session_state.structure,
|
|
st.session_state.structure,
|
|
|
- image,
|
|
|
|
|
|
|
+ image or Image.new('RGB', (2000, 2000), 'white'),
|
|
|
line_width,
|
|
line_width,
|
|
|
display_mode,
|
|
display_mode,
|
|
|
zoom_level,
|
|
zoom_level,
|
|
@@ -289,7 +278,7 @@ def create_table_line_editor():
|
|
|
VIEWPORT_HEIGHT
|
|
VIEWPORT_HEIGHT
|
|
|
)
|
|
)
|
|
|
create_save_section(
|
|
create_save_section(
|
|
|
- work_mode,
|
|
|
|
|
|
|
+ "edit",
|
|
|
st.session_state.structure,
|
|
st.session_state.structure,
|
|
|
image,
|
|
image,
|
|
|
line_width,
|
|
line_width,
|