чистый 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
-26
View File
@@ -123,30 +123,6 @@ 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": []}
# Попробовать 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: try:
import pdfplumber import pdfplumber
with pdfplumber.open(io.BytesIO(file_bytes)) as pdf: with pdfplumber.open(io.BytesIO(file_bytes)) as pdf:
@@ -163,7 +139,6 @@ def _parse_pdf(file_bytes: bytes) -> dict:
"text": line, "text": line,
"page": pn, "page": pn,
}) })
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:
@@ -174,7 +149,6 @@ def _parse_pdf(file_bytes: bytes) -> dict:
}) })
except Exception as e: except Exception as e:
result["errors"].append(f"pdfplumber: {e}") result["errors"].append(f"pdfplumber: {e}")
return result return result
+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.35</span></span> <span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.36</span></span>
</div> </div>
<div class="content"> <div class="content">