Skip to content

Instantly share code, notes, and snippets.

@swaathi
Last active December 25, 2016 11:18
Show Gist options
  • Save swaathi/f3c37d3cbade41282015d5f95800b492 to your computer and use it in GitHub Desktop.
Save swaathi/f3c37d3cbade41282015d5f95800b492 to your computer and use it in GitHub Desktop.
ML Training Data
require 'fileutils'
require 'securerandom'
directory = File.expand_path File.dirname(__FILE__)
textfiles = "#{directory}/textfiles"
FileUtils::mkdir_p textfiles
Dir["#{directory}/*.scss"].each do |file|
file_content = File.new(file, "r").read
rgbas = file_content.scan(/rgba\(([0-9, ]*)/)
textfile_name = "#{textfiles}/#{SecureRandom.hex(10)}.txt"
textfile = File.new(textfile_name, "w")
puts "Filename: #{textfile_name}"
for rgba in rgbas
puts rgba
textfile.puts rgba
end
textfile.close
puts "---"
end

The Plan

I'm trying to create an ML tool that will create color palettes that are pleasing to the eye. This is going to be a supervised ML engine, meaning I need data! Lots of it.

What do you get?

Your name on an open source ML project! 🎉 I'll add you to the list of contributors once the app is ready! :)

Responsibility Sharing

Since there's a range of people who want to help, it makes sense to divide responsibilities according to skills.

[C] - can code/willing to code

[M] - mangement work that does not need code

Gathering test data

Downloading test files [M]

Creating a structured dataset [C]

  • Convert the SCSS file into a cleaned text file
  • The text file should contain the rgb values each on a new line

Use the above ruby script to convert SCSS files to required text files

ruby parser.rb

IMPORTANT

Place the Ruby file in the same directory as your SCSS files

Make sure only valid SCSS files are present

Examples

  1. Palette file
/* Coolors Exported Palette - coolors.co/606c38-283618-fefae0-dda15e-bc6c25 */

/* HSL */
$color1: hsla(74%, 32%, 32%, 1);
$color2: hsla(88%, 38%, 15%, 1);
$color3: hsla(52%, 94%, 94%, 1);
$color4: hsla(32%, 65%, 62%, 1);
$color5: hsla(28%, 67%, 44%, 1);

/* RGB */
$color1: rgba(96, 108, 56, 1);
$color2: rgba(40, 54, 24, 1);
$color3: rgba(254, 250, 224, 1);
$color4: rgba(221, 161, 94, 1);
$color5: rgba(188, 108, 37, 1);
  1. Text File
96, 108, 56, 1
40, 54, 24, 1
254, 250, 224, 1
221, 161, 94, 1
188, 108, 37, 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment