# /// script # dependencies = [ # "transformers>=4.49", "accelerate", "torch", "pillow", "qwen-vl-utils", # "numpy", "huggingface_hub", "hf-transfer", # ] # requires-python = ">=3.11,<3.13" # /// # Demo: Handicate identifies images AND learns a new concept on the fly. # hf jobs uv run -d --flavor a10g-large --timeout 30m --python 3.11 -s HF_TOKEN ./jobs/see.py import os os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1" import sys from pathlib import Path # pull the framework code (vision module lives in core/) 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": # a distinctive custom shape (two overlapping triangles) 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": # same logo, slightly shifted (a new sighting) 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: # an unrelated image 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))