camelot-py 2.0 (pdfium, без Ghostscript/OpenCV), v1.31

This commit is contained in:
2026-06-17 21:31:37 +04:00
parent e613716178
commit 6187e4dee8
3 changed files with 21 additions and 16 deletions
+1 -1
View File
@@ -5,6 +5,6 @@ requests
psycopg2-binary psycopg2-binary
python-dotenv python-dotenv
pdfplumber pdfplumber
tabula-py camelot-py>=2.0
httpx httpx
h2 h2
+19 -14
View File
@@ -124,22 +124,27 @@ def _parse_doc(file_bytes: bytes) -> dict:
def _parse_pdf(file_bytes: bytes) -> dict: def _parse_pdf(file_bytes: bytes) -> dict:
result = {"elements": [], "errors": []} result = {"elements": [], "errors": []}
# Попробовать tabula (Java) — точнее таблицы # Попробовать camelot (pdfium, без системных зависимостей)
tables_from_tabula = False tables_from_camelot = False
try: try:
import tabula import camelot
tables = tabula.read_pdf(io.BytesIO(file_bytes), pages="all", multiple_tables=True) for flavor in ("lattice", "stream"):
for tbl in tables: try:
rows = [list(tbl.columns)] + tbl.values.tolist() ctables = camelot.read_pdf(io.BytesIO(file_bytes), pages="all", flavor=flavor)
result["elements"].append({ for ct in ctables:
"type": "table", rows = [list(ct.df.columns)] + ct.df.values.tolist()
"rows": rows, result["elements"].append({
}) "type": "table",
tables_from_tabula = len(tables) > 0 "rows": rows,
"page": ct.page,
})
tables_from_camelot = True
except Exception:
pass
except ImportError: except ImportError:
result["errors"].append("tabula not installed, using pdfplumber") result["errors"].append("camelot not installed, using pdfplumber")
except Exception as e: except Exception as e:
result["errors"].append(f"tabula error: {e}") result["errors"].append(f"camelot error: {e}")
# pdfplumber: текст + таблицы (если tabula не сработал) # pdfplumber: текст + таблицы (если tabula не сработал)
try: try:
@@ -158,7 +163,7 @@ def _parse_pdf(file_bytes: bytes) -> dict:
"text": line, "text": line,
"page": pn, "page": pn,
}) })
if not tables_from_tabula: if not tables_from_camelot:
tables = page.extract_tables() tables = page.extract_tables()
for tbl in tables: for tbl in tables:
if tbl: if tbl:
+1 -1
View File
@@ -59,7 +59,7 @@
<body> <body>
<div class="topbar"> <div class="topbar">
<img src="{{ url_for('static', filename='nubes-logo.svg') }}" alt="Nubes"> <img src="{{ url_for('static', filename='nubes-logo.svg') }}" alt="Nubes">
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.30</span></span> <span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.31</span></span>
</div> </div>
<div class="content"> <div class="content">