|
| 1 | +{ |
| 2 | + "nbformat": 4, |
| 3 | + "nbformat_minor": 5, |
| 4 | + "cells": [ |
| 5 | + { |
| 6 | + "cell_type": "markdown", |
| 7 | + "metadata": { |
| 8 | + "id": "ppy7so3HYiOK" |
| 9 | + }, |
| 10 | + "source": [ |
| 11 | + "# Multimodal Mountain Peak Search — Colab Notebook\n", |
| 12 | + "\n", |
| 13 | + "In this notebook we do the following:\n", |
| 14 | + "- Install dependencies\n", |
| 15 | + "- Connect to **Elasticsearch**\n", |
| 16 | + "- Create indices\n", |
| 17 | + "- Index a small **peaks catalog** (text+image blended vectors)\n", |
| 18 | + "- Index a few **photos**\n", |
| 19 | + "- Run **text → image** search and **identify-from-photo** search\n" |
| 20 | + ], |
| 21 | + "id": "ppy7so3HYiOK" |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "code", |
| 25 | + "metadata": { |
| 26 | + "colab": { |
| 27 | + "base_uri": "https://localhost:8080/" |
| 28 | + }, |
| 29 | + "id": "o0tHMSj6YiOM", |
| 30 | + "outputId": "f58fb49f-1d7f-49a3-cb26-07f63534497d", |
| 31 | + "cellView": "form" |
| 32 | + }, |
| 33 | + "execution_count": 23, |
| 34 | + "outputs": [ |
| 35 | + { |
| 36 | + "output_type": "stream", |
| 37 | + "name": "stdout", |
| 38 | + "text": [ |
| 39 | + "Elasticsearch url(https://localhost:9200): \n", |
| 40 | + "Elasticsearch base64 api keyw\n", |
| 41 | + "ES_URL : https://localhost:9200\n", |
| 42 | + "API_KEY_B64: set\n" |
| 43 | + ] |
| 44 | + } |
| 45 | + ], |
| 46 | + "source": [ |
| 47 | + "#@title Configure Elasticsearch (API key recommended)\n", |
| 48 | + "import os, base64\n", |
| 49 | + "\n", |
| 50 | + "# Prompt for Elasticsearch URL:\n", |
| 51 | + "ES_URL = input(\"Elasticsearch url(https://localhost:9200): \") or \"https://localhost:9200\"\n", |
| 52 | + "\n", |
| 53 | + "\n", |
| 54 | + "#Prompt Elasticsearch base64 api key:\n", |
| 55 | + "ES_API_KEY_B64 = input(\"Elasticsearch base64 api key\")\n", |
| 56 | + "\n", |
| 57 | + "\n", |
| 58 | + "print(\"ES_URL :\", ES_URL)\n", |
| 59 | + "print(\"API_KEY_B64:\", \"set\" if ES_API_KEY_B64 else \"MISSING\")\n", |
| 60 | + "\n", |
| 61 | + "# Propagate for scripts\n", |
| 62 | + "os.environ[\"ES_URL\"] = ES_URL\n", |
| 63 | + "os.environ[\"ES_API_KEY_B64\"] = ES_API_KEY_B64\n", |
| 64 | + "\n", |
| 65 | + "# Optional model override\n", |
| 66 | + "# os.environ[\"SIGLIP_MODEL_ID\"] = \"google/siglip-so400m-patch14-384\"\n" |
| 67 | + ], |
| 68 | + "id": "o0tHMSj6YiOM" |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "code", |
| 72 | + "metadata": { |
| 73 | + "id": "za6W0opPYiOM", |
| 74 | + "colab": { |
| 75 | + "base_uri": "https://localhost:8080/" |
| 76 | + }, |
| 77 | + "outputId": "bdbdac01-1579-4b60-b2b1-f753deaf9548" |
| 78 | + }, |
| 79 | + "execution_count": 2, |
| 80 | + "outputs": [ |
| 81 | + { |
| 82 | + "output_type": "stream", |
| 83 | + "name": "stdout", |
| 84 | + "text": [ |
| 85 | + "Cloning: https://github.com/navneet83/multimodal-mountain-peak-search\n", |
| 86 | + "Cloned and cwd set to /content/multimodal-mountain-peak-search\n" |
| 87 | + ] |
| 88 | + } |
| 89 | + ], |
| 90 | + "source": [ |
| 91 | + "#@title Clone Github repo\n", |
| 92 | + "REPO_URL = \"https://github.com/navneet83/multimodal-mountain-peak-search\"\n", |
| 93 | + "TARGET_DIR = \"/content/multimodal-mountain-peak-search\"\n", |
| 94 | + "import os, shutil, subprocess, sys\n", |
| 95 | + "\n", |
| 96 | + "if os.path.exists(TARGET_DIR):\n", |
| 97 | + " shutil.rmtree(TARGET_DIR)\n", |
| 98 | + "\n", |
| 99 | + "print(\"Cloning:\", REPO_URL)\n", |
| 100 | + "rc = subprocess.call([\"git\",\"clone\",\"--depth\",\"1\", REPO_URL, TARGET_DIR])\n", |
| 101 | + "if rc != 0:\n", |
| 102 | + " raise SystemExit(\"❌ Clone failed. Check the repo URL or network.\")\n", |
| 103 | + "\n", |
| 104 | + "os.chdir(TARGET_DIR)\n", |
| 105 | + "sys.path.insert(0, os.path.join(TARGET_DIR, \"src\")) # import ai_mpi.embeddings\n", |
| 106 | + "print(\"Cloned and cwd set to\", TARGET_DIR)" |
| 107 | + ], |
| 108 | + "id": "za6W0opPYiOM" |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "source": [ |
| 113 | + "#@title Install dependencies\n", |
| 114 | + "!pip -q install --upgrade pip\n", |
| 115 | + "!pip install -r requirements.txt\n", |
| 116 | + "print(\"Installed\")" |
| 117 | + ], |
| 118 | + "metadata": { |
| 119 | + "id": "JEMGE9kgrR5v" |
| 120 | + }, |
| 121 | + "id": "JEMGE9kgrR5v", |
| 122 | + "execution_count": null, |
| 123 | + "outputs": [] |
| 124 | + }, |
| 125 | + { |
| 126 | + "cell_type": "code", |
| 127 | + "metadata": { |
| 128 | + "id": "6T5tDn7ZYiOO" |
| 129 | + }, |
| 130 | + "execution_count": null, |
| 131 | + "outputs": [], |
| 132 | + "source": [ |
| 133 | + "#@title Create indices in Elasticsearch\n", |
| 134 | + "!python scripts/create_indices.py --recreate || python scripts/create_indices.py\n", |
| 135 | + "print(\"Indices ready\")" |
| 136 | + ], |
| 137 | + "id": "6T5tDn7ZYiOO" |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "metadata": { |
| 142 | + "id": "tk6MFsDyYiOP" |
| 143 | + }, |
| 144 | + "execution_count": null, |
| 145 | + "outputs": [], |
| 146 | + "source": [ |
| 147 | + "#@title Index peaks (blended text + reference images)\n", |
| 148 | + "!python scripts/embed_and_index_photos.py --index-peaks --peaks-yaml data/peaks.yaml --peaks-images-root data/peaks --blend-alpha-text 0.55 --blend-max-images 3\n", |
| 149 | + "print(\"Peaks indexed\")" |
| 150 | + ], |
| 151 | + "id": "tk6MFsDyYiOP" |
| 152 | + }, |
| 153 | + { |
| 154 | + "cell_type": "code", |
| 155 | + "metadata": { |
| 156 | + "id": "ualslgxsYiOP" |
| 157 | + }, |
| 158 | + "execution_count": null, |
| 159 | + "outputs": [], |
| 160 | + "source": [ |
| 161 | + "#@title Index your photos\n", |
| 162 | + "!python scripts/embed_and_index_photos.py --index-photos --images data/images --topk-predicted 5\n", |
| 163 | + "print(\"✅ Photos indexed\")" |
| 164 | + ], |
| 165 | + "id": "ualslgxsYiOP" |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "code", |
| 169 | + "source": [ |
| 170 | + "#@title Text → image search (type a peak name)\n", |
| 171 | + "query = \"Pumori\" #@param [\"Ama Dablam\", \"Pumori\", \"Mount Everest\"] {allow-input: true}\n", |
| 172 | + "k = 12 #@param {type:\"slider\", min:6, max:30, step:2}\n", |
| 173 | + "num_candidates = 4000 #@param {type:\"slider\", min:1000, max:6000, step:1000}\n", |
| 174 | + "\n", |
| 175 | + "!python scripts/query_by_peak_name.py --peak query --k {k} --num-candidates {num_candidates}" |
| 176 | + ], |
| 177 | + "metadata": { |
| 178 | + "cellView": "form", |
| 179 | + "id": "VjpCGK9Csz2F" |
| 180 | + }, |
| 181 | + "id": "VjpCGK9Csz2F", |
| 182 | + "execution_count": null, |
| 183 | + "outputs": [] |
| 184 | + }, |
| 185 | + { |
| 186 | + "cell_type": "code", |
| 187 | + "source": [ |
| 188 | + "#@title Identify from photo → similar photos (upload OR reuse a repo image)\n", |
| 189 | + "from google.colab import files\n", |
| 190 | + "uploaded = files.upload()\n", |
| 191 | + "\n", |
| 192 | + "for fn in uploaded.keys():\n", |
| 193 | + " !python scripts/identify_from_picture_find_similar_peaks.py --image \"{fn}\" --neighbors 30\n" |
| 194 | + ], |
| 195 | + "metadata": { |
| 196 | + "id": "mLirCeRJrkDV" |
| 197 | + }, |
| 198 | + "id": "mLirCeRJrkDV", |
| 199 | + "execution_count": null, |
| 200 | + "outputs": [] |
| 201 | + } |
| 202 | + ], |
| 203 | + "metadata": { |
| 204 | + "colab": { |
| 205 | + "name": "02_quickstart_colab_navneet_v2.ipynb", |
| 206 | + "provenance": [] |
| 207 | + }, |
| 208 | + "kernelspec": { |
| 209 | + "display_name": "Python 3", |
| 210 | + "language": "python", |
| 211 | + "name": "python3" |
| 212 | + }, |
| 213 | + "language_info": { |
| 214 | + "name": "python", |
| 215 | + "version": "3.x" |
| 216 | + } |
| 217 | + } |
| 218 | +} |
0 commit comments