fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -4,11 +4,10 @@ InsightFlow Image Processor - Phase 7
|
||||
图片处理模块:识别白板、PPT、手写笔记等内容
|
||||
"""
|
||||
|
||||
import os
|
||||
import io
|
||||
import uuid
|
||||
import base64
|
||||
from typing import List, Optional, Tuple
|
||||
import io
|
||||
import os
|
||||
import uuid
|
||||
from dataclasses import dataclass
|
||||
|
||||
# 尝试导入图像处理库
|
||||
@@ -42,7 +41,7 @@ class ImageEntity:
|
||||
name: str
|
||||
type: str
|
||||
confidence: float
|
||||
bbox: Optional[Tuple[int, int, int, int]] = None # (x, y, width, height)
|
||||
bbox: tuple[int, int, int, int] | None = None # (x, y, width, height)
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -63,8 +62,8 @@ class ImageProcessingResult:
|
||||
image_type: str # whiteboard, ppt, handwritten, screenshot, other
|
||||
ocr_text: str
|
||||
description: str
|
||||
entities: List[ImageEntity]
|
||||
relations: List[ImageRelation]
|
||||
entities: list[ImageEntity]
|
||||
relations: list[ImageRelation]
|
||||
width: int
|
||||
height: int
|
||||
success: bool
|
||||
@@ -75,7 +74,7 @@ class ImageProcessingResult:
|
||||
class BatchProcessingResult:
|
||||
"""批量图片处理结果"""
|
||||
|
||||
results: List[ImageProcessingResult]
|
||||
results: list[ImageProcessingResult]
|
||||
total_count: int
|
||||
success_count: int
|
||||
failed_count: int
|
||||
@@ -231,7 +230,7 @@ class ImageProcessor:
|
||||
print(f"Image type detection error: {e}")
|
||||
return "other"
|
||||
|
||||
def perform_ocr(self, image, lang: str = "chi_sim+eng") -> Tuple[str, float]:
|
||||
def perform_ocr(self, image, lang: str = "chi_sim+eng") -> tuple[str, float]:
|
||||
"""
|
||||
对图片进行OCR识别
|
||||
|
||||
@@ -262,7 +261,7 @@ class ImageProcessor:
|
||||
print(f"OCR error: {e}")
|
||||
return "", 0.0
|
||||
|
||||
def extract_entities_from_text(self, text: str) -> List[ImageEntity]:
|
||||
def extract_entities_from_text(self, text: str) -> list[ImageEntity]:
|
||||
"""
|
||||
从OCR文本中提取实体
|
||||
|
||||
@@ -322,7 +321,7 @@ class ImageProcessor:
|
||||
|
||||
return unique_entities
|
||||
|
||||
def generate_description(self, image_type: str, ocr_text: str, entities: List[ImageEntity]) -> str:
|
||||
def generate_description(self, image_type: str, ocr_text: str, entities: list[ImageEntity]) -> str:
|
||||
"""
|
||||
生成图片描述
|
||||
|
||||
@@ -435,7 +434,7 @@ class ImageProcessor:
|
||||
error_message=str(e),
|
||||
)
|
||||
|
||||
def _extract_relations(self, entities: List[ImageEntity], text: str) -> List[ImageRelation]:
|
||||
def _extract_relations(self, entities: list[ImageEntity], text: str) -> list[ImageRelation]:
|
||||
"""
|
||||
从文本中提取实体关系
|
||||
|
||||
@@ -475,7 +474,7 @@ class ImageProcessor:
|
||||
|
||||
return relations
|
||||
|
||||
def process_batch(self, images_data: List[Tuple[bytes, str]], project_id: str = None) -> BatchProcessingResult:
|
||||
def process_batch(self, images_data: list[tuple[bytes, str]], project_id: str = None) -> BatchProcessingResult:
|
||||
"""
|
||||
批量处理图片
|
||||
|
||||
@@ -515,7 +514,7 @@ class ImageProcessor:
|
||||
"""
|
||||
return base64.b64encode(image_data).decode("utf-8")
|
||||
|
||||
def get_image_thumbnail(self, image_data: bytes, size: Tuple[int, int] = (200, 200)) -> bytes:
|
||||
def get_image_thumbnail(self, image_data: bytes, size: tuple[int, int] = (200, 200)) -> bytes:
|
||||
"""
|
||||
生成图片缩略图
|
||||
|
||||
|
||||
Reference in New Issue
Block a user