feat(kb-workflow): 优化OCR处理逻辑
- 无论content步骤有没有字幕,都执行ocr步骤 - ocr超时设置为30分钟(1800秒) - 如果没有字幕文件但有视频文件,使用视频作为ocr源
This commit is contained in:
@@ -425,19 +425,19 @@ def call_content_agent(platform: str, meta_file: Path, content_dir: Path) -> Dic
|
|||||||
return call_subagent(agent_id, task, timeout=600)
|
return call_subagent(agent_id, task, timeout=600)
|
||||||
|
|
||||||
|
|
||||||
def call_ocr_processor(subtitle_file: Path, content_dir: Path) -> Dict[str, Any]:
|
def call_ocr_processor(source_file: Path, content_dir: Path, timeout: int = 1800) -> Dict[str, Any]:
|
||||||
"""调用 OCR 处理"""
|
"""调用 OCR 处理"""
|
||||||
task = f"""处理字幕文件,提取文字内容:
|
task = f"""处理文件,提取文字内容:
|
||||||
|
|
||||||
字幕文件: {subtitle_file}
|
源文件: {source_file}
|
||||||
输出目录: {content_dir}
|
输出目录: {content_dir}
|
||||||
|
|
||||||
请读取字幕文件,将内容转换为纯文本。
|
请读取文件,提取文字内容。
|
||||||
输出文件名格式: {{platform}}_{{id}}.txt
|
输出文件名格式: {{platform}}_{{id}}.txt
|
||||||
|
|
||||||
返回结果时告诉我输出文件的完整路径。"""
|
返回结果时告诉我输出文件的完整路径。"""
|
||||||
|
|
||||||
return call_subagent(OCR_AGENT, task, timeout=120)
|
return call_subagent(OCR_AGENT, task, timeout=timeout)
|
||||||
|
|
||||||
|
|
||||||
def call_deep_analyzer(meta_file: Path, text_file: Path, analyzed_dir: Path) -> Dict[str, Any]:
|
def call_deep_analyzer(meta_file: Path, text_file: Path, analyzed_dir: Path) -> Dict[str, Any]:
|
||||||
@@ -612,18 +612,26 @@ def process_url(url: str, base_path: Path = None) -> Dict[str, Any]:
|
|||||||
|
|
||||||
# OCR
|
# OCR
|
||||||
text_file = None
|
text_file = None
|
||||||
if subtitle_file:
|
print(f"\n{'='*50}")
|
||||||
print(f"\n{'='*50}")
|
print(f"步骤5: OCR处理 (kb-ocr-processor)")
|
||||||
print(f"步骤5: OCR处理 (kb-ocr-processor)")
|
print(f"{'='*50}")
|
||||||
print(f"{'='*50}")
|
|
||||||
|
# 无论有没有字幕,都尝试OCR处理
|
||||||
ocr_result = call_ocr_processor(Path(subtitle_file), dirs["content"])
|
ocr_source = subtitle_file
|
||||||
|
if not ocr_source and video_file:
|
||||||
|
ocr_source = video_file
|
||||||
|
|
||||||
|
if ocr_source:
|
||||||
|
# OCR超时设置为30分钟
|
||||||
|
ocr_result = call_ocr_processor(Path(ocr_source), dirs["content"], timeout=1800)
|
||||||
text_file = ocr_result.get("output_file") if ocr_result.get("success") else None
|
text_file = ocr_result.get("output_file") if ocr_result.get("success") else None
|
||||||
|
|
||||||
if text_file:
|
if text_file:
|
||||||
result["stages"].append({"stage": "ocr", "file": text_file})
|
result["stages"].append({"stage": "ocr", "file": text_file})
|
||||||
|
else:
|
||||||
|
print(f"OCR处理未生成文件")
|
||||||
else:
|
else:
|
||||||
print(f"\n无字幕文件,跳过OCR处理")
|
print(f"无字幕文件,跳过OCR处理")
|
||||||
|
|
||||||
# 深度分析
|
# 深度分析
|
||||||
print(f"\n{'='*50}")
|
print(f"\n{'='*50}")
|
||||||
|
|||||||
Reference in New Issue
Block a user