Skip to content

Commit

Permalink
refactor: Rename, add type annotations, remove redundant code, and so on
Browse files Browse the repository at this point in the history
  • Loading branch information
Tql-ws1 committed Feb 25, 2025
1 parent 572f29e commit b2fbd2b
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 160 deletions.
2 changes: 1 addition & 1 deletion babeldoc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
CACHE_FOLDER = Path.home() / ".cache" / "babeldoc"


def get_cache_file_path(filename):
def get_cache_file_path(filename: str) -> Path:
return CACHE_FOLDER / filename


Expand Down
12 changes: 6 additions & 6 deletions babeldoc/document_il/midend/paragraph_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ def get_layout(
self,
char: PdfCharacter,
page: Page,
xy_mode: Literal["topleft"]
| Literal["bottomright"]
| Literal["middle"] = "middle",
xy_mode: (
Literal["topleft"] | Literal["bottomright"] | Literal["middle"]
) = "middle",
):
tl, br, md = [
self._get_layout(char, page, mode)
Expand All @@ -279,9 +279,9 @@ def _get_layout(
self,
char: PdfCharacter,
page: Page,
xy_mode: Literal["topleft"]
| Literal["bottomright"]
| Literal["middle"] = "middle",
xy_mode: (
Literal["topleft"] | Literal["bottomright"] | Literal["middle"]
) = "middle",
):
# 这几个符号,解析出来的大小经常只有实际大小的一点点。
# if (
Expand Down
2 changes: 2 additions & 0 deletions babeldoc/document_il/translator/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import unicodedata
from abc import ABC
from abc import abstractmethod

import openai
import requests
Expand Down Expand Up @@ -115,6 +116,7 @@ def translate(self, text, ignore_cache=False):
self.cache.set(text, translation)
return translation

@abstractmethod
def do_translate(self, text):
"""
Actual translate text, override this method
Expand Down
4 changes: 1 addition & 3 deletions babeldoc/docvision/doclayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ def load_available():
@abc.abstractmethod
def stride(self) -> int:
"""Stride of the model input."""
pass

@abc.abstractmethod
def predict(self, image, imgsz=1024, **kwargs) -> list:
def predict(self, image: bytes, imgsz: int = 1024, **kwargs) -> list[int]:
"""
Predict the layout of a document page.
Expand All @@ -40,7 +39,6 @@ def predict(self, image, imgsz=1024, **kwargs) -> list:
imgsz: Resize the image to this size. Must be a multiple of the stride.
**kwargs: Additional arguments.
"""
pass


class YoloResult:
Expand Down
Loading

0 comments on commit b2fbd2b

Please sign in to comment.