чистый pdfplumber (camelot/tabula дают мусор), v1.36

This commit is contained in:
2026-06-17 22:09:26 +04:00
parent a150d3f2a8
commit 44ce0e09ab
2 changed files with 9 additions and 35 deletions
+8 -34
View File
@@ -123,30 +123,6 @@ def _parse_doc(file_bytes: bytes) -> dict:
def _parse_pdf(file_bytes: bytes) -> dict:
result = {"elements": [], "errors": []}
# Попробовать camelot (pdfium, без системных зависимостей)
tables_from_camelot = False
try:
import camelot
for flavor in ("lattice", "stream"):
try:
ctables = camelot.read_pdf(io.BytesIO(file_bytes), pages="all", flavor=flavor)
for ct in ctables:
rows = [list(ct.df.columns)] + ct.df.values.tolist()
result["elements"].append({
"type": "table",
"rows": rows,
"page": ct.page,
})
tables_from_camelot = True
except Exception:
pass
except ImportError:
result["errors"].append("camelot not installed, using pdfplumber")
except Exception as e:
result["errors"].append(f"camelot error: {e}")
# pdfplumber: текст + таблицы (если tabula не сработал)
try:
import pdfplumber
with pdfplumber.open(io.BytesIO(file_bytes)) as pdf:
@@ -163,18 +139,16 @@ def _parse_pdf(file_bytes: bytes) -> dict:
"text": line,
"page": pn,
})
if not tables_from_camelot:
tables = page.extract_tables()
for tbl in tables:
if tbl:
result["elements"].append({
"type": "table",
"rows": tbl,
"page": pn,
})
tables = page.extract_tables()
for tbl in tables:
if tbl:
result["elements"].append({
"type": "table",
"rows": tbl,
"page": pn,
})
except Exception as e:
result["errors"].append(f"pdfplumber: {e}")
return result
+1 -1
View File
@@ -59,7 +59,7 @@
<body>
<div class="topbar">
<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.35</span></span>
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.36</span></span>
</div>
<div class="content">