| |
| |
| |
| |
| |
| |
| |
| |
| |
| import os |
| os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1" |
| import sys |
| from pathlib import Path |
|
|
| |
| from huggingface_hub import snapshot_download |
| WORK = "/tmp/handicate" |
| snapshot_download("AmongTheCouch23/handicate-code", repo_type="dataset", local_dir=WORK) |
| sys.path.insert(0, WORK) |
|
|
| from PIL import Image, ImageDraw |
| from core.vision import VisionPerceiver, ConceptMemory |
|
|
|
|
| def make_img(path, kind): |
| im = Image.new("RGB", (224, 224), "white") |
| d = ImageDraw.Draw(im) |
| if kind == "logo": |
| d.polygon([(112, 30), (40, 190), (184, 190)], fill=(200, 30, 60)) |
| d.polygon([(112, 190), (40, 30), (184, 30)], outline=(20, 20, 120), width=8) |
| elif kind == "logo2": |
| d.polygon([(118, 36), (46, 196), (190, 196)], fill=(205, 35, 65)) |
| d.polygon([(118, 196), (46, 36), (190, 36)], outline=(25, 25, 125), width=8) |
| else: |
| d.ellipse([60, 60, 164, 164], fill=(40, 160, 90)) |
| im.save(path) |
| return path |
|
|
|
|
| a = make_img("/tmp/logo.png", "logo") |
| a2 = make_img("/tmp/logo2.png", "logo2") |
| other = make_img("/tmp/other.png", "blob") |
|
|
| vp = VisionPerceiver() |
| mem = ConceptMemory() |
|
|
| print("\n1) Identify an unknown image (VLM, no memory yet):") |
| print(" ->", vp.see(a, mem)) |
|
|
| print("\n2) Teach it on the fly:") |
| print(" ->", vp.see(a, mem, label="Owner's Handicate crest")) |
|
|
| print("\n3) See a NEW sighting of the same thing -> recognized instantly from memory:") |
| print(" ->", vp.see(a2, mem)) |
|
|
| print("\n4) An unrelated image is NOT falsely matched:") |
| print(" ->", vp.see(other, mem)) |
|
|
| print("\n5) Plain VLM identification of the unrelated image:") |
| print(" ->", vp.identify(other)) |
|
|