grob-products-updated / scripts /dump_panrack.py
bep40's picture
Upload scripts/dump_panrack.py
4af2232 verified
Raw History Blame Contribute Delete
1.76 kB
import requests, re, os, json
H = "https://huggingface.co"
from pymupdf import Document as MuDoc
pdf = requests.get(H + "/datasets/bep40/grob-products-updated/resolve/main/pdfs/imudex_2026.pdf", timeout=600).content
open("/tmp/i.pdf", "wb").write(pdf)
doc = MuDoc("/tmp/i.pdf")
# 1) full-text search for pot/pan/xoong/noi/pot rack/pan rack
pat = re.compile(r'(pot rack|pan rack|xoong|n[oòô]i|pan\s*rack|pot\s*stand|k.e\s*xoong|xoong\s*n[oòô]i)', re.I)
print("=== FULL TEXT SEARCH pot/pan/xoong/noi ===")
found = []
for pgn in range(len(doc)):
t = doc[pgn].get_text()
for m in pat.finditer(t):
s = max(0, m.start()-40); e = min(len(t), m.end()+60)
snippet = " ".join(t[s:e].split())
found.append((pgn+1, snippet[:140]))
for pgn, snip in found[:60]:
print(f"p{pgn}: ...{snip}...")
print("total matches lines:", len(found))
# 2) all image bboxes on page 81 (raw, no filter)
print("\n=== PAGE 81 ALL IMAGE BBOXES (raw) ===")
pg = doc[80]
for ip in pg.get_image_info():
bb = ip["bbox"]
w = ip.get("width") or 0; h = ip.get("height") or 0
print(f" bbox=[{round(bb[0],1)},{round(bb[1],1)},{round(bb[2],1)},{round(bb[3],1)}] size={w}x{h}")
# 3) dump ALL text lines page 81 sorted by y to see the full page structure incl. right column
print("\n=== PAGE 81 ALL TEXT (y-sorted, truncated to 160 chars) ===")
d = pg.get_text("dict")
lines = []
for b in d["blocks"]:
if b["type"] != 0:
continue
for l in b["lines"]:
txt = "".join(s["text"] for s in l["spans"]).strip()
if txt:
x0, y0, x1, y1 = l["bbox"]
lines.append((y0, x0, x1, txt[:160]))
lines.sort()
for y0, x0, x1, txt in lines:
print(f"y={y0:7.1f} x={x0:6.1f}-{x1:6.1f} | {txt}")
print("DONE")