Commit 
							
							·
						
						5eca0b2
	
0
								Parent(s):
							
							
initial commit
Browse filesThis view is limited to 50 files because it contains too many changes.  
							See raw diff
- .gitattributes +37 -0
- .gitignore +4 -0
- Dockerfile +38 -0
- README.md +11 -0
- app.py +181 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġa.png +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġbicycle.png +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġnear.png +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġocean.png +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġperson.png +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġriding.png +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġthe.png +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmaps.json +0 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/image.jpg +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/img_url.txt +1 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/preview_first_token.jpg +3 -0
- examples/auto_a_person_riding_a_bicycle_near_20250702_150805/prompt.txt +1 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġa.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġdog.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġdown.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġperson.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġstreet.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġthe.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġwalking.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġwith.png +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmaps.json +0 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/image.jpg +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/img_url.txt +1 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/preview_first_token.jpg +3 -0
- examples/auto_a_person_walking_down_the_stre_20250702_152111/prompt.txt +1 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġcomputing.png +3 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġin.png +3 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġjobs.png +3 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġthe.png +3 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġus.png +3 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/heatmaps.json +0 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/image.jpg +3 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/img_url.txt +1 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/preview_first_token.jpg +3 -0
- examples/auto_computing_jobs_in_the_us_20250702_150954/prompt.txt +1 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġchart.png +3 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġcolumn.png +3 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġindex.png +3 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġlabels.png +3 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġsimple.png +3 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġwith.png +3 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/heatmaps.json +0 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/image.jpg +3 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/img_url.txt +1 -0
- examples/auto_simple_column_chart_with_index_20250702_151028/preview_first_token.jpg +3 -0
    	
        .gitattributes
    ADDED
    
    | @@ -0,0 +1,37 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            *.7z filter=lfs diff=lfs merge=lfs -text
         | 
| 2 | 
            +
            *.arrow filter=lfs diff=lfs merge=lfs -text
         | 
| 3 | 
            +
            *.bin filter=lfs diff=lfs merge=lfs -text
         | 
| 4 | 
            +
            *.bz2 filter=lfs diff=lfs merge=lfs -text
         | 
| 5 | 
            +
            *.ckpt filter=lfs diff=lfs merge=lfs -text
         | 
| 6 | 
            +
            *.ftz filter=lfs diff=lfs merge=lfs -text
         | 
| 7 | 
            +
            *.gz filter=lfs diff=lfs merge=lfs -text
         | 
| 8 | 
            +
            *.h5 filter=lfs diff=lfs merge=lfs -text
         | 
| 9 | 
            +
            *.joblib filter=lfs diff=lfs merge=lfs -text
         | 
| 10 | 
            +
            *.lfs.* filter=lfs diff=lfs merge=lfs -text
         | 
| 11 | 
            +
            *.mlmodel filter=lfs diff=lfs merge=lfs -text
         | 
| 12 | 
            +
            *.model filter=lfs diff=lfs merge=lfs -text
         | 
| 13 | 
            +
            *.msgpack filter=lfs diff=lfs merge=lfs -text
         | 
| 14 | 
            +
            *.npy filter=lfs diff=lfs merge=lfs -text
         | 
| 15 | 
            +
            *.npz filter=lfs diff=lfs merge=lfs -text
         | 
| 16 | 
            +
            *.onnx filter=lfs diff=lfs merge=lfs -text
         | 
| 17 | 
            +
            *.ot filter=lfs diff=lfs merge=lfs -text
         | 
| 18 | 
            +
            *.parquet filter=lfs diff=lfs merge=lfs -text
         | 
| 19 | 
            +
            *.pb filter=lfs diff=lfs merge=lfs -text
         | 
| 20 | 
            +
            *.pickle filter=lfs diff=lfs merge=lfs -text
         | 
| 21 | 
            +
            *.pkl filter=lfs diff=lfs merge=lfs -text
         | 
| 22 | 
            +
            *.pt filter=lfs diff=lfs merge=lfs -text
         | 
| 23 | 
            +
            *.pth filter=lfs diff=lfs merge=lfs -text
         | 
| 24 | 
            +
            *.rar filter=lfs diff=lfs merge=lfs -text
         | 
| 25 | 
            +
            *.safetensors filter=lfs diff=lfs merge=lfs -text
         | 
| 26 | 
            +
            saved_model/**/* filter=lfs diff=lfs merge=lfs -text
         | 
| 27 | 
            +
            *.tar.* filter=lfs diff=lfs merge=lfs -text
         | 
| 28 | 
            +
            *.tar filter=lfs diff=lfs merge=lfs -text
         | 
| 29 | 
            +
            *.tflite filter=lfs diff=lfs merge=lfs -text
         | 
| 30 | 
            +
            *.tgz filter=lfs diff=lfs merge=lfs -text
         | 
| 31 | 
            +
            *.wasm filter=lfs diff=lfs merge=lfs -text
         | 
| 32 | 
            +
            *.xz filter=lfs diff=lfs merge=lfs -text
         | 
| 33 | 
            +
            *.zip filter=lfs diff=lfs merge=lfs -text
         | 
| 34 | 
            +
            *.zst filter=lfs diff=lfs merge=lfs -text
         | 
| 35 | 
            +
            *tfevents* filter=lfs diff=lfs merge=lfs -text
         | 
| 36 | 
            +
            *.png filter=lfs diff=lfs merge=lfs -text
         | 
| 37 | 
            +
            *.jpg filter=lfs diff=lfs merge=lfs -text
         | 
    	
        .gitignore
    ADDED
    
    | @@ -0,0 +1,4 @@ | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            __py_cache__/
         | 
| 2 | 
            +
            *.pyc
         | 
| 3 | 
            +
            .gradio/
         | 
| 4 | 
            +
            .ipynb_checkpoints/
         | 
    	
        Dockerfile
    ADDED
    
    | @@ -0,0 +1,38 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            FROM nvidia/cuda:12.2.2-cudnn8-devel-ubuntu22.04
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ENV DEBIAN_FRONTEND=noninteractive
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            RUN apt-get update && apt-get install -y \
         | 
| 6 | 
            +
                python3-pip \
         | 
| 7 | 
            +
                python3-dev \
         | 
| 8 | 
            +
                git \
         | 
| 9 | 
            +
                build-essential \
         | 
| 10 | 
            +
                ninja-build \
         | 
| 11 | 
            +
                && useradd -m user \
         | 
