Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
ARG REPOSITORY="docker.io"
FROM dedocproject/dedoc_jammy_p3.10_base:version_2025_09_11
ARG LANGUAGES=""
FROM dedocproject/dedoc_p3.10_base:version_2026_07_29
ARG LANGUAGES="rus"
RUN for lang in $LANGUAGES; do apt install -y tesseract-ocr-$(echo $lang | tr "_" "-"); done

ENV PYTHONPATH "${PYTHONPATH}:/dedoc_root"
ENV RESOURCES_PATH "/dedoc_root/resources"

COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --no-cache-dir torch~=2.6.0 torchvision~=0.21.0 --index-url https://download.pytorch.org/whl/cpu
RUN pip3 install --no-cache-dir transformers~=4.49.0
RUN apt-get update && apt-get install -y --fix-missing --no-install-recommends fontforge
RUN apt install -y libutf8proc-dev
RUN ln -s /usr/lib/x86_64-linux-gnu/libutf8proc.so /usr/lib/libutf8proc.so.1

RUN mkdir /dedoc_root
RUN mkdir /dedoc_root/dedoc
Expand Down
12 changes: 11 additions & 1 deletion dedoc/data_structures/tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,19 @@ def add_text(self, line: LineWithMeta) -> None:

@staticmethod
def __shift_annotations(line: LineWithMeta, text_length: int) -> List[Annotation]:
from dedoc.data_structures.concrete_annotations.attach_annotation import AttachAnnotation
from dedoc.data_structures.concrete_annotations.table_annotation import TableAnnotation

new_annotations = []
for annotation in line.annotations:
new_annotation = Annotation(start=annotation.start + text_length, end=annotation.end + text_length, name=annotation.name, value=annotation.value)
start = annotation.start + text_length
end = annotation.end + text_length
if annotation.name == TableAnnotation.name:
new_annotation = TableAnnotation(value=annotation.value, start=start, end=end)
elif annotation.name == AttachAnnotation.name:
new_annotation = AttachAnnotation(attach_uid=annotation.value, start=start, end=end)
else:
new_annotation = Annotation(start=start, end=end, name=annotation.name, value=annotation.value, is_mergeable=annotation.is_mergeable)
new_annotations.append(new_annotation)
return new_annotations

