import requests, re, json, os H = "https://huggingface.co" from pymupdf import Document as MuDoc def norm(s): return re.sub(r'[^0-9]','',str(s)) # Simulate frontend search + verify each returned Imudex product's image maps to the # correct column-aware region on its page (the exact fix logic). pdf=requests.get(H+"/datasets/bep40/grob-products-updated/resolve/main/pdfs/imudex_2026.pdf", timeout=600).content open("/tmp/imudex.pdf","wb").write(pdf) doc=MuDoc("/tmp/imudex.pdf") # page images per pdf index def page_imgs(pgn): pg=doc[pgn]; out=[] for ip in pg.get_image_info(): bb=ip["bbox"]; w=ip.get("width") or 0; h=ip.get("height") or 0 if w>=160 and h>=110: out.append({"x0":bb[0],"y0":bb[1],"x1":bb[2],"y1":bb[3],"w":w,"h":h}) return out PAGE_IMGS={pgn:page_imgs(pgn) for pgn in range(len(doc))} def side(x): return 'L' if x<567 else 'R' def expected_img(sku_page_no, code_x, code_y): # find the image whose column matches code side, nearest vertically pgn=sku_page_no-1 imgs=PAGE_IMGS[pgn]; s=side(code_x) cand=[im for im in imgs if side((im["x0"]+im["x1"])/2)==s] if not cand: return None bd=1e15; best=None for im in cand: icy=(im["y0"]+im["y1"])/2 dd=abs(icy-code_y) if dd img bbox {[round(im['x0']),round(im['y0']),round(im['x1']),round(im['y1'])] if im else None} label={ 'L' if row[0]<567 else 'R'}")