чистый pdfplumber (camelot/tabula дают мусор), v1.36
This commit is contained in:
+8
-34
@@ -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,18 +139,16 @@ 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:
|
result["elements"].append({
|
||||||
result["elements"].append({
|
"type": "table",
|
||||||
"type": "table",
|
"rows": tbl,
|
||||||
"rows": tbl,
|
"page": pn,
|
||||||
"page": pn,
|
})
|
||||||
})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
result["errors"].append(f"pdfplumber: {e}")
|
result["errors"].append(f"pdfplumber: {e}")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|||||||
Reference in New Issue
Block a user