Expand Down
13 changes: 7 additions & 6 deletions dedoc/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
archive_like_format={},
image_like_format={
"image/bmp", "image/x-ms-bmp", "image/dib", "image/x-eps", "application/postscript", "image/gif", "image/jpeg", "image/jp2", "image/x-jp2", "image/jpg",
"image/x-portable-pixmap", "image/x-portable-anymap", "image/x-portable-graymap", "image/x-portable-bitmap", "image/x-pcx", "image/x-pict",
"image/ras", "image/x-sun-raster", "image/sgi", "image/x-sgi", "image/tiff", "image/webp", "image/x-cmu-raster", "image/x-jp2-codestream"
"image/x-portable-pixmap", "image/x-portable-anymap", "image/x-portable-graymap", "image/x-portable-bitmap", "image/x-pcx", "image/vnd.zbrush.pcx",
"image/x-pict", "image/ras", "image/x-sun-raster", "image/sgi", "image/x-sgi", "image/tiff", "image/webp", "image/x-cmu-raster",
"image/x-jp2-codestream"
},
pdf_like_format={"image/vnd.djvu"},
csv_like_format={},
Expand Down Expand Up @@ -79,7 +80,7 @@
mhtml_like_format={"message/rfc822"},
archive_like_format={
"application/zip", "application/x-gzip", "application/gzip", "application/x-tar", "application/x-rar-compressed", "application/rar",
"application/x-rar", "application/x-7z-compressed"
"application/vnd.rar", "application/x-rar", "application/x-7z-compressed"
},
image_like_format={"image/png"},
pdf_like_format={"application/pdf"},
Expand All @@ -105,13 +106,13 @@
"message/rfc822": ".eml",
# archive
"application/x-gzip": ".gz", "application/gzip": ".gz", "application/x-rar-compressed": ".rar", "application/rar": ".rar", "application/x-tar": ".tar",
"application/x-rar": ".rar", "application/x-7z-compressed": ".7z", "application/zip": ".zip",
"application/vnd.rar": ".rar", "application/x-rar": ".rar", "application/x-7z-compressed": ".7z", "application/zip": ".zip",
# image
"image/x-ms-bmp": ".bmp", "image/sgi": ".sgi", "image/jpeg": ".jpg", "image/x-jp2": ".jp2", "image/x-portable-graymap": ".pgm", "image/x-pict": ".pic",
"image/gif": ".gif", "image/x-sgi": ".sgi", "image/x-sun-raster": ".ras", "image/x-eps": ".eps", "image/bmp": ".bmp", "image/x-portable-bitmap": ".pbm",
"image/webp": ".webp", "application/postscript": ".eps", "image/jpg": ".jpg", "image/x-jp2-codestream": "jp2", "image/x-portable-pixmap": ".ppm",
"image/jp2": ".jp2", "image/dib": ".dib", "image/x-pcx": ".pcx", "image/tiff": ".tiff", "image/x-cmu-raster": ".ras", "image/ras": ".ras",
"image/x-portable-anymap": ".pnm", "image/png": ".png",
"image/jp2": ".jp2", "image/dib": ".dib", "image/x-pcx": ".pcx", "image/vnd.zbrush.pcx": ".pcx", "image/tiff": ".tiff", "image/x-cmu-raster": ".ras",
"image/ras": ".ras", "image/x-portable-anymap": ".pnm", "image/png": ".png",
# pdf
"image/vnd.djvu": ".djvu", "application/pdf": ".pdf",
# csv
Expand Down
20 changes: 9 additions & 11 deletions docker_gpu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
ARG REPOSITORY="docker.io"
FROM dedocproject/dedoc_jammy_p3.10_base:version_2025_09_11
FROM dedocproject/dedoc_p3.10_base:version_2026_07_29
ARG LANGUAGES="rus"
RUN for lang in $LANGUAGES; do apt install -y tesseract-ocr-$(echo $lang | tr "_" "-"); done

ENV PYTHONPATH "${PYTHONPATH}:/dedoc_root"
ENV RESOURCES_PATH "/dedoc_root/resources"

ADD requirements.txt .
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html
RUN pip3 install --no-cache-dir transformers~=4.49.0

RUN mkdir /dedoc_root
RUN mkdir /dedoc_root/dedoc
ADD dedoc/config.py /dedoc_root/dedoc/config.py
ADD dedoc/download_models.py /dedoc_root/dedoc/download_models.py
COPY dedoc/config.py /dedoc_root/dedoc/config.py
COPY dedoc/download_models.py /dedoc_root/dedoc/download_models.py
RUN python3 /dedoc_root/dedoc/download_models.py

ADD dedoc /dedoc_root/dedoc
ADD VERSION /dedoc_root
COPY dedoc /dedoc_root/dedoc
COPY VERSION /dedoc_root
RUN echo "__version__ = \"$(cat /dedoc_root/VERSION)\"" > /dedoc_root/dedoc/version.py

ADD tests /dedoc_root/tests
ADD resources /dedoc_root/resources

CMD ["python3", "/dedoc_root/dedoc/main.py"]
CMD ["python3", "/dedoc_root/dedoc/main.py"]
5 changes: 3 additions & 2 deletions labeling/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
ARG REPOSITORY="docker.io"
FROM dedocproject/dedoc_jammy_p3.10_base:version_2025_09_11
FROM dedocproject/dedoc_p3.10_base:version_2026_07_29
RUN apt-get install -y tesseract-ocr-rus

ENV PYTHONPATH "${PYTHONPATH}:/labeling_root:/labeling_root/labeling"
ENV RESOURCES_PATH "/labeling_root/resources"

