Datasets:
Download scripts/dump_p81.py from bep40/grob-products-updated: direct link, hf CLI and curl.
- Browser
- Download file 983 Bytes
-
https://huggingface.co/datasets/bep40/grob-products-updated/resolve/main/scripts/dump_p81.py
- Command line
-
hf download hf://datasets/bep40/grob-products-updated/scripts/dump_p81.py
-
curl -L -o dump_p81.py https://huggingface.co/datasets/bep40/grob-products-updated/resolve/main/scripts/dump_p81.py
983 Bytes
| import requests, re, os | |
| 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") | |
| pg = doc[80] | |
| 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((round(x0,1), round(y0,1), round(x1,1), round(y1,1), txt)) | |
| lines.sort(key=lambda t: (t[1], t[0])) | |
| for x0,y0,x1,y1,txt in lines: | |
| # only left column (x<567) top region to keep output small, plus anything with keywords | |
| if x0 < 567 or re.search(r'Tên hàng|Mã số|Giá bán|Kích thước|Chiều rộng|7 801|7 804|I M U|Kệ|Giá', txt, re.I): | |
| print(f"y={y0:7.1f} x={x0:6.1f}-{x1:6.1f} | {txt}") | |
| print("PAGE 81 done") |