| 12 | 
            +
                && rm -rf /var/lib/apt/lists/*
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            USER user
         | 
| 15 | 
            +
            WORKDIR /home/user/app
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            COPY --chown=user:user . .
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            RUN pip install --upgrade pip setuptools wheel packaging
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            RUN pip install torch==2.6.0 torchvision==0.21.0 --index-url https://download.pytorch.org/whl/cu124
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            RUN pip install \
         | 
| 24 | 
            +
                gradio \
         | 
| 25 | 
            +
                pillow \
         | 
| 26 | 
            +
                matplotlib \
         | 
| 27 | 
            +
                numpy \
         | 
| 28 | 
            +
                requests \
         | 
| 29 | 
            +
                peft==0.15.2 \
         | 
| 30 | 
            +
                accelerate==1.4.0 \
         | 
| 31 | 
            +
                'transformers @ git+https://github.com/huggingface/transformers@ccf2ca162e33f381e454cdb74bf4b41a51ab976d'
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            # Install flash-attn matching dev environment
         | 
| 34 | 
            +
            RUN MAX_JOBS=1 pip install flash-attn==2.7.4.post1 --no-build-isolation
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            EXPOSE 7860
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            CMD ["python3", "app.py"]
         | 
    	
        README.md
    ADDED
    
    | @@ -0,0 +1,11 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            title: Jina Embeddings V4 Retrieval Visual
         | 
| 3 | 
            +
            emoji: 👀
         | 
| 4 | 
            +
            colorFrom: green
         | 
| 5 | 
            +
            colorTo: purple
         | 
| 6 | 
            +
            sdk: docker
         | 
| 7 | 
            +
            app_port: 7860
         | 
| 8 | 
            +
            pinned: false
         | 
| 9 | 
            +
            ---
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
         | 
    	
        app.py
    ADDED
    
    | @@ -0,0 +1,181 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            """
         | 
| 2 | 
            +
            app.py – Token‑wise heatmaps with JinaV4SimilarityMapper (similarity4)
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ───────── Feature checklist (for future edits) ─────────
         | 
| 5 | 
            +
            1. Prompt + Image‑URL inputs (placeholders).                       ✅
         | 
| 6 | 
            +
            2. Run → downloads image (≥512 h), gets tokens+heatmaps,           ✅
         | 
| 7 | 
            +
               auto‑selects first token, shows overlay, clears inputs.
         | 
| 8 | 
            +
            3. Output widgets hidden until results are ready.                  ✅
         | 
| 9 | 
            +
            4. Every run saved to examples/auto_<timestamp>/ with:
         | 
| 10 | 
            +
                 • prompt.txt, img_url.txt, image.jpg,
         | 
| 11 | 
            +
                 • heatmaps.json, per‑token PNGs, preview_first_token.jpg.     ✅
         | 
| 12 | 
            +
            5. On startup, first 3 example folders rendered below output with
         | 
| 13 | 
            +
               layout: Prompt → Image URL → Tokens → Image+Heatmap.            ✅
         | 
| 14 | 
            +
            6. Margins: 40 px before “Examples” heading, 25 px between         ✅
         | 
| 15 | 
            +
               successive examples (no separators, no extra HTML).
         | 
| 16 | 
            +
            7. Works on gradio==5.35.0 (no gr.Box, no Button.style, etc.).     ✅
         | 
| 17 | 
            +
            """
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            import sys, signal, base64, re, io, json, time
         | 
| 20 | 
            +
            from io import BytesIO
         | 
| 21 | 
            +
            from pathlib import Path
         | 
| 22 | 
            +
            from typing import Dict
         | 
| 23 | 
            +
            import subprocess
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            import requests
         | 
| 26 | 
            +
            import gradio as gr
         | 
| 27 | 
            +
            from PIL import Image
         | 
| 28 | 
            +
            from similarity import JinaV4SimilarityMapper
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            EX_DIR = Path("examples"); EX_DIR.mkdir(exist_ok=True)
         | 
| 31 | 
            +
            MIN_H  = 512
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            # ───────── component helper (Buttons vs Radio) ─────────
         | 
| 34 | 
            +
            if hasattr(gr, "Buttons"):
         | 
| 35 | 
            +
                ButtonsLike = gr.Buttons
         | 
| 36 | 
            +
                def buttons_update(toks):
         | 
| 37 | 
            +
                    first = toks[0] if toks else None
         | 
| 38 | 
            +
                    return ButtonsLike.update(choices=toks, value=first, visible=True)
         | 
| 39 | 
            +
            else:
         | 
| 40 | 
            +
                ButtonsLike = gr.Radio
         | 
| 41 | 
            +
                def buttons_update(toks):
         | 
| 42 | 
            +
                    first = toks[0] if toks else None
         | 
| 43 | 
            +
                    return gr.update(choices=toks, value=first, visible=True)
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            # ───────── util functions ─────────
         | 
| 46 | 
            +
            def _slug(t: str, n: int = 60) -> str:
         | 
| 47 | 
            +
                return re.sub(r"[^\w\-]+", "_", t.lower())[:n] or "x"
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            def _ensure_h(img: Image.Image, h: int = MIN_H) -> Image.Image:
         | 
| 50 | 
            +
                if img.height >= h:
         | 
| 51 | 
            +
                    return img
         | 
| 52 | 
            +
                sc = h / img.height
         | 
| 53 | 
            +
                return img.resize((int(img.width * sc), h), Image.BICUBIC)
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            def overlay(tok: str, maps: Dict[str, str], base: Image.Image) -> Image.Image:
         | 
| 56 | 
            +
                if tok not in maps:
         | 
| 57 | 
            +
                    return base
         | 
| 58 | 
            +
                hm = Image.open(BytesIO(base64.b64decode(maps[tok]))).convert("RGBA")
         | 
| 59 | 
            +
                if hm.size != base.size:
         | 
| 60 | 
            +
                    hm = hm.resize(base.size, Image.BILINEAR)
         | 
| 61 | 
            +
                return Image.alpha_composite(base.convert("RGBA"), hm)
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            def save_run(prompt: str, url: str, img: Image.Image, maps: Dict[str, str]) -> None:
         | 
| 64 | 
            +
                ts   = time.strftime("%Y%m%d_%H%M%S")
         | 
| 65 | 
            +
                fldr = EX_DIR / f"auto_{_slug(prompt,30)}_{ts}"
         | 
| 66 | 
            +
                fldr.mkdir(parents=True, exist_ok=True)
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                (fldr / "prompt.txt").write_text(prompt)
         | 
| 69 | 
            +
                (fldr / "img_url.txt").write_text(url)
         | 
| 70 | 
            +
                img.convert("RGB").save(fldr / "image.jpg", "JPEG")
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                with (fldr / "heatmaps.json").open("w") as f:
         | 
| 73 | 
            +
                    json.dump(maps, f)
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                for tok, b64png in maps.items():
         | 
| 76 | 
            +
                    (fldr / f"heatmap_{_slug(tok,30)}.png").write_bytes(base64.b64decode(b64png))
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                first = next(iter(maps))
         | 
| 79 | 
            +
                overlay(first, maps, img).convert("RGB").save(fldr / "preview_first_token.jpg", "JPEG")
         | 
| 80 | 
            +
                print(f"✨ Saved run to {fldr}", flush=True)
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            # ───────── load mapper ─────────
         | 
| 83 | 
            +
            print("⏳ Loading JinaV4SimilarityMapper …", flush=True)
         | 
| 84 | 
            +
            MAPPER = JinaV4SimilarityMapper(client_type="local")
         | 
| 85 | 
            +
            print("✅ Mapper ready.", flush=True)
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            # ───────── load up to 3 example folders ─────────
         | 
| 88 | 
            +
            def load_examples(n: int = 3):
         | 
| 89 | 
            +
                ex = []
         | 
| 90 | 
            +
                for fld in sorted(EX_DIR.iterdir())[:n]:
         | 
| 91 | 
            +
                    p_txt, p_url, p_img, p_map = fld/"prompt.txt", fld/"img_url.txt", None, fld/"heatmaps.json"
         | 
| 92 | 
            +
                    for c in fld.glob("image.*"): p_img = c; break
         | 
| 93 | 
            +
                    if not (p_txt.exists() and p_url.exists() and p_img and p_map.exists()): continue
         | 
| 94 | 
            +
                    ex.append(dict(
         | 
| 95 | 
            +
                        prompt=p_txt.read_text().strip(),
         | 
| 96 | 
            +
                        url   =p_url.read_text().strip(),
         | 
| 97 | 
            +
                        base  =Image.open(p_img).convert("RGB"),
         | 
| 98 | 
            +
                        maps  =json.load(open(p_map))
         | 
| 99 | 
            +
                    ))
         | 
| 100 | 
            +
                return ex
         | 
| 101 | 
            +
             | 
| 102 | 
            +
            static_examples = load_examples()
         | 
| 103 | 
            +
             | 
| 104 | 
            +
            # ───────── backend for user Run ─────────
         | 
| 105 | 
            +
            def run_mapper(prompt: str, img_url: str):
         | 
| 106 | 
            +
                if not img_url:
         | 
| 107 | 
            +
                    raise gr.Error("Please provide an image URL.")
         | 
| 108 | 
            +
                try:
         | 
| 109 | 
            +
                    r = requests.get(img_url, stream=True, timeout=10); r.raise_for_status()
         | 
| 110 | 
            +
                    img = _ensure_h(Image.open(io.BytesIO(r.content)).convert("RGB"))
         | 
| 111 | 
            +
                except Exception as e:
         | 
| 112 | 
            +
                    raise gr.Error(f"Image load failed: {e}")
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                img_proc = img.copy(); MAPPER.process_image(img_proc)
         | 
| 115 | 
            +
                toks, maps = MAPPER.get_token_similarity_maps(prompt, img_proc)
         | 
| 116 | 
            +
                if not toks:
         | 
| 117 | 
            +
                    raise gr.Error("Mapper returned no tokens.")
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                save_run(prompt, img_url, img, maps)
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                first_tok = toks[0]
         | 
| 122 | 
            +
                info      = f"**Prompt:** {prompt}\n\n**Image URL:** {img_url}"
         | 
| 123 | 
            +
                return (
         | 
| 124 | 
            +
                    buttons_update(toks), maps, img,
         | 
| 125 | 
            +
                    gr.update(value=overlay(first_tok, maps, img), visible=True),
         | 
| 126 | 
            +
                    gr.update(value=info, visible=True),
         | 
| 127 | 
            +
                    "", "")
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            # ───────── UI ─────────
         | 
| 130 | 
            +
            css = """
         | 
| 131 | 
            +
            #main-title { margin-bottom: 40px; }
         | 
| 132 | 
            +
            #run-btn { margin: 20px 0; }
         | 
| 133 | 
            +
            #examples-title { margin: 40px 0; }
         | 
| 134 | 
            +
            .example-space { margin: 20px 0; }
         | 
| 135 | 
            +
            """
         | 
| 136 | 
            +
             | 
| 137 | 
            +
            with gr.Blocks(css=css) as demo:
         | 
| 138 | 
            +
                gr.Markdown("# Jina Embeddings v4", elem_id="main-title")
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                # User input
         | 
| 141 | 
            +
                prompt_in = gr.Textbox(label="Prompt", placeholder="Describe what to query…")
         | 
| 142 | 
            +
                url_in    = gr.Textbox(label="Image URL", placeholder="https://example.com/image.jpg")
         | 
| 143 | 
            +
                run_btn   = gr.Button("Run", elem_id="run-btn")
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                # Output area
         | 
| 146 | 
            +
                info_md   = gr.Markdown(visible=False)
         | 
| 147 | 
            +
                token_sel = ButtonsLike(choices=[], label="Tokens", interactive=True, visible=False)
         | 
| 148 | 
            +
                maps_st   = gr.State({})
         | 
| 149 | 
            +
                img_st    = gr.State(None)
         | 
| 150 | 
            +
                img_out   = gr.Image(label="Image + Heatmap", visible=False)
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                run_btn.click(run_mapper,
         | 
| 153 | 
            +
                    [prompt_in, url_in],
         | 
| 154 | 
            +
                    [token_sel, maps_st, img_st, img_out, info_md, prompt_in, url_in])
         | 
| 155 | 
            +
             | 
| 156 | 
            +
                (token_sel.select if hasattr(token_sel,"select") else token_sel.change)(
         | 
| 157 | 
            +
                    overlay, [token_sel, maps_st, img_st], [img_out])
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                # Margin before examples heading
         | 
| 160 | 
            +
                gr.Markdown("## Examples", elem_id="examples-title")
         | 
| 161 | 
            +
             | 
| 162 | 
            +
                # Render examples
         | 
| 163 | 
            +
                for ex in static_examples:
         | 
| 164 | 
            +
                    gr.Markdown(f"**Prompt:** {ex['prompt']}")
         | 
| 165 | 
            +
                    gr.Markdown(f"**Image URL:** {ex['url']}")
         | 
| 166 | 
            +
                    ex_img_st  = gr.State(ex["base"])
         | 
| 167 | 
            +
                    ex_map_st  = gr.State(ex["maps"])
         | 
| 168 | 
            +
                    first      = next(iter(ex["maps"]))
         | 
| 169 | 
            +
                    ex_btns    = ButtonsLike(choices=list(ex["maps"].keys()), value=first, interactive=True)
         | 
| 170 | 
            +
                    ex_disp    = gr.Image(value=overlay(first, ex["maps"], ex["base"]))
         | 
| 171 | 
            +
                    (ex_btns.select if hasattr(ex_btns,"select") else ex_btns.change)(
         | 
| 172 | 
            +
                        overlay, [ex_btns, ex_map_st, ex_img_st], [ex_disp])
         | 
| 173 | 
            +
                    # vertical margin after each example
         | 
| 174 | 
            +
                    gr.Markdown("", elem_classes=["example-space"])
         | 
| 175 | 
            +
             | 
| 176 | 
            +
            # ───────── graceful shutdown ─────────
         | 
| 177 | 
            +
            def _shutdown(*_): print("🛑 Shutting down …", flush=True); demo.close(); sys.exit(0)
         | 
| 178 | 
            +
            signal.signal(signal.SIGINT, _shutdown); signal.signal(signal.SIGTERM, _shutdown)
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            if __name__ == "__main__":
         | 
| 181 | 
            +
                demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
         | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġa.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġbicycle.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġnear.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġocean.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġperson.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġriding.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmap_ġthe.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/heatmaps.json
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/image.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/img_url.txt
    ADDED
    
    | @@ -0,0 +1 @@ | |
|  | 
|  | |
| 1 | 
            +
            https://cdn.duvine.com/wp-content/uploads/2016/04/17095703/Slides_mallorca_FOR-WEB.jpg
         | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/preview_first_token.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_riding_a_bicycle_near_20250702_150805/prompt.txt
    ADDED
    
    | @@ -0,0 +1 @@ | |
|  | 
|  | |
| 1 | 
            +
            A person riding a bicycle near the ocean
         | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġa.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġdog.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġdown.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġperson.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġstreet.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġthe.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġwalking.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmap_ġwith.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/heatmaps.json
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/image.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/img_url.txt
    ADDED
    
    | @@ -0,0 +1 @@ | |
|  | 
|  | |
| 1 | 
            +
            https://www.dogingtonpost.com/wp-content/uploads/2014/04/walkingthedog2.jpg
         | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/preview_first_token.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_a_person_walking_down_the_stre_20250702_152111/prompt.txt
    ADDED
    
    | @@ -0,0 +1 @@ | |
|  | 
|  | |
| 1 | 
            +
            A person walking down the street with a dog
         | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġcomputing.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġin.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġjobs.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġthe.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/heatmap_ġus.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/heatmaps.json
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/image.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/img_url.txt
    ADDED
    
    | @@ -0,0 +1 @@ | |
|  | 
|  | |
| 1 | 
            +
            https://www.ayresassociates.com/wp-content/uploads/2019/02/Career-Expo-Pie-Chart-Crop.jpg
         | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/preview_first_token.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_computing_jobs_in_the_us_20250702_150954/prompt.txt
    ADDED
    
    | @@ -0,0 +1 @@ | |
|  | 
|  | |
| 1 | 
            +
            Computing jobs in the US
         | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġchart.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġcolumn.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġindex.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġlabels.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġsimple.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/heatmap_ġwith.png
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/heatmaps.json
    ADDED
    
    | The diff for this file is too large to render. 
		See raw diff | 
|  | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/image.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/img_url.txt
    ADDED
    
    | @@ -0,0 +1 @@ | |
|  | 
|  | |
| 1 | 
            +
            https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSf3wwnclk5MltzC6R_ghESRmlR2jlOf2REsw&s
         | 
    	
        examples/auto_simple_column_chart_with_index_20250702_151028/preview_first_token.jpg
    ADDED
    
    |   | 
| Git LFS Details
 | 
