| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- """
- 表格结构分析控件
- """
- import streamlit as st
- from .drawing import clear_table_image_cache
- def create_analysis_section(y_tolerance: int, x_tolerance: int, min_row_height: int):
- """
- 创建分析区域
-
- Args:
- y_tolerance: Y轴聚类容差
- x_tolerance: X轴聚类容差
- min_row_height: 最小行高
- """
- if st.button("🔍 分析表格结构"):
- with st.spinner("分析中..."):
- try:
- generator = st.session_state.generator
- structure = generator.analyze_table_structure(
- y_tolerance=y_tolerance,
- x_tolerance=x_tolerance,
- min_row_height=min_row_height
- )
-
- if not structure:
- st.warning("⚠️ 未检测到表格结构")
- st.stop()
-
- structure['modified_h_lines'] = set()
- structure['modified_v_lines'] = set()
-
- st.session_state.structure = structure
- st.session_state.undo_stack = []
- st.session_state.redo_stack = []
- clear_table_image_cache()
-
- st.success(
- f"✅ 检测到 {len(structure['rows'])} 行"
- f"({len(structure['horizontal_lines'])} 条横线),"
- f"{len(structure['columns'])} 列"
- f"({len(structure['vertical_lines'])} 条竖线)"
- )
-
- col1, col2, col3, col4 = st.columns(4)
- with col1:
- st.metric("行数", len(structure['rows']))
- with col2:
- st.metric("横线数", len(structure['horizontal_lines']))
- with col3:
- st.metric("列数", len(structure['columns']))
- with col4:
- st.metric("竖线数", len(structure['vertical_lines']))
-
- except Exception as e:
- st.error(f"❌ 分析失败: {e}")
- import traceback
- st.code(traceback.format_exc())
- st.stop()
|