artificialhoney commited on
Commit
6893772
1 Parent(s): 956b3b5

feat css3 colors

Browse files
.gitignore CHANGED
@@ -2,4 +2,5 @@
2
  images/
3
  conditioning/
4
  files.list
5
- __pycache__/
 
 
2
  images/
3
  conditioning/
4
  files.list
5
+ __pycache__/
6
+ batch.py
README.md CHANGED
@@ -9,10 +9,10 @@ dataset_info:
9
  dtype: string
10
  splits:
11
  - name: train
12
- num_bytes: 8373338923
13
  num_examples: 77478
14
- download_size: 16124853637
15
- dataset_size: 8373338923
16
  ---
17
  # Dataset Card for Graffiti
18
 
 
9
  dtype: string
10
  splits:
11
  - name: train
12
+ num_bytes: 8371549111
13
  num_examples: 77478
14
+ download_size: 16130259612
15
+ dataset_size: 8371549111
16
  ---
17
  # Dataset Card for Graffiti
18
 
cli.py CHANGED
@@ -10,8 +10,7 @@ import os
10
 
11
  from controlnet_aux.processor import Processor
12
  from colorthief import ColorThief
13
- from colors import name_that_color
14
- import webcolors
15
 
16
  from PIL import Image
17
 
@@ -243,8 +242,9 @@ class CLI():
243
 
244
  palette = []
245
  for color in color_thief.get_palette(color_count=6):
246
- color_name = name_that_color(webcolors.rgb_to_hex(color))
247
- palette.append(color_name)
 
248
 
