Logo
    →AI Text-to-Colour

    →AI Text-to-Colour

    Introduction

    I set out with a simple goal, to programatically generate colour palettes from text in a way that’s explainable. I’m determined that the colour palette should be unconstrained across the full colour space.

    Create a Clean Text Dataset

    I start in Collab to create a text dataset for development and testing purposes. I come across a government website containing 146 of Aesop’s fables. They each have their own page, with incremental URL numbers, making them easy to scrape into markdown files.

    ‣
    Dataset Creation Code

    Deciding on Approach

    I collaborate with ChatGPT to explore several methods for converting text into colour...

    • Use high-dimensional text embeddings, reduce to three dimensions for RGB values, normalise to 0-255 range, and create additional colours through strategic offsets in colour space.
    • Develop a semantic colour wheel with custom embeddings → generate text embeddings → measure cosine similarity.
    • Deploy a compact neural network trained to map text embeddings directly to RGB or HSL colour-space coordinates.
    • Transform text embedding into a prompt → generate an image with that prompt → extract dominant colours from the resulting image.

    However, these approaches seem unnecessarily complex, so I decide to start with something simpler and test its effectiveness. Here's my refined approach:

    • Conduct a thematic analysis on the text to understand its style and content.
    • Leverage this style and content analysis to generate an appropriate colour palette.

    This streamlined approach feels possible with just a couple of ChatGPT API requests. The methodology also gives us the additional benefit of explainability, as I can provide the thematic analysis output to end users, helping them understand the rationale behind the colour selection.

    Step 1: Thematic Analysis to Structured JSON

    The prompt I settled on for thematic analysis:

    You can see how this approach could aid explainability. For example you can see what influenced colour selection for ‘A Raven & A Swan’:

    Step 2: Generate Colour Palette From Structured JSON

    Now we take that thematic analysis, and get OpenAI to respond with a colour palette.

    Processing Confirmation / Output

    Processing file: The_Hare__the_Tortoise.md
    Markdown file content read successfully.
    OpenAI API call for theme analysis successful.
    Theme analysis JSON parsed successfully.
    OpenAI API call for color palette successful.
    Color palette JSON parsed successfully.
    Results for The_Hare__the_Tortoise.md stored.
    Generated color palette:
    {'color_palette': ['#4CAF50', '#FF5722', '#8BC34A', '#FFC107', '#FFEB3B', '#9E9E9E', '#795548', '#607D8B']}
    image
    ⚠️

    I realise at this point, evaluating this is going to be challenging. So rather than look across 140 fables that are all similar, I try some very different content, and check the response for that.

    A BBC news article about escalating tensions between the US and Russia and the deployment of nuclear submarines… and I’m pleasantly surprised. The results pass the gut check.

    Generated color palette:
    {'color_palette': ['#00274D', '#D9534F', '#AAB7B8', '#5D6D7E', '#F7F9F9','#A93226','#2874A6','#1C2833']}
    image

    Step 3: Computation at Scale

    To check this approach scales and doesn’t take too long, I use my dataset to generate 100+ palettes in short order. Success.

    ‣
    Tabular Results
    ID
    Name
    0
    The Wolf & the Shepherd
    #2D5016
    #B2A079
    #6C8C5B
    #9D9173
    #8B6C42
    #A3915E
    #D4CBB1
    #CCB49E
    1
    The Fox & the Lion
    #2C5F2D
    #FFAE42
    #8DB600
    #FFD700
    #A0A083
    #C19A6B
    #FFDDC1
    #4B5320
    2
    The Fox & the Leopard
    #FFAB00
    #007FFF
    #FFD700
    #00FF00
    #FF4500
    #8A2BE2
    #FF69B4
    #40E0D0
    3
    The Mole & His Mother
    #4A7B9D
    #C07C32
    #89A3B2
    #5C8A70
    #F3D5B5
    #7C3E66
    #D4E09B
    #B4CDED
    4
    The North Wind & the Sun
    #FFDD00
    #0055FF
    #FFD700
    #3399FF
    #66CC66
    #FF9900
    #CCCCFF
    #FFCCCC
    5
    A Raven & a Swan
    #264653
    #E76F51
    #468FAF
    #5A9367
    #F4A261
    #E9C46A
    #2A9D8F
    #8AB17D
    6
    The Wolf & the Lamb
    #2B3B1E
    #D4A017
    #5A7560
    #A3A9A7
    #6B544E
    #9D9D93
    #B7C7BE
    #F3EDD2
    7
    The Cat, the Cock & the Young Mouse
    #2D5016
    #FFD700
    #FF7F50
    #4682B4
    #8B4513
    #32CD32
    #FF4500
    #B22222
    8
    The Bundle of Sticks
    #284B63
    #B5651D
    #556B2F
    #8FBC8B
    #C0C0C0
    #FFD700
    #2F4F4F
    #FF4500
    9
    The Animals & the Plague
    #3B7A57
    #FFDA00
    #88B04B
    #A8D08D
    #F28C28
    #C04000
    #FFF4E5
    #D4A017
    10
    The Boy & the Nettles
    #2A511C
    #F5A623
    #7C9F4B
    #F0D77B
    #82BB2D
    #C2E88C
    #F7E5B6
    #4C6A22
    11
    The Lion, the Bear & the Fox
    #4A7023
    #A6714C
    #6B8E23
    #8B4513
    #C3B091
    #FFD700
    #8FBC8F
    #2F4F4F
    12
    The Frog & the Mouse
    #2D5016
    #BDA27E
    #4C773A
    #8C9D70
    #6B4423
    #94755B
    #3A2710
    #CFAF92
    13
    The Fox & the Grapes
    #2D6A4F
    #FFDD00
    #AACD6E
    #7A4419
    #5A3E36
    #73A942
    #F4E9B7
    #8E8484
    14
    The Farmer & the Stork
    #3A5311
    #FFD700
    #8B4513
    #7CFC00
    #FFF8DC
    #FF4500
    #4682B4
    #8A2BE2
    15
    The Cat & the Old Rat
    #1A5E63
    #F2C14E
    #286466
    #70A9A1
    #F56C42
    #295E5C
    #E2D58B
    #3E6259
    16
    The Wolf & the Ass
    #235789
    #D72638
    #F4A261
    #6B4226
    #9BC1BC
    #CDCDCD
    #468189
    #302F38
    17
    The Stag, the Sheep & the Wolf
    #124559
    #FFD700
    #8FA998
    #F5F5DC
    #8B4513
    #3CB371
    #D2B48C
    #F08080
    18
    The Sheep & the Pig
    #598F2A
    #F2A65A
    #A5C882
    #F2E2B0
    #CFE9A0
    #A6784B
    #F2D7B3
    #8C5330
    19
    The Wild Boar & the Fox
    #2B5D34
    #E09F3E
    #6D8B55
    #A67C52
    #7E4E60
    #C4A77D
    #EAE2B7
    #705D56
    20
    The Hare & the Tortoise
    #4CAF50
    #FF5722
    #8BC34A
    #FFC107
    #FFEB3B
    #9E9E9E
    #795548
    #607D8B
    21
    The Swallow & the Crow
    #2C8C28
    #DC7633
    #3498DB
    #58D68D
    #F4D03F
    #F7DC6F
    #E74C3C
    #E59866
    22
    The Fighting Bulls & the Frog
    #2B4F81
    #EFA5A5
    #6EA77B
    #C1D5DE
    #F2E394
    #91A6B2
    #DAC4B2
    #9A745B
    23
    The Ass & His Shadow
    #FFA500
    #0057B7
    #008000
    #FFD700
    #B22222
    #8B4513
    #4682B4
    #DAA520
    24
    The Gnat & the Bull
    #4A772F
    #D4A017
    #75B798
    #9DC183
    #F0E162
    #8C5E2F
    #EDC9AF
    #FFD700
    25
    The Wolf & the Sheep
    #2D5016
    #A14030
    #538D4E
    #59755F
    #C69E70
    #8B5A2B
    #A4C2A8
    #746C56
    26
    The Spendthrift & the Swallow
    #2B7A4B
    #D97706
    #FFE066
    #56A3A6
    #755A57
    #A69C8A
    #EADCA6
    #D0E1D4
    27
    The Old Lion & the Fox
    #4A3D16
    #C95C1D
    #7E7541
    #5A4E31
    #B39E77
    #D1C4A8
    #887C6B
    #A68E6A
    28
    The Lark & Her Young Ones
    #4B8E2E
    #D4A017
    #6BA544
    #D68F0E
    #FFA726
    #C5E1A5
    #8D6E63
    #FFCC80
    29
    The Monkey & the Cat
    #FFD700
    #4B0082
    #DAA520
    #8A2BE2
    #FF4500
    #32CD32
    #00CED1
    #FFB6C1
    30
    The Cock & the Fox
    #FFA500
    #2E8B57
    #FFD700
    #4682B4
    #8B4513
    #D2691E
    #FFDAB9
    #F5DEB3
    31
    The Dog & His Reflection
    #3A6F42
    #D9B310
    #89CFF0
    #4F9D9D
    #5A3E36
    #FFD700
    #8B4513
    #F4A460
    32
    The Miller, His Son & the Ass
    #3B0B39
    #F7A600
    #F2D785
    #29487D
    #8649A3
    #D8B5E1
    #85B245
    #F4DAC6
    33
    The Dog, the Cock & the Fox
    #FF5733
    #33FFCE
    #FFBD33
    #3380FF
    #B833FF
    #FF33A6
    #33FF57
    #FF8F33
    34
    The Lion, the Ass & the Fox
    #005F3F
    #ECA400
    #F7F4EA
    #71A6D2
    #A3694F
    #9CCB19
    #E7C77F
    #3B1F1F
    35
    The Mice & the Weasels
    #2C3E50
    #E74C3C
    #16A085
    #F39C12
    #8E44AD
    #2980B9
    #27AE60
    #F1C40F
    36
    The Farmer & the Cranes
    #2D5016
    #FFD700
    #8B4513
    #4682B4
    #98FB98
    #FAFAD2
    #F0E68C
    #B0C4DE
    37
    The Cat & the Fox
    #2D5016
    #7C1A02
    #4F7021
    #BDB086
    #D4B483
    #A68F60
    #785A2C
    #F2E6CE
    38
    The Two Pots
    #FF5733
    #3357FF
    #FFBD33
    #33FF57
    #FF33A6
    #33FFC7
    #A633FF
    #FFD133
    39
    The Eagle & the Jackdaw
    #2A6D26
    #FFD700
    #87CEEB
    #8B4513
    #FF69B4
    #32CD32
    #FFA07A
    #4682B4
    40
    The Porcupine & the Snakes
    #048BA8
    #EF476F
    #2A9D8F
    #F4A261
    #E76F51
    #264653
    #81C784
    #FFDD57
    41
    The Town Mouse & the Country Mouse
    #FFD700
    #8B4513
    #6B8E23
    #4682B4
    #FFFAF0
    #D2691E
    #FFE4B5
    #32CD32
    42
    The Ass & the Grasshoppers
    #2B7A0B
    #FFBF00
    #9ACD32
    #8B4513
    #6A9D68
    #FAFAD2
    #D4AF37
    #4B5320
    43
    Two Travelers & a Bear
    #005500
    #AA5500
    #777700
    #557755
    #330000
    #552200
    #446644
    #2F4F2F
    44
    The Leap at Rhodes
    #2C3E50
    #E74C3C
    #2980B9
    #27AE60
    #F1C40F
    #8E44AD
    #3498DB
    #16A085
    45
    The Fox & the Pheasants
    #4A8F29
    #F09D28
    #77C65D
    #F4E063
    #2D5016
    #936639
    #D79A2B
    #788857
    46
    The Vain JackDaw & his Borrowed Feathers
    #1E4D2B
    #E6B800
    #A3BFA8
    #F0E68C
    #8F9779
    #CC5500
    #D2691E
    #FFD700
    47
    The Heron
    #2A4D69
    #FFC857
    #76B041
    #3083DC
    #B9D8C2
    #F7FFF7
    #F4A261
    #264653
    48
    The Plane Tree
    #2D6A4F
    #FFB703
    #88D498
    #FFD60A
    #023E8A
    #E85D04
    #370617
    #606C38
    49
    The Dog in the Manger
    #2B8EAD
    #AD2D2B
    #8EAD2D
    #2D8E41
    #AD8E2D
    #2D8EAD
    #8E2DB5
    #2D3F8E
    50
    The Fox & the Stork
    #FF5733
    #337BFF
    #FFBD33
    #33FFBD
    #FFFFFF
    #FFD700
    #7FFFD4
    #FF69B4
    51
    Three Bullocks & a Lion
    #005F73
    #F77F00
    #0A9396
    #94D2BD
    #EE9B00
    #CA6702
    #BB3E03
    #AE2012
    52
    The Old Lion
    #4D2600
    #FFD700
    #8B4513
    #CD5C5C
    #D2B48C
    #A9A9A9
    #228B22
    #8FBC8F
    53
    The Birds, the Beasts & the Bat
    #2E1F52
    #FFD700
    #4B0082
    #800000
    #8B4513
    #708090
    #556B2F
    #4682B4
    54
    The Fox & the Crab
    #3C6E71
    #D9BF77
    #A8C686
    #F4A259
    #292F36
    #6B4226
    #F6AE2D
    #CB997E
    55
    The Boys & the Frogs
    #2B8EAD
    #F2F230
    #9BCCCF
    #F28A30
    #4A7A8C
    #557C55
    #A1A15D
    #9E4829
    56
    The Ass & the Lap Dog
    #2D5016
    #8A5A00
    #5D8456
    #7B7265
    #C4A484
    #9E7020
    #E4C17A
    #6C5723
    57
    The Ass Carrying the Image
    #335C67
    #E09F3E
    #9E2A2B
    #540B0E
    #F4F1BB
    #D9BF77
    #81B29A
    #F2C57C
    58
    The Frogs Who Wished for a King
    #0047AB
    #FFD700
    #8A2BE2
    #32CD32
    #48D1CC
    #FF69B4
    #CD5C5C
    #FFA07A
    59
    The Fox & the Hedgehog
    #3B5323
    #FFD700
    #8FBC8F
    #4682B4
    #BDB76B
    #A0522D
    #2E8B57
    #DAA520
    60
    The Astrologer
    #083D77
    #F4D35E
    #F4A261
    #E9C46A
    #264653
    #2A9D8F
    #E76F51
    #E63946
    61
    The Quack Toad
    #2A5B1D
    #A83232
    #6F8F49
    #B95F5F
    #F2D49B
    #C9EBD4
    #FFD48F
    #D1B1C8
    62
    The Farmer & His Sons
    #4A772F
    #F2C249
    #8FBF6E
    #417D62
    #D9A441
    #7B8D3F
    #B9C4A7
    #8A7E4E
    63
    The Monkey & the Camel
    #2E8B57
    #FFD700
    #8B4513
    #4682B4
    #FF7F50
    #D2691E
    #CD5C5C
    #7FFF00
    64
    The Man & the Satyr
    #136F3C
    #D4A017
    #479B62
    #B4C674
    #8E5A2C
    #593D1B
    #7A7245
    #5F513F
    65
    The Goose & the Golden Egg
    #2E4057
    #D4AF37
    #6B8E23
    #8FBC8F
    #F4A460
    #4682B4
    #FFD700
    #A52A2A
    66
    The Wolf, the Kid & the Goat
    #4D4F23
    #B5651D
    #8FA03C
    #C19A6B
    #7F7F52
    #E9D66B
    #C8A165
    #987654
    67
    The Peacock
    #2A4D14
    #8B4513
    #3B7A57
    #6B4226
    #4F7F50
    #AF8F62
    #60706E
    #A8B7AB
    68
    The Wolf in Sheep's Clothing
    #6B8E23
    #FF4500
    #FFD700
    #8B4513
    #4682B4
    #2E8B57
    #DDA0DD
    #F0E68C
    69
    The Man & the Lion
    #2A7F24
    #F4A261
    #B4C424
    #264653
    #E76F51
    #F2E394
    #D69F7E
    #264653
    70
    The Wolf & the House Dog
    #2C3E50
    #E74C3C
    #3498DB
    #1ABC9C
    #F1C40F
    #9B59B6
    #E67E22
    #34495E
    71
    The Flies & the Honey
    #C39E27
    #276AC3
    #D4B483
    #FFE39C
    #8C7536
    #6A4A3C
    #F7D488
    #84A3C9
    72
    The Mule
    #28A745
    #FFDD57
    #7DCFB6
    #F783AC
    #FFD700
    #8A9A5B
    #FF6347
    #C4B454
    73
    The Bear & the Bees
    #2A3B1D
    #D9A441
    #7A8F47
    #BF977D
    #F4E3C1
    #8C6442
    #3F5B29
    #B2AB8C
    74
    The Goatherd & the Goat
    #2F4F4F
    #FFA07A
    #8FBC8F
    #4682B4
    #FFD700
    #F0E68C
    #EEE8AA
    #556B2F
    75
    The Shepherd Boy & the Wolf
    #2E8B57
    #FF6347
    #FFD700
    #4682B4
    #8B4513
    #32CD32
    #8A2BE2
    #D3D3D3
    76
    The Travelers & the Sea
    #1B3B6F
    #FFCC33
    #4C91AF
    #FFD700
    #B0E0E6
    #8FBC8F
    #FA8072
    #2E8B57
    77
    The Wolf & His Shadow
    #2D3E16
    #B8A71E
    #6C5B7B
    #C06C84
    #F67280
    #355C7D
    #B0E57C
    #FF6347
    78
    The Travelers & the Purse
    #336699
    #CC3300
    #6699CC
    #993300
    #CC9966
    #666633
    #FFCC99
    #996633
    79
    The Fisherman & the Little Fish
    #2E8B57
    #FFD700
    #4682B4
    #B0C4DE
    #8B4513
    #FFFFE0
    #20B2AA
    #F0E68C
    80
    The Hare & His Ears
    #0B3D91
    #FFD700
    #8B4513
    #228B22
    #FF4500
    #6A5ACD
    #00CED1
    #D2691E
    81
    The Shepherd & the Lion
    #2E4053
    #A93226
    #2874A6
    #1ABC9C
    #F4D03F
    #8E44AD
    #5D6D7E
    #D4AC0D
    82
    The Fox & the Crow
    #2D5016
    #F2AA4C
    #728C69
    #F2E6D0
    #C75643
    #96C5F2
    #E3F294
    #A67B5B
    83
    The Serpent & the Eagle
    #2E8B57
    #FFD700
    #8B4513
    #6495ED
    #FFF5EE
    #FF4500
    #B22222
    #00FA9A
    84
    The Sick Stag
    #2E8B57
    #FF4500
    #8FBC8F
    #FFA07A
    #DEB887
    #BDB76B
    #7FFF00
    #4682B4
    85
    The Mother & the Wolf
    #FF4500
    #008080
    #FFD700
    #32CD32
    #8B4513
    #4682B4
    #FF6347
    #FFDAB9
    86
    The Frogs & the Ox
    #2A5D34
    #F2C300
    #8FCB9B
    #FFD966
    #5A8E7C
    #F4A742
    #B6D4A6
    #3F6953
    87
    The Wolf & the Lean Dog
    #3E6B48
    #BF3B2B
    #7F9D8D
    #A3C1AD
    #D3CEC4
    #867D59
    #4B3B47
    #7D4F44
    88
    The Fox Without a Tail
    #2F4F4F
    #FFD700
    #8FBC8F
    #BC8F8F
    #4682B4
    #B22222
    #FAFAD2
    #556B2F
    89
    The Ants & the Grasshopper
    #3C8D0D
    #FFBB33
    #75D507
    #669900
    #33CCFF
    #FF5733
    #FFC300
    #DAF7A6
    90
    Mercury & the Woodman
    #1D5F29
    #F2B134
    #7DA453
    #D97A35
    #C3D9A5
    #8C564B
    #2B3E2F
    #998675
    91
    The Stag & His Reflection
    #1B5E20
    #FFC107
    #388E3C
    #FFEB3B
    #8BC34A
    #FF5722
    #3E2723
    #4CAF50
    92
    The Wolves & the Sheep
    #6B8E23
    #FF4500
    #FFD700
    #8B4513
    #DDA0DD
    #87CEEB
    #8FBC8F
    #F5DEB3
    93
    The Oak & the Reeds
    #3A7356
    #D4A017
    #7DA184
    #5C4F48
    #C3A89B
    #B2C4A2
    #857B82
    #A9BFB5
    94
    The Bull & the Goat
    #3B3C36
    #C29B2E
    #76877D
    #B0A67D
    #4C3F30
    #7A643A
    #A87E4A
    #624836
    95
    The Mischievous Dog
    #0048BA
    #FBC02D
    #A5D6A7
    #FFC107
    #8D6E63
    #C5E1A5
    #FFF176
    #81D4FA
    96
    The Dog & his Master's Dinner
    #2A7F62
    #FC814A
    #FCD34B
    #81B29A
    #F4EBDB
    #3B3C36
    #FAF3E0
    #929487
    97
    The Rat & the Elephant
    #2A1B0A
    #D4A017
    #5C4033
    #FFC857
    #B88B4A
    #F4E285
    #726E60
    #8AB6D6
    98
    The Rabbit, the Weasel & the Cat
    #2D572C
    #FFCC00
    #8C6A4F
    #006400
    #B2BEB5
    #A2C523
    #FFD700
    #8B4513
    99
    The Bat & the Weasels
    #2D5016
    #BE4B49
    #A1C935
    #3D7328
    #5A4F49
    #D1A566
    #798A63
    #FFC857
    100
    The Dogs & the Hides
    #2A3A45
    #8A715B
    #467387
    #7D9F77
    #A4A990
    #CDD9B5
    #DEB073
    #6B5947
    101
    The Goatherd & the Wild Goats
    #002B36
    #B58900
    #2AA198
    #268BD2
    #859900
    #D33682
    #6C71C4
    #93A1A1
    102
    Belling the Cat
    #FF5733
    #1F618D
    #28B463
    #F7DC6F
    #AF7AC5
    #85C1E9
    #F5B7B1
    #F0E68C
    103
    The Eagle & the Kite
    #2F4F4F
    #FFD700
    #8FBC8F
    #4682B4
    #D3D3D3
    #8B4513
    #708090
    #C0C0C0
    104
    The Wolf & the Goat
    #2E4053
    #F39C12
    #66CDAA
    #B22222
    #8FBC8F
    #FFD700
    #F0E68C
    #D3D3D3
    105
    The Monkey & the Dolphin
    #22577E
    #57CC99
    #38A3A5
    #80ED99
    #C7F9CC
    #E8F9F3
    #57A773
    #009688
    106
    The Ass & His Driver
    #2E4057
    #C2894B
    #847F81
    #B2ABB4
    #6E5848
    #B7AC92
    #D9C3B7
    #593F2A
    107
    The Peacock & the Crane
    #2D5016
    #FFA500
    #B0C4DE
    #F0E68C
    #8A2BE2
    #20B2AA
    #FF6347
    #DAA520
    108
    Hercules & the Wagoner
    #2E8B57
    #FFD700
    #6B8E23
    #8B4513
    #A0522D
    #D2B48C
    #556B2F
    #DEB887
    109
    The Milkmaid & Her Pail
    #467B32
    #FFD700
    #8B4513
    #F4A460
    #F5F5DC
    #C0C0C0
    #D2691E
    #B0E0E6
    110
    The Cat & the Birds
    #3A6B35
    #8B4513
    #46732E
    #725F3F
    #F5DEB3
    #FFD700
    #556B2F
    #E9967A
    111
    The Oxen & the Wheels
    #7A4419
    #273D52
    #AC8D7D
    #6E8B3D
    #F5C36E
    #8C4F3F
    #CAC0A7
    #5A6F39
    112
    The Wolf & the Crane
    #005A1F
    #B22222
    #6B8E23
    #D2691E
    #8B4513
    #2E8B57
    #708090
    #DAA520
    113
    The Crow & the Pitcher
    #FFA500
    #00539C
    #FFD700
    #8FBC8F
    #708090
    #D2691E
    #C0C0C0
    #483D8B
    114
    The Hares & the Frogs
    #2C5F2D
    #BF8F00
    #6B4226
    #636363
    #B7A57A
    #32612D
    #FFEB3B
    #BF360C
    115
    The Lion's Share
    #2A4F1E
    #D9A441
    #61823A
    #8B5E3C
    #F4AA2F
    #C94545
    #9C6A29
    #747474
    116
    The Dogs & the Fox
    #2E8B57
    #FFD700
    #CD853F
    #8B0000
    #D2691E
    #B0C4DE
    #556B2F
    #8B4513
    117
    The Fox & the Goat
    #006400
    #FFD700
    #8B4513
    #2E8B57
    #D2691E
    #8FBC8F
    #ADFF2F
    #F0E68C
    118
    The Fox & the Monkey
    #236B2E
    #FFD700
    #8FBC8F
    #4682B4
    #C71585
    #FF6347
    #20B2AA
    #FFDAB9
    119
    The Ass in the Lion's Skin
    #1B5E20
    #FF6F00
    #4CAF50
    #FFC107
    #B39DDB
    #FFCDD2
    #FFE082
    #C8E6C9
    120
    The Kid & the Wolf
    #4A7A8C
    #FFD700
    #B3C1A9
    #9A8F7B
    #C2A5BC
    #F5E0C3
    #5F5E3D
    #D9BF77
    121
    The Lion & the Gnat
    #1A661A
    #FFA500
    #228B22
    #FFD700
    #32CD32
    #8B4513
    #708090
    #FF6347
    122
    The Farmer & the Snake
    #1F618D
    #E74C3C
    #2980B9
    #3498DB
    #F1C40F
    #F39C12
    #D5DBDB
    #AAB7B8
    123
    The Rose & the Butterfly
    #3B6F3E
    #B03A2E
    #FFD700
    #8E44AD
    #F5B041
    #5DADE2
    #27AE60
    #EC7063
    124
    The Owl & the Grasshopper
    #2E8B57
    #FFD700
    #8FBC8F
    #BDB76B
    #6B8E23
    #DAA520
    #20B2AA
    #8A2BE2
    125
    The Eagle & the Beetle
    #1F3B4D
    #F2A71B
    #ADC2A9
    #7B3F00
    #D9D4A3
    #A29193
    #68829E
    #F1F0E1
    126
    The Ass & the Load of Salt
    #2E8B57
    #FFD700
    #6B8E23
    #98FB98
    #8B4513
    #ADD8E6
    #F4A460
    #228B22
    127
    The Lion & the Ass
    #4A752C
    #D4A017
    #6A8C3A
    #B8C4BB
    #826F57
    #F0E6C8
    #A5A392
    #C0A582
    128
    The Lion & the Mouse
    #0B6623
    #F5DEB3
    #FFD700
    #8B4513
    #FFA500
    #B22222
    #98FB98
    #4682B4
    129
    The Cock & the Jewel
    #2A623D
    #D4A017
    #8DB580
    #EFE1BA
    #F1C40F
    #E67E22
    #2980B9
    #F39C12
    130
    The Two Goats
    #1C3D99
    #FFC857
    #FF5733
    #89CFF0
    #4CAF50
    #FFD700
    #9370DB
    #FA8072
    131
    Jupiter & the Monkey
    #4A7C59
    #FFD700
    #8FBC8F
    #556B2F
    #8A2BE2
    #FF6347
    #4682B4
    #D2691E
    132
    The Dog & the Oyster
    #2F4F4F
    #FF8C00
    #B0C4DE
    #8FBC8F
    #F5DEB3
    #4682B4
    #CD5C5C
    #EEE8AA
    133
    The Wolf & the Kid
    #D9480F
    #4F759B
    #8AA399
    #6C704F
    #FFC857
    #A5AA5C
    #CFD186
    #7D4E57
    134
    The Miser
    #2E8B57
    #8B0000
    #A0522D
    #556B2F
    #8FBC8F
    #DEB887
    #4682B4
    #708090
    135
    The Boy & the Filberts
    #2E8B57
    #FFD700
    #3CB371
    #EEE8AA
    #8FBC8F
    #FAFAD2
    #DAA520
    #F0E68C
    136
    The Tortoise & the Ducks
    #2E8B57
    #FFD700
    #4682B4
    #6A5ACD
    #8B4513
    #FF6347
    #20B2AA
    #DAA520
    137
    The Ass, the Fox & the Lion
    #2D5016
    #B85941
    #6A8B3A
    #B3A357
    #E3CDA4
    #715C36
    #8C6031
    #A1B07E
    138
    The Bees, Wasps & the Hornet
    #0C3D1B
    #FFDE34
    #A1C349
    #F9C74F
    #2C6E49
    #D4A5A5
    #FAEDCD
    #6A994E
    139
    The Young Crab & His Mother
    #2D8C3B
    #F7A600
    #92D4E8
    #B4EBC1
    #E3F9A6
    #F5C253
    #FFF3D8
    #B8DDEA
    140
    The Wolf & the Lion
    #1A472A
    #A89B5D
    #567D46
    #7F6C3B
    #422C1B
    #86B88E
    #A64439
    #D9C77A
    141
    The Fighting Cocks & the Eagle
    #4B5320
    #FFD700
    #8B4513
    #6B8E23
    #87CEEB
    #DEB887
    #D2691E
    #708090
    142
    The Ant & the Dove
    #2D572C
    #FFC107
    #4CAF50
    #FFA726
    #8BC34A
    #F57C00
    #AED581
    #FF9800
    143
    The Mouse & the Weasel
    #2A6041
    #C47F17
    #7BC96F
    #F2A541
    #D9C5B2
    #8A5E3C
    #F0EAD6
    #54494B
    144
    US Russia News Article
    #00274D
    #D9534F
    #AAB7B8
    #5D6D7E
    #F7F9F9
    #A93226
    #2874A6
    #1C2833

    I initially considered creating a static webpage for each fable with its corresponding palette. However, I decided to be more ambitious and transform this concept into a simple web product.

    Step 4: To Production

    The vision is simple. A text box where you can paste any text, and generate a sympathetic colour palette based on the nature of that text.

    Given I’ve already got some prompts working with the OpenAI API this is largely a UI/UX challenge from here on in. It took a couple of hours to get things to an acceptable standard, most of that time is the Replit agent crunching through my requests. Here’s a concise summary of that back and forth…

    And just like that, we’re up and running. Why not try HEXpert? Or watch the demo if it’s not running today.

    ToDo

    If you share some of my personality traits, you won't feel a sense of closure once you reach this point but instead a sense of dread about the number of loose ends you've created. I'll leave this to-do list here for my sanity:

    • Iterate on the thematic analysis prompt.
    • Iterate on the palette generation prompt.
    • Explore training a neural net instead.
    import requests
    from bs4 import BeautifulSoup
    import re
    import os
    import shutil
    from google.colab import drive
    
    # Mount Google Drive
    drive.mount('/content/drive')
    
    # --- Fetch the index page ---
    index_url = "https://read.gov/aesop/001.html"
    response = requests.get(index_url)
    index_html = response.text
    
    # --- Extract fable titles and urls ---
    soup = BeautifulSoup(index_html, 'html.parser')
    fable_list = soup.find_all('a')
    
    fables_data = []
    for link in fable_list:
        title = link.text.strip()
        url = link.get('href')
        if url and '.html' in url: # Include all links that contain '.html'
            fables_data.append({'title': title, 'url': url})
    
    print(f"Found {len(fables_data)} fables.")
    
    # --- Construct full urls ---
    base_url = "https://read.gov/aesop/"
    for fable in fables_data:
        fable['full_url'] = base_url + fable['url']
    
    # --- Fetch individual fable pages ---
    fables_with_html = []
    for fable in fables_data:
        fable_url = fable['full_url']
        print(f"Fetching HTML for: {fable_url}")
        try:
            response = requests.get(fable_url)
            response.raise_for_status() # Raise an exception for bad status codes
            fable_html = response.text
            fables_with_html.append({'title': fable['title'], 'url': fable['url'], 'full_url': fable['full_url'], 'html': fable_html})
        except requests.exceptions.RequestException as e:
            print(f"Error fetching {fable_url}: {e}")
    
    print(f"Successfully fetched HTML for {len(fables_with_html)} fables.")
    
    # --- Extract fable text and morale ---
    for fable in fables_with_html:
        soup = BeautifulSoup(fable['html'], 'html.parser')
    
        # Extract fable text - look for paragraph tags within the body content
        text = []
        # Assuming the main content is within the body and uses <p> tags
        # You might need to adjust this based on the actual HTML structure
        for paragraph in soup.find_all('p'):
            text.append(paragraph.get_text(strip=True))
        fable['text'] = '\n'.join(text)
    
        # Extract morale - look for blockquote tags
        morale = None
        blockquote = soup.find('blockquote')
        if blockquote:
            morale = blockquote.get_text(strip=True)
        fable['morale'] = morale
    
    # --- Format as markdown ---
    for fable in fables_with_html:
        markdown_content = f"# {fable['title']}\n\n"
        markdown_content += fable['text']
    
        if fable['morale']:
            # Assuming the morale might have multiple paragraphs or formatting,
            # we'll just add it as is after a blank line.
            # If specific blockquote formatting is needed, it would require more
            # complex parsing of the morale text.
            markdown_content += f"\n\nMorale: {fable['morale']}"
    
        fable['markdown_content'] = markdown_content
    
    # --- Save to markdown file ---
    output_dir = "fables_markdown"
    os.makedirs(output_dir, exist_ok=True)
    
    for fable in fables_with_html:
        title = fable['title']
        markdown_content = fable['markdown_content']
    
        # Sanitize the title for use as a filename
        # Replace spaces with underscores
        filename = title.replace(" ", "_")
        # Remove characters that are not letters, numbers, underscores, or hyphens
        filename = re.sub(r'[^\w-]', '', filename)
        # Add the markdown extension
        filename = filename + ".md"
    
        # Construct the full file path
        filepath = os.path.join(output_dir, filename)
    
        # Save the markdown content to the file
        try:
            with open(filepath, 'w', encoding='utf-8') as f:
                f.write(markdown_content)
            print(f"Saved: {filepath}")
        except IOError as e:
            print(f"Error saving {filepath}: {e}")
    
    # --- Zip the output directory ---
    zip_filename = "aesop_fables_markdown.zip"
    shutil.make_archive(zip_filename.replace(".zip", ""), 'zip', output_dir)
    print(f"Created zip file: {zip_filename}")
    Analyse the provided text and return a theme analysis in JSON format. 
    Follow these exact specifications:
    
    Output Requirements:
    
    - Return ONLY valid JSON, no additional text or explanations
    - Use exactly this structure with these key names
    - Select values ONLY from the predefined options listed below
    - Include exactly 3 values per array (most relevant first)
    
    JSON Structure:
    {
    "type_of_text": ["value1", "value2", "value3"],
    "mood_of_text": ["value1", "value2", "value3"],
    "setting_environment": ["value1", "value2", "value3"],
    "characters_objects": ["value1", "value2", "value3"],
    "era_timeframe": ["value1", "value2", "value3"],
    "cultural_influences": ["value1", "value2", "value3"],
    "intended_audience": ["value1", "value2", "value3"],
    "narrative_pace_tempo": ["value1", "value2", "value3"],
    "dominant_themes": ["value1", "value2", "value3"]
    }
    
    Selection Rules:
    
    1. Choose the 3 most relevant values for each category
    2. Order values by relevance (most important first)
    3. If fewer than 3 values apply, repeat the most relevant
    4. Values must directly relate to explicit text content, not interpretations
    
    Input Text 
    {replace with markdown file text}
    {'type_of_text': ['fable', 'narrative', 'story'],
     'mood_of_text': ['didactic', 'reflective', 'somber'],
     'setting_environment': ['natural', 'wetland', 'forest'],
     'characters_objects': ['raven', 'swan', 'feathers'],
     'era_timeframe': ['timeless', 'mythical', 'ancient'],
     'cultural_influences': ['folklore', 'moralistic', 'traditional'],
     'intended_audience': ['children', 'general', 'educational'],
     'narrative_pace_tempo': ['steady', 'moderate', 'calm'],
     'dominant_themes': ['envy', 'identity', 'nature']}
    Generate a HEX color palette in JSON format based on the provided theme analysis. Follow these exact specifications:
    
    **Output Requirements:**
    - Return ONLY valid JSON, no additional text or explanations
    - Use exactly this structure with these key names
    - Include exactly 1 primary, 1 secondary, 2 tertiary, and 4 quaternary colors
    - All HEX codes must be uppercase 6-character format (e.g., "#2D5016")
    
    **JSON Structure:**
    {
      "primary": "#HEXCODE",
      "secondary": "#HEXCODE", 
      "tertiary": ["#HEXCODE", "#HEXCODE"],
      "quaternary": ["#HEXCODE", "#HEXCODE", "#HEXCODE", "#HEXCODE"]
    }
    
    **Color Selection Criteria:**
    1. Primary: Dominant theme/setting color (highest contrast)
    2. Secondary: Key symbolic element (complementary to primary)
    3. Tertiary: Supporting thematic elements (harmonious with primary/secondary)
    4. Quaternary: Accent colors for objects/atmosphere (complete the palette)
    
    **Requirements:**
    - Ensure sufficient contrast between primary and secondary (minimum 3:1 ratio)
    - Colors must harmoniously work together (analogous, complementary, or triadic schemes)
    - Reflect the dominant themes and setting from the input JSON
    - Prioritize the most frequently mentioned elements in character_objects and setting_environment
    
    **Input Theme Analysis:**
    {INPUT_JSON_HERE}
    - Create a minimal UI app where pasted text is analysed for themes by OpenAI.
    - Allow custom-defined prompts for thematic analysis in strict JSON.
    - Use thematic JSON response to request a HEX colour palette from OpenAI.
    - Display generated colour palette visually in proportional rectangles.
    - Adjust UI to prioritise colour palette display above textual analysis.
    - Add copy-on-hover functionality to colour labels.
    - Add an expandable "analysis details" section with a terminal-style typing animation.
    - Refine animation speed, colours, and spacing for readability.
    - Insert subtle footer credit link
    - Fix mobile responsiveness issues, especially clipped buttons.
    - Add a thin, colourful SVG logo under the main HEXpert title.
    - Adjust spacing to improve visual cohesion between logo and title.
    - Resolve HTTPS/SSL issues after adding custom domain
    - Add colour ramps