|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Celeste AI - Working With Images\n", |
| 8 | + "\n", |
| 9 | + "Unified interface for image **generation**, **editing**, and **analysis** across providers.\n", |
| 10 | + "\n", |
| 11 | + "Star on GitHub 👉 [withceleste/celeste-python](https://github.com/withceleste/celeste-python)" |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "markdown", |
| 16 | + "metadata": {}, |
| 17 | + "source": [ |
| 18 | + "## Setup" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "code", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "import celeste\n", |
| 26 | + "from IPython.display import Image, display" |
| 27 | + ], |
| 28 | + "outputs": [], |
| 29 | + "execution_count": null |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "markdown", |
| 33 | + "metadata": {}, |
| 34 | + "source": [ |
| 35 | + "---\n", |
| 36 | + "\n", |
| 37 | + "## Generate\n", |
| 38 | + "\n", |
| 39 | + "Create images from text prompts." |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "img_gen_result = await celeste.images.generate(\n", |
| 47 | + " \"A nano banana on the beach\",\n", |
| 48 | + " model=\"gemini-2.5-flash-image\",\n", |
| 49 | + ")" |
| 50 | + ], |
| 51 | + "outputs": [], |
| 52 | + "execution_count": null |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "metadata": {}, |
| 57 | + "source": [ |
| 58 | + "display(Image(data=img_gen_result.content.data))" |
| 59 | + ], |
| 60 | + "outputs": [], |
| 61 | + "execution_count": null |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "markdown", |
| 65 | + "metadata": {}, |
| 66 | + "source": [ |
| 67 | + "---\n", |
| 68 | + "\n", |
| 69 | + "## Edit\n", |
| 70 | + "\n", |
| 71 | + "Modify existing images with text instructions." |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "metadata": {}, |
| 77 | + "source": [ |
| 78 | + "img_edit_result = await celeste.images.edit(\n", |
| 79 | + " image=img_gen_result.content,\n", |
| 80 | + " prompt=\"Make it night time\",\n", |
| 81 | + " model=\"gemini-2.5-flash-image\",\n", |
| 82 | + ")" |
| 83 | + ], |
| 84 | + "outputs": [], |
| 85 | + "execution_count": null |
| 86 | + }, |
| 87 | + { |
| 88 | + "cell_type": "code", |
| 89 | + "metadata": {}, |
| 90 | + "source": [ |
| 91 | + "display(Image(data=img_edit_result.content.data))" |
| 92 | + ], |
| 93 | + "outputs": [], |
| 94 | + "execution_count": null |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "markdown", |
| 98 | + "metadata": {}, |
| 99 | + "source": [ |
| 100 | + "---\n", |
| 101 | + "\n", |
| 102 | + "## Analyze\n", |
| 103 | + "\n", |
| 104 | + "Extract information from images." |
| 105 | + ] |
| 106 | + }, |
| 107 | + { |
| 108 | + "cell_type": "code", |
| 109 | + "metadata": {}, |
| 110 | + "source": [ |
| 111 | + "analyze_result = await celeste.images.analyze(\n", |
| 112 | + " prompt=\"What fruit is in this image and what color is it?\",\n", |
| 113 | + " image=img_gen_result.content,\n", |
| 114 | + " model=\"gemini-2.5-flash-lite\",\n", |
| 115 | + ")" |
| 116 | + ], |
| 117 | + "outputs": [], |
| 118 | + "execution_count": null |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "metadata": {}, |
| 123 | + "source": [ |
| 124 | + "print(analyze_result.content)" |
| 125 | + ], |
| 126 | + "outputs": [], |
| 127 | + "execution_count": null |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "markdown", |
| 131 | + "metadata": { |
| 132 | + "ExecuteTime": { |
| 133 | + "end_time": "2026-01-12T21:53:45.320259Z", |
| 134 | + "start_time": "2026-01-12T21:53:45.313508Z" |
| 135 | + } |
| 136 | + }, |
| 137 | + "source": [ |
| 138 | + "---\n", |
| 139 | + "\n", |
| 140 | + "## Local Generation with Ollama\n", |
| 141 | + "\n", |
| 142 | + "Generate images locally using Ollama. No API key needed." |
| 143 | + ] |
| 144 | + }, |
| 145 | + { |
| 146 | + "cell_type": "markdown", |
| 147 | + "metadata": {}, |
| 148 | + "source": [ |
| 149 | + "1. Start the server (in a terminal):\n", |
| 150 | + "```bash\n", |
| 151 | + "ollama serve\n", |
| 152 | + "```\n", |
| 153 | + "\n", |
| 154 | + "2. Pull the image model:\n", |
| 155 | + "```bash\n", |
| 156 | + "ollama pull x/flux2-klein\n", |
| 157 | + "```" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "cell_type": "code", |
| 162 | + "metadata": {}, |
| 163 | + "source": [ |
| 164 | + "prompt = \"A blurry iPhone-style photograph showing the window of a moving train. Through the window, a scenic landscape appears: tall green cliffs running alongside a river, with a small European village built on the slopes. The motion blur suggests the train is moving quickly, with soft reflections on the glass, natural daylight, and a casual handheld phone-camera aesthetic. Sharp textures where possible, rich colors, and a realistic sense of depth and distance.\"\n", |
| 165 | + "\n", |
| 166 | + "local_result = await celeste.images.generate(\n", |
| 167 | + " prompt=prompt,\n", |
| 168 | + " model=\"x/flux2-klein\",\n", |
| 169 | + " provider=\"ollama\",\n", |
| 170 | + " steps=1,\n", |
| 171 | + ")\n", |
| 172 | + "display(Image(data=local_result.content.data))" |
| 173 | + ], |
| 174 | + "outputs": [], |
| 175 | + "execution_count": null |
| 176 | + }, |
| 177 | + { |
| 178 | + "metadata": {}, |
| 179 | + "cell_type": "markdown", |
| 180 | + "source": [ |
| 181 | + "---\n", |
| 182 | + "\n", |
| 183 | + "## Streaming (Ollama)\n", |
| 184 | + "\n", |
| 185 | + "Ollama streams NDJSON progress events. Celeste exposes these as image stream chunks with `metadata` (progress) and a final chunk containing the image." |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | + "cell_type": "code", |
| 190 | + "metadata": {}, |
| 191 | + "source": [ |
| 192 | + "from tqdm.asyncio import tqdm\n", |
| 193 | + "\n", |
| 194 | + "steps = 4\n", |
| 195 | + "\n", |
| 196 | + "stream = celeste.images.stream.generate(\n", |
| 197 | + " prompt=prompt,\n", |
| 198 | + " model=\"x/flux2-klein\",\n", |
| 199 | + " provider=\"ollama\",\n", |
| 200 | + " steps=steps,\n", |
| 201 | + ")\n", |
| 202 | + "\n", |
| 203 | + "async for chunk in tqdm(stream, total=steps+1):\n", |
| 204 | + " pass\n", |
| 205 | + "\n", |
| 206 | + "display(Image(data=chunk.content.data))" |
| 207 | + ], |
| 208 | + "outputs": [], |
| 209 | + "execution_count": null |
| 210 | + }, |
| 211 | + { |
| 212 | + "metadata": {}, |
| 213 | + "cell_type": "markdown", |
| 214 | + "source": [ |
| 215 | + "---\n", |
| 216 | + "Star on GitHub 👉 [withceleste/celeste-python](https://github.com/withceleste/celeste-python)" |
| 217 | + ] |
| 218 | + }, |
| 219 | + { |
| 220 | + "metadata": {}, |
| 221 | + "cell_type": "code", |
| 222 | + "outputs": [], |
| 223 | + "execution_count": null, |
| 224 | + "source": "" |
| 225 | + } |
| 226 | + ], |
| 227 | + "metadata": { |
| 228 | + "kernelspec": { |
| 229 | + "display_name": "Python 3 (ipykernel)", |
| 230 | + "language": "python", |
| 231 | + "name": "python3" |
| 232 | + }, |
| 233 | + "language_info": { |
| 234 | + "codemirror_mode": { |
| 235 | + "name": "ipython", |
| 236 | + "version": 3 |
| 237 | + }, |
| 238 | + "file_extension": ".py", |
| 239 | + "mimetype": "text/x-python", |
| 240 | + "name": "python", |
| 241 | + "nbconvert_exporter": "python", |
| 242 | + "pygments_lexer": "ipython3", |
| 243 | + "version": "3.13.3" |
| 244 | + } |
| 245 | + }, |
| 246 | + "nbformat": 4, |
| 247 | + "nbformat_minor": 4 |
| 248 | +} |
0 commit comments