|
|
@@ -33,13 +33,18 @@ def create_directory_selector(
|
|
|
"""
|
|
|
st.sidebar.subheader("目录模式")
|
|
|
|
|
|
- source_names = [src["name"] for src in data_sources]
|
|
|
- selected_name = st.sidebar.selectbox(
|
|
|
+ # 使用 description 作为显示名称 (如果不存在则使用 name)
|
|
|
+ source_options = [src.get("description", src["name"]) for src in data_sources]
|
|
|
+
|
|
|
+ selected_option = st.sidebar.selectbox(
|
|
|
"选择数据源",
|
|
|
- source_names,
|
|
|
+ source_options,
|
|
|
key="dir_mode_source"
|
|
|
)
|
|
|
- source_cfg = next(src for src in data_sources if src["name"] == selected_name)
|
|
|
+
|
|
|
+ # 根据选择的选项找到对应的配置
|
|
|
+ selected_index = source_options.index(selected_option)
|
|
|
+ source_cfg = data_sources[selected_index]
|
|
|
|
|
|
# 🔑 保存当前选择的数据源配置到 session_state
|
|
|
if "current_data_source" not in st.session_state or st.session_state.current_data_source != source_cfg:
|
|
|
@@ -53,10 +58,10 @@ def create_directory_selector(
|
|
|
output_dir = Path(output_cfg.get("directory", "output/table_structures"))
|
|
|
structure_suffix = output_cfg.get("structure_suffix", "_structure.json")
|
|
|
|
|
|
- # 🔑 获取工具类型
|
|
|
- tool = source_cfg.get("tool", "ppstructv3")
|
|
|
- st.session_state.current_tool = tool
|
|
|
- st.sidebar.info(f"🔧 工具: {tool.upper()}")
|
|
|
+ # 🔑 获取数据格式 (json_format > 默认)
|
|
|
+ json_format = source_cfg.get("json_format", "ppstructure")
|
|
|
+ st.session_state.current_json_format = json_format
|
|
|
+ st.sidebar.info(f"🔧 格式: {json_format.upper()}")
|
|
|
|
|
|
# 构建/缓存目录清单
|
|
|
catalog_key = f"catalog::{source_cfg['json_dir']}"
|
|
|
@@ -96,7 +101,8 @@ def create_directory_selector(
|
|
|
st.session_state.current_catalog_index = selected
|
|
|
|
|
|
# 🔑 关键优化:只在切换文件时才重新加载
|
|
|
- current_entry_key = f"{selected_name}::{catalog[selected]['json']}"
|
|
|
+ # 使用 json 文件名作为唯一键的一部分
|
|
|
+ current_entry_key = f"{source_cfg['name']}::{catalog[selected]['json'].name}"
|
|
|
|
|
|
if ('last_loaded_entry' not in st.session_state or
|
|
|
st.session_state.last_loaded_entry != current_entry_key):
|
|
|
@@ -106,7 +112,7 @@ def create_directory_selector(
|
|
|
output_dir,
|
|
|
structure_suffix,
|
|
|
current_entry_key,
|
|
|
- tool # 🔑 传入工具类型
|
|
|
+ json_format=json_format # 🔑 传入格式类型
|
|
|
)
|
|
|
|
|
|
# 页码跳转处理
|
|
|
@@ -127,7 +133,7 @@ def _load_catalog_entry(
|
|
|
output_dir: Path,
|
|
|
structure_suffix: str,
|
|
|
entry_key: str,
|
|
|
- tool: str = "ppstructv3" # 🔑 新增参数
|
|
|
+ json_format: str = "ppstructure"
|
|
|
):
|
|
|
"""
|
|
|
加载目录条目(JSON + 图片 + 结构)
|
|
|
@@ -137,7 +143,7 @@ def _load_catalog_entry(
|
|
|
output_dir: 输出目录
|
|
|
structure_suffix: 结构文件后缀
|
|
|
entry_key: 条目唯一键
|
|
|
- tool: 工具类型
|
|
|
+ json_format: 数据格式类型 (如 "mineru", "ppstructure")
|
|
|
"""
|
|
|
base_name = entry["json"].stem
|
|
|
structure_file = output_dir / f"{base_name}{structure_suffix}"
|
|
|
@@ -149,12 +155,12 @@ def _load_catalog_entry(
|
|
|
raw = json.load(fp)
|
|
|
|
|
|
# 🔑 根据工具类型解析数据
|
|
|
- table_bbox, ocr_data = TableLineGenerator.parse_ocr_data(raw, tool=tool)
|
|
|
+ table_bbox, ocr_data = TableLineGenerator.parse_ocr_data(raw, json_format=json_format)
|
|
|
|
|
|
st.session_state.ocr_data = ocr_data
|
|
|
st.session_state.table_bbox = table_bbox
|
|
|
st.session_state.loaded_json_name = entry["json"].name
|
|
|
- st.info(f"🔧 使用 {tool.upper()} 解析 JSON")
|
|
|
+ st.info(f"🔧 使用 {json_format.upper()} 解析 JSON")
|
|
|
|
|
|
except Exception as e:
|
|
|
st.error(f"❌ 加载 JSON 失败: {e}")
|