ADD requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --no-cache-dir torch~=2.6.0 torchvision~=0.21.0 --index-url https://download.pytorch.org/whl/cpu
RUN pip3 install Jinja2==3.1.2

RUN mkdir /labeling_root
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ huggingface-hub>=0.14.1,<1.0
imutils==0.5.4
itsdangerous>=2.1.0,<=2.1.2
levenshtein>=0.12.2,<1
numpy>=1.22.0,<2.0
olefile~=0.46
opencv-python>=4.5.5.64,<4.6.0
orjson>=3.8.11,<4.0
Expand All @@ -22,7 +21,6 @@ py7zr~=1.0
pypdf>=4.0,<6.0
pytesseract==0.3.10
python-docx==0.8.11
python-logstash-async>=2.5.0,<=2.7.0
python-magic<1.0
python-multipart==0.0.6
rarfile==4.0
Expand Down
6 changes: 3 additions & 3 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
ARG REPOSITORY="docker.io"
FROM dedocproject/dedoc_jammy_p3.10_base:version_2025_09_11
FROM dedocproject/dedoc_p3.10_base:version_2026_07_29
RUN apt-get install -y tesseract-ocr-rus

ENV PYTHONPATH "${PYTHONPATH}:/dedoc_root:/dedoc_root/tests:/dedoc_root/langchain"

COPY requirements.txt .
RUN pip3 install --no-cache-dir "langchain-community<1.0"
RUN pip3 install --no-cache-dir -r requirements.txt
RUN pip3 install --no-cache-dir torch~=2.6.0 torchvision~=0.21.0 --index-url https://download.pytorch.org/whl/cpu
RUN pip3 install --no-cache-dir transformers~=4.49.0
RUN apt-get update && apt-get install -y --fix-missing --no-install-recommends fontforge

RUN mkdir /dedoc_root
COPY docs/source/_static/code_examples/langchain /dedoc_root/langchain
Expand Down
Binary file modified tests/data/file.bin
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/unit_tests/test_misc_tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from dedoc.data_structures.concrete_annotations.bold_annotation import BoldAnnotation
from dedoc.data_structures.concrete_annotations.italic_annotation import ItalicAnnotation
from dedoc.data_structures.concrete_annotations.table_annotation import TableAnnotation
from dedoc.data_structures.hierarchy_level import HierarchyLevel
from dedoc.data_structures.line_metadata import LineMetadata
from dedoc.data_structures.line_with_meta import LineWithMeta
from dedoc.data_structures.tree_node import TreeNode
from dedoc.utils.annotation_merger import AnnotationMerger


class TestTreeNode(TestCase):
Expand Down Expand Up @@ -34,3 +36,21 @@ def test_root_node_annotations(self) -> None:
self.assertEqual("True", italic.value)
self.assertEqual(10, italic.start)
self.assertEqual(22, italic.end)

def test_add_text_keeps_multiple_tables_after_merge(self) -> None:
"""Two tables on a glued line must both survive add_text and AnnotationMerger."""
hl = HierarchyLevel.create_raw_text()
first = LineWithMeta(line="Начало ", metadata=LineMetadata(hierarchy_level=hl, page_id=0, line_id=0))
tables = [TableAnnotation(value="t1", start=0, end=5), TableAnnotation(value="t2", start=0, end=5)]
second = LineWithMeta(line="текст", metadata=LineMetadata(hierarchy_level=hl, page_id=0, line_id=1), annotations=tables)
node = TreeNode.create(lines=[first])
node.add_text(second)

table_anns = [ann for ann in node.annotations if ann.name == TableAnnotation.name]
self.assertEqual(2, len(table_anns))
self.assertTrue(all(isinstance(ann, TableAnnotation) for ann in table_anns))
self.assertTrue(all(ann.is_mergeable is False for ann in table_anns))

merged = AnnotationMerger().merge_annotations(node.annotations, node.text)
merged_tables = [ann for ann in merged if ann.name == TableAnnotation.name]
self.assertEqual({"t1", "t2"}, {ann.value for ann in merged_tables})
Loading