249
  json.dump({
250
  "file": data["file"],
 
10
 
11
  from controlnet_aux.processor import Processor
12
  from colorthief import ColorThief
13
+ from colors import name_that_color, rgb_to_hex, NTC_NAMES, CSS3_NAMES
 
14
 
15
  from PIL import Image
16
 
 
242
 
243
  palette = []
244
  for color in color_thief.get_palette(color_count=6):
245
+ color_hex = rgb_to_hex(color)
246
+ palette.append([color_hex, name_that_color(color_hex, NTC_NAMES), name_that_color(color_hex, CSS3_NAMES)])
247
+
248
 
249
  json.dump({
250
  "file": data["file"],
colors.py CHANGED
@@ -1,4 +1,144 @@
1
- import webcolors
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  NTC_NAMES = [
4
  ["4C4F56", "Abbey", 76, 79, 86, 157, 15, 81],
@@ -1569,7 +1709,7 @@ NTC_NAMES = [
1569
  ["EDF6FF", "Zumthor", 237, 246, 255, 148, 255, 246],
1570
  ]
1571
 
1572
- def name_that_color(color):
1573
  color = color.upper()
1574
  if len(color) < 3 or len(color) > 7:
1575
  return ["#000000", "Invalid Color: " + color, False]
@@ -1586,16 +1726,16 @@ def name_that_color(color):
1586
  ndf = 0
1587
  cl = -1
1588
  df = -1
1589
- for i in range(len(NTC_NAMES)):
1590
- if color == "#" + NTC_NAMES[i][0]:
1591
- return ["#" + NTC_NAMES[i][0], NTC_NAMES[i][1], True]
1592
- ndf1 = (r - NTC_NAMES[i][2]) ** 2 + (g - NTC_NAMES[i][3]) ** 2 + (b - NTC_NAMES[i][4]) ** 2
1593
- ndf2 = (h - NTC_NAMES[i][5]) ** 2 + (s - NTC_NAMES[i][6]) ** 2 + (l - NTC_NAMES[i][7]) ** 2
1594
  ndf = ndf1 + ndf2 * 2
1595
  if df < 0 or df > ndf:
1596
  df = ndf
1597
  cl = i
1598
- return ["#000000", "Invalid Color: " + color, False] if cl < 0 else ["#" + NTC_NAMES[cl][0], NTC_NAMES[cl][1], False]
1599
 
1600
  def hex_to_hsl(color):
1601
  rgb = [int('0x' + color[1:3], 16) / 255, int('0x' + color[3:5], 16) / 255, int('0x' + color[5:7], 16) / 255]
@@ -1620,22 +1760,5 @@ def hex_to_hsl(color):
1620
  def hex_to_rgb(color):
1621
  return [int('0x' + color[1:3], 16), int('0x' + color[3:5], 16), int('0x' + color[5:7], 16)]
1622
 
1623
- def closest_colour(requested_colour):
1624
- min_colours = {}
1625
- for key, name in webcolors.CSS3_HEX_TO_NAMES.items():
1626
- r_c, g_c, b_c = webcolors.hex_to_rgb(key)
1627
- rd = (r_c - requested_colour[0]) ** 2
1628
- gd = (g_c - requested_colour[1]) ** 2
1629
- bd = (b_c - requested_colour[2]) ** 2
1630
- min_colours[(rd + gd + bd)] = name
1631
- return min_colours[min(min_colours.keys())]
1632
-
1633
- def get_colour_name(requested_colour):
1634
- hex_value = webcolors.rgb_to_hex(requested_colour)
1635
- ntc_value = name_that_color(hex_value)
1636
- try:
1637
- closest_name = actual_name = webcolors.rgb_to_name(requested_colour)
1638
- except ValueError:
1639
- closest_name = closest_colour(requested_colour)
1640
- actual_name = None
1641
- return hex_value, actual_name, closest_name, ntc_value
 
1
+ CSS3_NAMES = [
2
+ ["f0f8ff", "aliceblue", 240, 248, 255, 147, 255, 247],
3
+ ["faebd7", "antiquewhite", 250, 235, 215, 24, 198, 232],
4
+ ["00ffff", "cyan", 0, 255, 255, 127, 255, 127],
5
+ ["7fffd4", "aquamarine", 127, 255, 212, 113, 255, 191],
6
+ ["f0ffff", "azure", 240, 255, 255, 127, 255, 247],
7
+ ["f5f5dc", "beige", 245, 245, 220, 42, 141, 232],
8
+ ["ffe4c4", "bisque", 255, 228, 196, 23, 254, 225],
9
+ ["000000", "black", 0, 0, 0, 0, 0, 0],
10
+ ["ffebcd", "blanchedalmond", 255, 235, 205, 25, 255, 230],
11
+ ["0000ff", "blue", 0, 0, 255, 170, 255, 127],
12
+ ["8a2be2", "blueviolet", 138, 43, 226, 192, 193, 134],
13
+ ["a52a2a", "brown", 165, 42, 42, 0, 151, 103],
14
+ ["deb887", "burlywood", 222, 184, 135, 23, 145, 178],
15
+ ["5f9ea0", "cadetblue", 95, 158, 160, 128, 65, 127],
16
+ ["7fff00", "chartreuse", 127, 255, 0, 63, 255, 127],
17
+ ["d2691e", "chocolate", 210, 105, 30, 17, 191, 120],
18
+ ["ff7f50", "coral", 255, 127, 80, 11, 255, 167],
19
+ ["6495ed", "cornflowerblue", 100, 149, 237, 154, 201, 168],
20
+ ["fff8dc", "cornsilk", 255, 248, 220, 33, 255, 237],
21
+ ["dc143c", "crimson", 220, 20, 60, -8, 212, 120],
22
+ ["00008b", "darkblue", 0, 0, 139, 170, 255, 69],
23
+ ["008b8b", "darkcyan", 0, 139, 139, 127, 255, 69],
24
+ ["b8860b", "darkgoldenrod", 184, 134, 11, 30, 226, 97],
25
+ ["a9a9a9", "darkgrey", 169, 169, 169, 0, 0, 169],
26
+ ["006400", "darkgreen", 0, 100, 0, 85, 255, 50],
27
+ ["bdb76b", "darkkhaki", 189, 183, 107, 39, 97, 148],
28
+ ["8b008b", "darkmagenta", 139, 0, 139, -42, 255, 69],
29
+ ["556b2f", "darkolivegreen", 85, 107, 47, 58, 99, 77],
30
+ ["ff8c00", "darkorange", 255, 140, 0, 23, 255, 127],
31
+ ["9932cc", "darkorchid", 153, 50, 204, 198, 154, 127],
32
+ ["8b0000", "darkred", 139, 0, 0, 0, 255, 69],
33
+ ["e9967a", "darksalmon", 233, 150, 122, 10, 182, 177],
34
+ ["8fbc8f", "darkseagreen", 143, 188, 143, 85, 64, 165],
35
+ ["483d8b", "darkslateblue", 72, 61, 139, 175, 99, 100],
36
+ ["2f4f4f", "darkslategrey", 47, 79, 79, 127, 64, 63],
37
+ ["00ced1", "darkturquoise", 0, 206, 209, 128, 255, 104],
38
+ ["9400d3", "darkviolet", 148, 0, 211, 199, 255, 105],
39
+ ["ff1493", "deeppink", 255, 20, 147, -22, 255, 137],
40
+ ["00bfff", "deepskyblue", 0, 191, 255, 138, 255, 127],
41
+ ["696969", "dimgrey", 105, 105, 105, 0, 0, 105],
42
+ ["1e90ff", "dodgerblue", 30, 144, 255, 148, 255, 142],
43
+ ["b22222", "firebrick", 178, 34, 34, 0, 173, 105],
44
+ ["fffaf0", "floralwhite", 255, 250, 240, 28, 255, 247],
45
+ ["228b22", "forestgreen", 34, 139, 34, 85, 154, 86],
46
+ ["ff00ff", "magenta", 255, 0, 255, -42, 255, 127],
47
+ ["dcdcdc", "gainsboro", 220, 220, 220, 0, 0, 220],
48
+ ["f8f8ff", "ghostwhite", 248, 248, 255, 170, 255, 251],
49
+ ["ffd700", "gold", 255, 215, 0, 35, 255, 127],
50
+ ["daa520", "goldenrod", 218, 165, 32, 30, 189, 125],
51
+ ["808080", "grey", 128, 128, 128, 0, 0, 128],
52
+ ["008000", "green", 0, 128, 0, 85, 255, 64],
53
+ ["adff2f", "greenyellow", 173, 255, 47, 59, 255, 151],
54
+ ["f0fff0", "honeydew", 240, 255, 240, 85, 255, 247],
55
+ ["ff69b4", "hotpink", 255, 105, 180, -21, 254, 179],
56
+ ["cd5c5c", "indianred", 205, 92, 92, 0, 135, 148],
57
+ ["4b0082", "indigo", 75, 0, 130, 194, 255, 65],
58
+ ["fffff0", "ivory", 255, 255, 240, 42, 255, 247],
59
+ ["f0e68c", "khaki", 240, 230, 140, 38, 196, 190],
60
+ ["e6e6fa", "lavender", 230, 230, 250, 170, 169, 240],
61
+ ["fff0f5", "lavenderblush", 255, 240, 245, -14, 255, 247],
62
+ ["7cfc00", "lawngreen", 124, 252, 0, 64, 255, 126],
63
+ ["fffacd", "lemonchiffon", 255, 250, 205, 38, 255, 230],
64
+ ["add8e6", "lightblue", 173, 216, 230, 137, 135, 201],
65
+ ["f08080", "lightcoral", 240, 128, 128, 0, 201, 184],
66
+ ["e0ffff", "lightcyan", 224, 255, 255, 127, 255, 239],
67
+ ["fafad2", "lightgoldenrodyellow", 250, 250, 210, 42, 203, 229],
68
+ ["d3d3d3", "lightgrey", 211, 211, 211, 0, 0, 211],
69
+ ["90ee90", "lightgreen", 144, 238, 144, 85, 187, 191],
70
+ ["ffb6c1", "lightpink", 255, 182, 193, -6, 255, 218],
71
+ ["ffa07a", "lightsalmon", 255, 160, 122, 12, 255, 188],
72
+ ["20b2aa", "lightseagreen", 32, 178, 170, 125, 177, 105],
73
+ ["87cefa", "lightskyblue", 135, 206, 250, 143, 234, 192],
74
+ ["778899", "lightslategrey", 119, 136, 153, 148, 36, 136],
75
+ ["b0c4de", "lightsteelblue", 176, 196, 222, 151, 104, 199],
76
+ ["ffffe0", "lightyellow", 255, 255, 224, 42, 255, 239],
77
+ ["00ff00", "lime", 0, 255, 0, 85, 255, 127],
78
+ ["32cd32", "limegreen", 50, 205, 50, 85, 155, 127],
79
+ ["faf0e6", "linen", 250, 240, 230, 21, 169, 240],
80
+ ["800000", "maroon", 128, 0, 0, 0, 255, 64],
81
+ ["66cdaa", "mediumaquamarine", 102, 205, 170, 113, 129, 153],
82
+ ["0000cd", "mediumblue", 0, 0, 205, 170, 255, 102],
83
+ ["ba55d3", "mediumorchid", 186, 85, 211, 204, 150, 147],
84
+ ["9370db", "mediumpurple", 147, 112, 219, 183, 152, 165],
85
+ ["3cb371", "mediumseagreen", 60, 179, 113, 103, 126, 119],
86
+ ["7b68ee", "mediumslateblue", 123, 104, 238, 176, 203, 171],
87
+ ["00fa9a", "mediumspringgreen", 0, 250, 154, 111, 255, 125],
88
+ ["48d1cc", "mediumturquoise", 72, 209, 204, 125, 152, 140],
89
+ ["c71585", "mediumvioletred", 199, 21, 133, -26, 206, 110],
90
+ ["191970", "midnightblue", 25, 25, 112, 170, 161, 68],
91
+ ["f5fffa", "mintcream", 245, 255, 250, 106, 255, 250],
92
+ ["ffe4e1", "mistyrose", 255, 228, 225, 4, 255, 240],
93
+ ["ffe4b5", "moccasin", 255, 228, 181, 26, 255, 218],
94
+ ["ffdead", "navajowhite", 255, 222, 173, 25, 255, 214],
95
+ ["000080", "navy", 0, 0, 128, 170, 255, 64],
96
+ ["fdf5e6", "oldlace", 253, 245, 230, 27, 217, 241],
97
+ ["808000", "olive", 128, 128, 0, 42, 255, 64],
98
+ ["6b8e23", "olivedrab", 107, 142, 35, 56, 154, 88],
99
+ ["ffa500", "orange", 255, 165, 0, 27, 255, 127],
100
+ ["ff4500", "orangered", 255, 69, 0, 11, 255, 127],
101
+ ["da70d6", "orchid", 218, 112, 214, -40, 150, 164],
102
+ ["eee8aa", "palegoldenrod", 238, 232, 170, 38, 170, 204],
103
+ ["98fb98", "palegreen", 152, 251, 152, 85, 235, 201],
104
+ ["afeeee", "paleturquoise", 175, 238, 238, 127, 165, 206],
105
+ ["db7093", "palevioletred", 219, 112, 147, -13, 152, 165],
106
+ ["ffefd5", "papayawhip", 255, 239, 213, 26, 255, 234],
107
+ ["ffdab9", "peachpuff", 255, 218, 185, 20, 255, 220],
108
+ ["cd853f", "peru", 205, 133, 63, 20, 149, 134],
109
+ ["ffc0cb", "pink", 255, 192, 203, -7, 255, 223],
110
+ ["dda0dd", "plum", 221, 160, 221, -42, 120, 190],
111
+ ["b0e0e6", "powderblue", 176, 224, 230, 132, 132, 203],
112
+ ["800080", "purple", 128, 0, 128, -42, 255, 64],
113
+ ["ff0000", "red", 255, 0, 0, 0, 255, 127],
114
+ ["bc8f8f", "rosybrown", 188, 143, 143, 0, 64, 165],
115
+ ["4169e1", "royalblue", 65, 105, 225, 159, 185, 145],
116
+ ["8b4513", "saddlebrown", 139, 69, 19, 17, 193, 78],
117
+ ["fa8072", "salmon", 250, 128, 114, 4, 237, 182],
118
+ ["f4a460", "sandybrown", 244, 164, 96, 19, 222, 170],
119
+ ["2e8b57", "seagreen", 46, 139, 87, 103, 128, 92],
120
+ ["fff5ee", "seashell", 255, 245, 238, 17, 255, 246],
121
+ ["a0522d", "sienna", 160, 82, 45, 13, 143, 102],
122
+ ["c0c0c0", "silver", 192, 192, 192, 0, 0, 192],
123
+ ["87ceeb", "skyblue", 135, 206, 235, 139, 182, 185],
124
+ ["6a5acd", "slateblue", 106, 90, 205, 175, 136, 147],
125
+ ["708090", "slategrey", 112, 128, 144, 148, 32, 128],
126
+ ["fffafa", "snow", 255, 250, 250, 0, 255, 252],
127
+ ["00ff7f", "springgreen", 0, 255, 127, 106, 255, 127],
128
+ ["4682b4", "steelblue", 70, 130, 180, 146, 112, 125],
129
+ ["d2b48c", "tan", 210, 180, 140, 24, 111, 175],
130
+ ["008080", "teal", 0, 128, 128, 127, 255, 64],
131
+ ["d8bfd8", "thistle", 216, 191, 216, -42, 61, 203],
132
+ ["ff6347", "tomato", 255, 99, 71, 6, 254, 163],
133
+ ["40e0d0", "turquoise", 64, 224, 208, 123, 183, 144],
134
+ ["ee82ee", "violet", 238, 130, 238, -42, 193, 184],
135
+ ["f5deb3", "wheat", 245, 222, 179, 27, 195, 211],
136
+ ["ffffff", "white", 255, 255, 255, 0, 0, 255],
137
+ ["f5f5f5", "whitesmoke", 245, 245, 245, 0, 0, 245],
138
+ ["ffff00", "yellow", 255, 255, 0, 42, 255, 127],
139
+ ["9acd32", "yellowgreen", 154, 205, 50, 56, 155, 127],
140
+ ]
141
+
142
 
143
  NTC_NAMES = [
144
  ["4C4F56", "Abbey", 76, 79, 86, 157, 15, 81],
 
1709
  ["EDF6FF", "Zumthor", 237, 246, 255, 148, 255, 246],
1710
  ]
1711
 
1712
+ def name_that_color(color, names):
1713
  color = color.upper()
1714
  if len(color) < 3 or len(color) > 7:
1715
  return ["#000000", "Invalid Color: " + color, False]
 
1726
  ndf = 0
1727
  cl = -1
1728
  df = -1
1729
+ for i in range(len(names)):
1730
+ if color == "#" + names[i][0]:
1731
+ return ["#" + names[i][0], names[i][1], True]
1732
+ ndf1 = (r - names[i][2]) ** 2 + (g - names[i][3]) ** 2 + (b - names[i][4]) ** 2
1733
+ ndf2 = (h - names[i][5]) ** 2 + (s - names[i][6]) ** 2 + (l - names[i][7]) ** 2
1734
  ndf = ndf1 + ndf2 * 2
1735
  if df < 0 or df > ndf:
1736
  df = ndf
1737
  cl = i
1738
+ return ["#000000", "Invalid Color: " + color, False] if cl < 0 else ["#" + names[cl][0], names[cl][1], False]
1739
 
1740
  def hex_to_hsl(color):
1741
  rgb = [int('0x' + color[1:3], 16) / 255, int('0x' + color[3:5], 16) / 255, int('0x' + color[5:7], 16) / 255]
 
1760
  def hex_to_rgb(color):
1761
  return [int('0x' + color[1:3], 16), int('0x' + color[3:5], 16), int('0x' + color[5:7], 16)]
1762
 
1763
+ def rgb_to_hex(color):
1764
+ return '#{:02x}{:02x}{:02x}'.format(*color)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
data/graffiti-database.com/metadata.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5da51677a29f6db9ce29b0e07368e9c2efd5e36e15d1342db420f5a2270275e0
3
- size 21153581
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9db53158c7b6461b799b4b8e58255215d60d18cb59750ae89ea86f6c9cfe9e99
3
+ size 24220066
data/graffiti.org/metadata.jsonl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:42b3833b040590704bd02aca030019d2c3018c5e8e59d2e3c6c6d85cc027f579
3
- size 12314494
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a758ab6bfbb1f86173b5856e799646ebacaf12c62d918cd7f0a466807ad0b2e1
3
+ size 14653984
graffiti.py CHANGED
@@ -120,13 +120,14 @@ class Graffiti(datasets.GeneratorBasedBuilder):
120
 
121
  text = data["caption"]
122
  if data["palette"] != None:
123
- text += ", in the colors "
124
  colors = []
125
  for color in data["palette"]:
126
- if color[1] in colors:
127
  continue
128
- colors.append(color[1])
129
- text += " and ".join(colors)
 
 
130
  if data["artist"] != None:
131
  # text += ", with text " + data["artist"]
132
  text += ", by " + data["artist"]
 
120
 
121
  text = data["caption"]
122
  if data["palette"] != None:
 
123
  colors = []
124
  for color in data["palette"]:
125
+ if color[2] in colors or "grey" in color[2]:
126
  continue
127
+ colors.append(color[2])
128
+ if len(colors) > 0:
129
+ text += ", in the colors "
130
+ text += " and ".join(colors)
131
  if data["artist"] != None:
132
  # text += ", with text " + data["artist"]
133
  text += ", by " + data["artist"]
requirements.txt CHANGED
@@ -4,5 +4,4 @@ transformers
4
  controlnet-aux==0.0.6
5
  mediapipe
6
  datasets
7
- colorthief
8
- webcolors
 
4
  controlnet-aux==0.0.6
5
  mediapipe
6
  datasets
7
+ colorthief