"""Parcours complet avec votre photo (propositions sûres seulement, rien de nouveau n'est créé) : python test_facing_flow.py photo.jpg [http://127.0.0.1:2001] ATTENTION : « finish » augmente les compteurs cumulés de la base -> utilisez une copie (kb_session).""" import base64 import sys import time import requests path = sys.argv[1] base = (sys.argv[2] if len(sys.argv) > 2 else "http://127.0.0.1:2001").rstrip("/") + "/facing" def show(st): print(f" phase={st['phase']} | inconnus restants={st['unknown_left']} | comptage=" f"{[(c['name'], c['count']) for c in st['counts']]}") b64 = base64.b64encode(open(path, "rb").read()).decode() job = requests.post(f"{base}/analyze", json={"image": b64}, timeout=60).json()["job_id"] while True: j = requests.get(f"{base}/jobs/{job}", timeout=10).json() print(f"analyse {j['status']} {j['progress']} %") if j["status"] != "processing": break time.sleep(1) if j["status"] != "done": sys.exit(f"ECHEC : {j['error']}") st = j["results"] sid = st["session_id"] show(st) if st["phase"] == "review": choices = [] for g in st["groups"]: if g["pick"] is not None and g["pick"] >= 0: sug = g["suggest"][g["pick"]] print(f" groupe {g['id'] + 1} ({len(g['box_ids'])} facings) -> {sug['name']} ({sug['source']})") choices.append({"group": g["id"], "kind": "existing", "sku": sug["sku"]}) else: print(f" groupe {g['id'] + 1} ({len(g['box_ids'])} facings) -> plus tard") choices.append({"group": g["id"], "kind": "later"}) r = requests.post(f"{base}/{sid}/review", json={"choices": choices}, timeout=60) print("revue :", r.status_code) st = r.json() show(st) if st["phase"] == "resolve": print(f"{st['unknown_left']} produit(s) restent INCONNUS (à traiter sur le téléphone) -> terminer") r = requests.post(f"{base}/{sid}/finish", timeout=60) st = r.json() show(st) print("\n=== Facings dans cette photo ===") for c in st["counts"]: print(f"{c['name']}: {c['count']}{' [NOUVEAU]' if c['new'] else ''} (cumul : {c['cumul']} facings sur {c['photos']} photos)") if st["unknown_left"]: print(f"\nProduits restés INCONNUS (non comptés) : {st['unknown_left']}")