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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 416,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "\u001b[2mUsing Python 3.12.10 environment at: /Users/andrew/Developer/ML/whale/.venv\u001b[0m\n",
13
+ "\u001b[2mAudited \u001b[1m3 packages\u001b[0m \u001b[2min 11ms\u001b[0m\u001b[0m\n"
14
+ ]
15
+ }
16
+ ],
17
+ "source": [
18
+ "!uv pip install cairosvg torch colour-science"
19
+ ]
20
+ },
21
+ {
22
+ "attachments": {},
23
+ "cell_type": "markdown",
24
+ "metadata": {},
25
+ "source": [
26
+ "Dataset consisting of\n",
27
+ "- Various single shapes\n",
28
+ " - Square\n",
29
+ " - Rounded rectangle\n",
30
+ " - Circle\n",
31
+ "- at various coordinates\n",
32
+ "\n",
33
+ "Output:\n",
34
+ "- text prompt\n",
35
+ "- png images of the shapes\n",
36
+ "- svg text for the shapes"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": 417,
42
+ "metadata": {},
43
+ "outputs": [
44
+ {
45
+ "name": "stdout",
46
+ "output_type": "stream",
47
+ "text": [
48
+ "Failures in 1000 attempts: 0\n",
49
+ "Contrast ratio: 2.72\n"
50
+ ]
51
+ },
52
+ {
53
+ "data": {
54
+ "image/svg+xml": [
55
+ "<svg width=\"100\" height=\"100\" style=\"background-color: #adf3b3;\"><rect x=\"30\" y=\"30\" width=\"40\" height=\"40\" fill=\"#0857fe\"/></svg>"
56
+ ],
57
+ "text/plain": [
58
+ "<IPython.core.display.SVG object>"
59
+ ]
60
+ },
61
+ "execution_count": 417,
62
+ "metadata": {},
63
+ "output_type": "execute_result"
64
+ }
65
+ ],
66
+ "source": [
67
+ "import torch.random\n",
68
+ "import colour\n",
69
+ "from IPython.display import SVG\n",
70
+ "import torch.random\n",
71
+ "\n",
72
+ "def uniform(low=0, high=1):\n",
73
+ " return torch.rand(1).item() * (high - low) + low\n",
74
+ "\n",
75
+ "\n",
76
+ "def random_color():\n",
77
+ " r = uniform(0.0, 1.0)\n",
78
+ " g = uniform(0.0, 1.0)\n",
79
+ " b = uniform(0.0, 1.0)\n",
80
+ " return r, g, b\n",
81
+ "\n",
82
+ "def hex(r: float, g: float, b: float):\n",
83
+ " return f\"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}\"\n",
84
+ "\n",
85
+ "ColorType = tuple[float, float, float]\n",
86
+ "\n",
87
+ "def contrast_ratio(bg: ColorType, color: ColorType):\n",
88
+ " r1, g1, b1 = bg\n",
89
+ " r2, g2, b2 = color\n",
90
+ " # Convert to CIE XYZ\n",
91
+ " _, bg_lum, _ = colour.RGB_to_XYZ([r1, g1, b1], colour.models.RGB_COLOURSPACES['sRGB'].whitepoint, colour.models.RGB_COLOURSPACES['sRGB'].whitepoint, colour.models.RGB_COLOURSPACES['sRGB'].matrix_RGB_to_XYZ)\n",
92
+ " _, fg_lum, _ = colour.RGB_to_XYZ([r2, g2, b2], colour.models.RGB_COLOURSPACES['sRGB'].whitepoint, colour.models.RGB_COLOURSPACES['sRGB'].whitepoint, colour.models.RGB_COLOURSPACES['sRGB'].matrix_RGB_to_XYZ)\n",
93
+ " # Relative luminance is the Y component in XYZ\n",
94
+ " L1, L2 = max(bg_lum, fg_lum), min(bg_lum, fg_lum)\n",
95
+ " eps = 1e-6\n",
96
+ " return (L1 + eps) / (L2 + eps)\n",
97
+ "\n",
98
+ "def contrasting_color(background: ColorType, threshold=2.0, max_attempts=100):\n",
99
+ " \"\"\"\n",
100
+ " Generate a random color with contrast ratio above the threshold with the given background.\n",
101
+ " The threshold has been tuned so that it doesn't fail for random colors, if you have fixed colors you can increase the threshold\n",
102
+ " \"\"\"\n",
103
+ " for _ in range(max_attempts):\n",
104
+ " color = random_color()\n",
105
+ " ratio = contrast_ratio(background, color)\n",
106
+ " if ratio >= threshold:\n",
107
+ " return color, ratio\n",
108
+ " raise ValueError(f'No color found with contrast ratio >= {threshold} for background {background} in {max_attempts} attempts')\n",
109
+ "\n",
110
+ "def check_generate_contrast(tests=1000, max_attempts=100):\n",
111
+ " failures_per_1000 = 0\n",
112
+ " for _ in range(tests):\n",
113
+ " try:\n",
114
+ " contrasting_color(random_color(), max_attempts=max_attempts)\n",
115
+ " except ValueError:\n",
116
+ " failures_per_1000 += 1\n",
117
+ " return failures_per_1000\n",
118
+ "\n",
119
+ "print(f\"Failures in 1000 attempts: {check_generate_contrast(tests=1000, max_attempts=100)}\")\n",
120
+ "\n",
121
+ "test_color = random_color()\n",
122
+ "test_bg_color, ratio = contrasting_color(test_color)\n",
123
+ "print(f'Contrast ratio: {ratio:.2f}')\n",
124
+ "SVG(f'<svg width=\"100\" height=\"100\" style=\"background-color: {hex(*test_bg_color)};\"><rect x=\"30\" y=\"30\" width=\"40\" height=\"40\" fill=\"{hex(*test_color)}\" /></svg>')"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "execution_count": 418,
130
+ "metadata": {},
131
+ "outputs": [
132
+ {
133
+ "name": "stderr",
134
+ "output_type": "stream",
135
+ "text": [
136
+ "100%|██████████| 10000/10000 [00:04<00:00, 2071.32it/s]"
137
+ ]
138
+ },
139
+ {
140
+ "name": "stdout",
141
+ "output_type": "stream",
142
+ "text": [
143
+ "Generated 10000 examples\n",
144
+ "a line from (255.0, 219.0) to (365.0, 347.0) with stroke #210949 and width 3.9 within a 512 x 512 box of color \"white\"\n",
145
+ "<svg width=\"512\" height=\"512\" viewBox=\"0 0 512 512\" xmlns=\"http://www.w3.org/2000/svg\">\n",
146
+ " <rect width=\"512\" height=\"512\" fill=\"#ffffff\" />\n",
147
+ " <line x1=\"255.0\" y1=\"219.0\" x2=\"365.0\" y2=\"347.0\" stroke=\"#210949\" stroke-width=\"3.9\" />\n",
148
+ "</svg>\n",
149
+ "line\n",
150
+ "#ffffff\n",
151
+ "#f00314\n"
152
+ ]
153
+ },
154
+ {
155
+ "name": "stderr",
156
+ "output_type": "stream",
157
+ "text": [
158
+ "\n"
159
+ ]
160
+ },
161
+ {
162
+ "data": {
163
+ "image/svg+xml": [
164
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"512\" height=\"512\" viewBox=\"0 0 512 512\">\n",
165
+ " <rect width=\"512\" height=\"512\" fill=\"#ffffff\"/>\n",
166
+ " <line x1=\"255.0\" y1=\"219.0\" x2=\"365.0\" y2=\"347.0\" stroke=\"#210949\" stroke-width=\"3.9\"/>\n",
167
+ "</svg>"
168
+ ],
169
+ "text/plain": [
170
+ "<IPython.core.display.SVG object>"
171
+ ]
172
+ },
173
+ "execution_count": 418,
174
+ "metadata": {},
175
+ "output_type": "execute_result"
176
+ }
177
+ ],
178
+ "source": [
179
+ "from typing import Any\n",
180
+ "from tqdm import tqdm\n",
181
+ "\n",
182
+ "shape_types = [\n",
183
+ " (0.5, 'circle'),\n",
184
+ " (0.8, 'rect'),\n",
185
+ " (1, 'rounded-rect'),\n",
186
+ " (0.25, 'line'),\n",
187
+ "]\n",
188
+ "\n",
189
+ "backgrounds = [\n",
190
+ " (1.0, ('black', (0, 0, 0))),\n",
191
+ " (0.5, ('#000000', (0, 0, 0))),\n",
192
+ " (1.0, ('white', (1.0, 1.0, 1.0))),\n",
193
+ " (0.5, ('#ffffff', (1.0, 1.0, 1.0))),\n",
194
+ " (0.5, ('gray', (0.5, 0.5, 0.5))),\n",
195
+ " (0.5, (\"RANDOM\", None)),\n",
196
+ "]\n",
197
+ "\n",
198
+ "\n",
199
+ "def sample(options: list, value: float) -> Any:\n",
200
+ " \"\"\" Takes a random sample from a list of (weight, option) tuples\"\"\"\n",
201
+ " total_weight = sum(weight for weight, _ in options)\n",
202
+ " options_normalized = [(weight / total_weight, option) for weight, option in options]\n",
203
+ " v = value\n",
204
+ " for weight, option in options_normalized:\n",
205
+ " if v < weight:\n",
206
+ " return option\n",
207
+ " v -= weight\n",
208
+ " raise ValueError(f\"Value {v} is out of range for options {options_normalized}\")\n",
209
+ "\n",
210
+ "# iterate over the shapes and make random examples\n",
211
+ "def shape_data(num_examples=1000, use_background=False): \n",
212
+ " c_width = 512\n",
213
+ " c_height = 512\n",
214
+ " margin_x = c_width * 0.02\n",
215
+ " margin_y = c_height * 0.02\n",
216
+ " def wrap(svg: str, background: ColorType):\n",
217
+ " background_str = f'\\n <rect width=\"{c_width}\" height=\"{c_height}\" fill=\"{hex(*background)}\" />' if background else ''\n",
218
+ " return f'<svg width=\"{c_width}\" height=\"{c_height}\" viewBox=\"0 0 {c_width} {c_height}\" xmlns=\"http://www.w3.org/2000/svg\">{background_str}\\n {svg}\\n</svg>'\n",
219
+ " # normalize shape_types\n",
220
+ " for _ in tqdm(range(num_examples)):\n",
221
+ " shape_name = sample(shape_types, uniform())\n",
222
+ " bg_name, bg_color = sample(backgrounds, uniform()) if use_background else (None, None)\n",
223
+ " if bg_name == \"RANDOM\":\n",
224
+ " bg_color = random_color()\n",
225
+ " bg_name = hex(*bg_color)\n",
226
+ " color, _ = contrasting_color(background=bg_color) if bg_color else random_color()\n",
227
+ " bg_desc = f'within a {c_width} x {c_height} box of color \"{bg_name}\"'\n",
228
+ " meta = (shape_name, hex(*bg_color), hex(*color))\n",
229
+ " if shape_name == 'circle':\n",
230
+ " # Choose a radius > 0, and ensure the circle is strictly inside the bounds\n",
231
+ " max_r = min(c_width - 2 * margin_x, c_height - 2 * margin_y) / 2\n",
232
+ " r = uniform(8, max_r) # radius at least 8\n",
233
+ " r = round(r, 0)\n",
234
+ " # x and y must be at least r from the edge, and at most width - r\n",
235
+ " x = uniform(r, c_width - r)\n",
236
+ " x = round(x, 0)\n",
237
+ " y = uniform(r, c_height - r)\n",
238
+ " y = round(y, 0)\n",
239
+ " desc = f'a circle with radius {r} at ({x}, {y}) filled with {hex(*color)} {bg_desc}'\n",
240
+ " svg = f'<circle cx=\"{x}\" cy=\"{y}\" r=\"{r}\" fill=\"{hex(*color)}\" />'\n",
241
+ " yield desc, wrap(svg, bg_color), *meta\n",
242
+ " elif shape_name == \"rect\":\n",
243
+ " # Constrain to leave at least 2% margin on any side\n",
244
+ " max_w = c_width - 2 * margin_x\n",
245
+ " max_h = c_height - 2 * margin_y\n",
246
+ " w = uniform(max_w * 0.1, max_w) # width at least 10% of max_w\n",
247
+ " w = round(w, 0)\n",
248
+ " h = uniform(max_h * 0.1, max_h) # height at least 10% of max_h\n",
249
+ " h = round(h, 0)\n",
250
+ " x = uniform(margin_x, c_width - margin_x - w)\n",
251
+ " x = round(x, 0)\n",
252
+ " y = uniform(margin_y, c_height - margin_y - h)\n",
253
+ " y = round(y, 0)\n",
254
+ " desc = f'a rectangle with width {w} and height {h} at ({x}, {y}) filled with {hex(*color)} {bg_desc}'\n",
255
+ " svg = f'<rect x=\"{x}\" y=\"{y}\" width=\"{w}\" height=\"{h}\" fill=\"{hex(*color)}\" />'\n",
256
+ " yield desc, wrap(svg, bg_color), *meta\n",
257
+ " elif shape_name == 'rounded-rect':\n",
258
+ " # Constrain to leave at least 2% margin on any side\n",
259
+ " max_w = c_width - 2 * margin_x\n",
260
+ " max_h = c_height - 2 * margin_y\n",
261
+ " min_w = max_w * 0.1\n",
262
+ " min_h = max_h * 0.1\n",
263
+ " w = uniform(min_w, max_w)\n",
264
+ " w = round(w, 0)\n",
265
+ " h = uniform(min_h, max_h)\n",
266
+ " h = round(h, 0)\n",
267
+ " # x and y must be such that the rect stays within the canvas\n",
268
+ " x = uniform(margin_x, c_width - margin_x - w)\n",
269
+ " x = round(x, 0)\n",
270
+ " y = uniform(margin_y, c_height - margin_y - h)\n",
271
+ " y = round(y, 0)\n",
272
+ " r = uniform(0, min(w, h) / 2)\n",
273
+ " r = round(r, 1)\n",
274
+ " desc = f'a rounded rectangle with width {w}, height {h}, and radius {r} at ({x}, {y}) filled with {hex(*color)} {bg_desc}'\n",
275
+ " svg = f'<rect x=\"{x}\" y=\"{y}\" width=\"{w}\" height=\"{h}\" rx=\"{r}\" ry=\"{r}\" fill=\"{hex(*color)}\" />'\n",
276
+ " yield desc, wrap(svg, bg_color), *meta\n",
277
+ " elif shape_name == 'line':\n",
278
+ " # Constrain to leave at least 2% margin on any side\n",
279
+ " x1 = uniform(margin_x, c_width - margin_x)\n",
280
+ " x1 = round(x1, 0)\n",
281
+ " y1 = uniform(margin_y, c_height - margin_y)\n",
282
+ " y1 = round(y1, 0)\n",
283
+ " x2 = uniform(margin_x, c_width - margin_x)\n",
284
+ " x2 = round(x2, 0)\n",
285
+ " y2 = uniform(margin_y, c_height - margin_y)\n",
286
+ " y2 = round(y2, 0)\n",
287
+ " color = random_color()\n",
288
+ " stroke_width = round(uniform(1, 6), 1)\n",
289
+ " desc = f'a line from ({x1}, {y1}) to ({x2}, {y2}) with stroke {hex(*color)} and width {stroke_width} {bg_desc}'\n",
290
+ " svg = f'<line x1=\"{x1}\" y1=\"{y1}\" x2=\"{x2}\" y2=\"{y2}\" stroke=\"{hex(*color)}\" stroke-width=\"{stroke_width}\" />'\n",
291
+ " yield desc, wrap(svg, bg_color), *meta\n",
292
+ " \n",
293
+ "\n",
294
+ "examples = list(shape_data(10000, use_background=True))\n",
295
+ "print(f'Generated {len(examples)} examples')\n",
296
+ "\n",
297
+ "print('\\n'.join(examples[0]))\n",
298
+ "SVG(examples[0][1])"
299
+ ]
300
+ },
301
+ {
302
+ "cell_type": "code",
303
+ "execution_count": 419,
304
+ "metadata": {},
305
+ "outputs": [
306
+ {
307
+ "name": "stderr",
308
+ "output_type": "stream",
309
+ "text": [
310
+ "100%|██████████| 10000/10000 [01:29<00:00, 112.01it/s]\n"
311
+ ]
312
+ }
313
+ ],
314
+ "source": [
315
+ "import os\n",
316
+ "from tqdm import tqdm\n",
317
+ "import json\n",
318
+ "os.environ[\"DYLD_LIBRARY_PATH\"] = \"/opt/homebrew/lib\"\n",
319
+ "import cairosvg\n",
320
+ "\n",
321
+ "\n",
322
+ "def generate_images(output_dir=\"./data/shapes\"):\n",
323
+ " os.makedirs(output_dir, exist_ok=True)\n",
324
+ "\n",
325
+ " # delete all the old files\n",
326
+ " for file in os.listdir(output_dir):\n",
327
+ " os.remove(f\"{output_dir}/{file}\")\n",
328
+ "\n",
329
+ " def render_example(svg, i):\n",
330
+ " file_name = f\"{i:06d}.png\"\n",
331
+ " temp_path = f\"{output_dir}/{file_name}\"\n",
332
+ " cairosvg.svg2png(svg, write_to=temp_path)\n",
333
+ " return file_name\n",
334
+ "\n",
335
+ "\n",
336
+ " with open(f\"{output_dir}/metadata.jsonl\", \"w\") as f:\n",
337
+ " for i, example in tqdm(enumerate(examples), total=len(examples)):\n",
338
+ " #print(\"rendering\", example[1])\n",
339
+ " img = render_example(example[1], i)\n",
340
+ " # Add metadata to metadata.jsonl\n",
341
+ " f.write(json.dumps({\"desc\": example[0], \"svg\": example[1], \"file_name\": img, \"shape_name\": example[2], \"bg_color\": example[3], \"color\": example[4]}) + \"\\n\")\n",
342
+ " if i%100 == 0:\n",
343
+ " f.flush()\n",
344
+ " #print(example[0], render_example(example[1]))\n",
345
+ "generate_images()"
346
+ ]
347
+ },
348
+ {
349
+ "cell_type": "code",
350
+ "execution_count": 423,
351
+ "metadata": {},
352
+ "outputs": [
353
+ {
354
+ "data": {
355
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAAABmJLR0QA/wD/AP+gvaeTAAAUdElEQVR4nO3de3TXdf3A8X23cbU4oacSU8kLJtdAlIuojIsZWUkDNLNSQ8v6eSw3OVnKNSo9SFZWXuhHFzOLTLNftz/8ZXZOWXlHHNfhNpBtwDYYY4Mx8PfHZ+cL+TOFOfbZ9no8/vLFOZ7z+kef5/t9v9gyr776ag4A8eSmvQAA6RAAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAAghIAgKAEACAoAQAISgAIra62Pu0VIDUCQFwPLv/jpKGzS1ZuTHsRSEfm1VdfTXsH6Gj79x/4+peX/fgHj+bk5Lx7wHEPP/GtASe+M+2loKP5BEBEK59Zd/+9/5P8c3VlzbUzFzY2NKW7EnQ8ASC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UAAEEJAEBQAgAQlAAABCUAAEEJAEBQAgAQlAAABCUAAEEJAEBQAgAQlAAABCUAAEEJAEBQAgAQlAAABCUAAEEJAEBQAgAQlAAABCUAAEEJAEBQAgAQlAAABCUAAEEJAEBQ/wcXcWzF4y/mmQAAAABJRU5ErkJggg==",
356
+ "text/plain": [
357
+ "<IPython.core.display.Image object>"
358
+ ]
359
+ },
360
+ "execution_count": 423,
361
+ "metadata": {},
362
+ "output_type": "execute_result"
363
+ }
364
+ ],
365
+ "source": [
366
+ "from IPython.display import Image\n",
367
+ "cairosvg.svg2png(examples[0][1], write_to=\"./output.png\")\n",
368
+ "Image(filename=\"./output.png\")"
369
+ ]
370
+ },
371
+ {
372
+ "cell_type": "code",
373
+ "execution_count": 421,
374
+ "metadata": {},
375
+ "outputs": [
376
+ {
377
+ "data": {
378
+ "application/vnd.jupyter.widget-view+json": {
379
+ "model_id": "ee645e163c8144498689b13747ecd2f2",
380
+ "version_major": 2,
381
+ "version_minor": 0
382
+ },
383
+ "text/plain": [
384
+ "Resolving data files: 0%| | 0/10001 [00:00<?, ?it/s]"
385
+ ]
386
+ },
387
+ "metadata": {},
388
+ "output_type": "display_data"
389
+ },
390
+ {
391
+ "data": {
392
+ "application/vnd.jupyter.widget-view+json": {
393
+ "model_id": "d79680a43a5d4de0a917de4c03da6bb2",
394
+ "version_major": 2,
395
+ "version_minor": 0
396
+ },
397
+ "text/plain": [
398
+ "Downloading data: 0%| | 0/10001 [00:00<?, ?files/s]"
399
+ ]
400
+ },
401
+ "metadata": {},
402
+ "output_type": "display_data"
403
+ },
404
+ {
405
+ "data": {
406
+ "application/vnd.jupyter.widget-view+json": {
407
+ "model_id": "637f82e0971543f5929c786c8c40b047",
408
+ "version_major": 2,
409
+ "version_minor": 0
410
+ },
411
+ "text/plain": [
412
+ "Generating train split: 0 examples [00:00, ? examples/s]"
413
+ ]
414
+ },
415
+ "metadata": {},
416
+ "output_type": "display_data"
417
+ }
418
+ ],
419
+ "source": [
420
+ "# Create Dataset object\n",
421
+ "from datasets import load_dataset\n",
422
+ "\n",
423
+ "shapes_dataset = load_dataset(\"imagefolder\", data_dir=\"./data/shapes\")\n"
424
+ ]
425
+ },
426
+ {
427
+ "cell_type": "code",
428
+ "execution_count": 422,
429
+ "metadata": {},
430
+ "outputs": [
431
+ {
432
+ "data": {
433
+ "application/vnd.jupyter.widget-view+json": {
434
+ "model_id": "a271274070c84c7fb7d2fe8cdb7d471c",
435
+ "version_major": 2,
436
+ "version_minor": 0
437
+ },
438
+ "text/plain": [
439
+ "Uploading the dataset shards: 0%| | 0/1 [00:00<?, ?it/s]"
440
+ ]
441
+ },
442
+ "metadata": {},
443
+ "output_type": "display_data"
444
+ },
445
+ {
446
+ "data": {
447
+ "application/vnd.jupyter.widget-view+json": {
448
+ "model_id": "119330c1626b4ea28fea8418df8210de",
449
+ "version_major": 2,
450
+ "version_minor": 0
451
+ },
452
+ "text/plain": [
453
+ "Map: 0%| | 0/10000 [00:00<?, ? examples/s]"
454
+ ]
455
+ },
456
+ "metadata": {},
457
+ "output_type": "display_data"
458
+ },
459
+ {
460
+ "data": {
461
+ "application/vnd.jupyter.widget-view+json": {
462
+ "model_id": "32e80b41ef544d64b5b3a5f21e4ef15b",
463
+ "version_major": 2,
464
+ "version_minor": 0
465
+ },
466
+ "text/plain": [
467
+ "Creating parquet from Arrow format: 0%| | 0/100 [00:00<?, ?ba/s]"
468
+ ]
469
+ },
470
+ "metadata": {},
471
+ "output_type": "display_data"
472
+ },
473
+ {
474
+ "data": {
475
+ "application/vnd.jupyter.widget-view+json": {
476
+ "model_id": "8c2a3a613ea047059ead76da4b191636",
477
+ "version_major": 2,
478
+ "version_minor": 0
479
+ },
480
+ "text/plain": [
481
+ "Uploading...: 0%| | 0.00/29.5M [00:00<?, ?B/s]"
482
+ ]
483
+ },
484
+ "metadata": {},
485
+ "output_type": "display_data"
486
+ },
487
+ {
488
+ "data": {
489
+ "application/vnd.jupyter.widget-view+json": {
490
+ "model_id": "27e4f630d9b340fe80353ed8b11b91f8",
491
+ "version_major": 2,
492
+ "version_minor": 0
493
+ },
494
+ "text/plain": [
495
+ "README.md: 0%| | 0.00/347 [00:00<?, ?B/s]"
496
+ ]
497
+ },
498
+ "metadata": {},
499
+ "output_type": "display_data"
500
+ },
501
+ {
502
+ "data": {
503
+ "text/plain": [
504
+ "CommitInfo(commit_url='https://huggingface.co/datasets/darknoon/simple-shapes-svg/commit/d9f47eeaa9b84d78c01cbe0df90d3413ea57ce62', commit_message='Upload dataset', commit_description='', oid='d9f47eeaa9b84d78c01cbe0df90d3413ea57ce62', pr_url=None, repo_url=RepoUrl('https://huggingface.co/datasets/darknoon/simple-shapes-svg', endpoint='https://huggingface.co', repo_type='dataset', repo_id='darknoon/simple-shapes-svg'), pr_revision=None, pr_num=None)"
505
+ ]
506
+ },
507
+ "execution_count": 422,
508
+ "metadata": {},
509
+ "output_type": "execute_result"
510
+ }
511
+ ],
512
+ "source": [
513
+ "shapes_dataset.push_to_hub(\"darknoon/simple-shapes-svg\")"
514
+ ]
515
+ }
516
+ ],
517
+ "metadata": {
518
+ "kernelspec": {
519
+ "display_name": ".venv",
520
+ "language": "python",
521
+ "name": "python3"
522
+ },
523
+ "language_info": {
524
+ "codemirror_mode": {
525
+ "name": "ipython",
526
+ "version": 3
527
+ },
528
+ "file_extension": ".py",
529
+ "mimetype": "text/x-python",
530
+ "name": "python",
531
+ "nbconvert_exporter": "python",
532
+ "pygments_lexer": "ipython3",
533
+ "version": "3.12.10"
534
+ },
535
+ "orig_nbformat": 4
536
+ },
537
+ "nbformat": 4,
538
+ "nbformat_minor": 2
539
+ }