From c0c00b1e17cec616334e205e38b1219dfba3acaa Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:33:34 -0600 Subject: [PATCH 01/18] adds homework setup in readme --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 6fdced5..bf4a3e4 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,34 @@ The way it should work is: - [Word Count](http://omnicalc-target.herokuapp.com/word_count/new) - [Descriptive Statistics](http://omnicalc-target.herokuapp.com/descriptive_statistics/new) +## Part IV: Homework Setup + +For our homework, we're going to be exploring a machine learning API marketplace called [Algorithmia](https://algorithmia.com/). + +First, visit [Algorithmia](https://algorithmia.com/) and sign up for an account. You'll be able to find your API keys by visiting https://algorithmia.com/users/[your username] or by clicking on the profile icon at the top right and clicking the 'My API Keys' link. You'll need this key to complete the homework exercises below. + +We'll also need to make sure your API key stays hidden, in case your project ever gets pushed to Github or another public repository. Unsavory types like to scrape Github for sensitive information like API keys and run up huge bills for compromised users. In this specific case, you didn't have to tie your API key to a credit card, but protecting your API keys is generally good practice. + +We've already got the infrastructure for this in place. Our class project apps come bundled with a gem called `dotenv` which lets us store sensitive information just in our local development environment and hide that info from Git so it doesn't get pushed anywhere with our code. The info is stored in a file called `.env` that exists in the root folder of your application. If you open it up, you'll see the following code. + +``` +TEST_ENV_VAR="It works!" +``` + +This is just a key-value pair that we can access anywhere in our Rails environment using the ENV hash. For example, to access this 'sensitive' info, we can open up Rails console and type in: + +``` +ENV['TEST_ENV_VAR'] +``` + +and we should see output of + +``` +"It works!" +``` + +You can use this pattern throughout your Rails app to pull up any sensitive info. Practice by using the `.env` file to store your Algorithmia API key. + ## Stretch Goals - [Bootstrap it](http://getbootstrap.com/components/#panels) to make it look like [the real Omnicalc](http://omnicalc-target.herokuapp.com/). We've already connected `bootstrap.css` and [Font Awesome](http://fontawesome.io/icons/) for you, so you can just start using them. From 5c31412e76377cddafe0688b86fe16fe11b65fcd Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:43:46 -0600 Subject: [PATCH 02/18] adds algorithmia gem --- Gemfile | 1 + Gemfile.lock | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Gemfile b/Gemfile index 6680c06..3cd9f5f 100644 --- a/Gemfile +++ b/Gemfile @@ -73,3 +73,4 @@ end gem 'jquery-rails' gem "turbolinks" +gem 'algorithmia' diff --git a/Gemfile.lock b/Gemfile.lock index 3d9eb18..c9f56dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,6 +64,9 @@ GEM tzinfo (~> 1.1) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) + algorithmia (1.0.1) + httparty (~> 0.13) + json (~> 1.8) annotate (2.7.2) activerecord (>= 3.2, < 6.0) rake (>= 10.4, < 13.0) @@ -114,6 +117,8 @@ GEM globalid (0.4.0) activesupport (>= 4.2.0) hashdiff (0.3.4) + httparty (0.15.6) + multi_xml (>= 0.5.2) i18n (0.8.6) jbuilder (2.7.0) activesupport (>= 4.2.0) @@ -122,6 +127,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + json (1.8.6) launchy (2.4.3) addressable (~> 2.3) letter_opener (1.4.1) @@ -145,6 +151,7 @@ GEM mini_portile2 (2.3.0) minitest (5.10.2) multi_json (1.12.1) + multi_xml (0.6.0) nio4r (2.1.0) nokogiri (1.8.2) mini_portile2 (~> 2.3.0) @@ -267,6 +274,7 @@ PLATFORMS ruby DEPENDENCIES + algorithmia annotate awesome_print better_errors From 9acbd3ef02902c46791ac6b9d09d096ab232dc1b Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:52:28 -0600 Subject: [PATCH 03/18] stops ignoring .env files temporarily --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 90309d2..7b3487b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,3 @@ .byebug_history # Ignore dotenv files -/.env* From 162ec78d1540ccea403975587f8fb6715175954f Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:53:21 -0600 Subject: [PATCH 04/18] adds .env file --- .env | 1 + 1 file changed, 1 insertion(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..3ade5f4 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +ALGORITHMIA_KEY="It works!" From 3770e5a28ffbde82035fa9e48edfe334b7feeb03 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:53:48 -0600 Subject: [PATCH 05/18] reignores .env files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7b3487b..90309d2 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ .byebug_history # Ignore dotenv files +/.env* From f88e11b734d6e3207c29bd7edfa5a106ac5f3b04 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:55:05 -0600 Subject: [PATCH 06/18] rm .env --- .env | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 3ade5f4..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -ALGORITHMIA_KEY="It works!" From 7ed175c2bd0fe701aea4a0f869f6bac1739a59af Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:55:35 -0600 Subject: [PATCH 07/18] Don't ignore .env --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index 90309d2..dcc5b36 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,3 @@ /yarn-error.log .byebug_history - -# Ignore dotenv files -/.env* From ea46d60ba0cfa3c0f45223f858d5f1c9c3fe143a Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:56:45 -0600 Subject: [PATCH 08/18] Add .env --- .env | 1 + 1 file changed, 1 insertion(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..16e4deb --- /dev/null +++ b/.env @@ -0,0 +1 @@ +ALGORITHMIA_KEY=replace_me_with_real_key From a2afed241a8049ea90e055d7fa45c6b31dd69ae7 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 12:57:04 -0600 Subject: [PATCH 09/18] Ignore .env --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index dcc5b36..90309d2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ /yarn-error.log .byebug_history + +# Ignore dotenv files +/.env* From cf45da87ff0a4cb4ea125633174c8569f0717c91 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 13:02:31 -0600 Subject: [PATCH 10/18] removes .env --- .env | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 16e4deb..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -ALGORITHMIA_KEY=replace_me_with_real_key From dec4064e36bb0482672415ff9bb1bc975e95479b Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 13:13:49 -0600 Subject: [PATCH 11/18] updates readme --- README.md | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bf4a3e4..8c31310 100644 --- a/README.md +++ b/README.md @@ -124,29 +124,45 @@ The way it should work is: For our homework, we're going to be exploring a machine learning API marketplace called [Algorithmia](https://algorithmia.com/). -First, visit [Algorithmia](https://algorithmia.com/) and sign up for an account. You'll be able to find your API keys by visiting https://algorithmia.com/users/[your username] or by clicking on the profile icon at the top right and clicking the 'My API Keys' link. You'll need this key to complete the homework exercises below. +First, visit [Algorithmia](https://algorithmia.com/) and sign up for an account. You'll be able to find your API keys by visiting 'https://algorithmia.com/users/[your username]' or by clicking on the profile icon at the top right and clicking the 'My API Keys' link. You'll need this key to complete the homework exercises below. We'll also need to make sure your API key stays hidden, in case your project ever gets pushed to Github or another public repository. Unsavory types like to scrape Github for sensitive information like API keys and run up huge bills for compromised users. In this specific case, you didn't have to tie your API key to a credit card, but protecting your API keys is generally good practice. -We've already got the infrastructure for this in place. Our class project apps come bundled with a gem called `dotenv` which lets us store sensitive information just in our local development environment and hide that info from Git so it doesn't get pushed anywhere with our code. The info is stored in a file called `.env` that exists in the root folder of your application. If you open it up, you'll see the following code. +We've already got the infrastructure for this in place. Our class project apps come bundled with a gem called `dotenv` which lets us store sensitive information just in our local development environment and hide that info from Git so it doesn't get pushed anywhere with our code. The info is stored in a file called `.env` that exists in the root folder of your application. Create a new file at the root directory of your application and call it `.env`. In the file place, the following code: ``` -TEST_ENV_VAR="It works!" +ALGORITHMIA_KEY="replace_me_with_your_key" ``` This is just a key-value pair that we can access anywhere in our Rails environment using the ENV hash. For example, to access this 'sensitive' info, we can open up Rails console and type in: ``` -ENV['TEST_ENV_VAR'] +ENV['ALGORITHMIA_KEY'] ``` and we should see output of ``` -"It works!" +"replace_me_with_your_key" ``` -You can use this pattern throughout your Rails app to pull up any sensitive info. Practice by using the `.env` file to store your Algorithmia API key. +You can use this pattern throughout your Rails app to pull up any sensitive info. Practice by using the `.env` file to store your actual Algorithmia API key. + + +## Part V: Homework 1: Colorize API + +The first API we'll use is a service that colorizes black and white images. + +Here's how it should work: + +- If I visit `/colorize`, I should see a form that has a single input which lets me enter the URL of a black and white image. You can use [https://cdn.vox-cdn.com/uploads/chorus_asset/file/4863353/grantpark-1.0.jpg](https://cdn.vox-cdn.com/uploads/chorus_asset/file/4863353/grantpark-1.0.jpg) as an example. The smaller the image, the better. Try not to go beyond 800x800px. +- The input should have a label of `Image URL` and the button you click to submit the form should be called `Colorize`. +- When the form is submitted, I should see a colorized version of the original black and white picture + +The API needs a bit of time to do it's work, so expect it to take about 30 seconds or so for the request to complete. + +Visit the [Image Colorization API](https://algorithmia.com/algorithms/deeplearning/ColorfulImageColorization), and follow the instructions at the bottom of the page to integrate the API in your controller. ** You do not need to include the `require 'algorithmia'` statement from the instructions** + ## Stretch Goals From c7c57f797652826a19a9dec8236c73d3cdd545cd Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 13:18:08 -0600 Subject: [PATCH 12/18] adds homework problem 1 spec --- spec/features/algorithmia_spec.rb | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/features/algorithmia_spec.rb diff --git a/spec/features/algorithmia_spec.rb b/spec/features/algorithmia_spec.rb new file mode 100644 index 0000000..47bbc8a --- /dev/null +++ b/spec/features/algorithmia_spec.rb @@ -0,0 +1,46 @@ +require "rails_helper" + +describe "/colorize" do + it "has a label named 'Image URL'", points: 1, hint: h("copy_must_match label_for_input") do + visit "/colorize" + + expect(page).to have_css("label", text: 'Image URL') + end +end + +describe "/colorize" do + it "has an input", points: 1 do + visit "/colorize" + + expect(page).to have_css("input", count: 1) + end +end + +describe "/colorize" do + it "has a button named 'Colorize'", points: 1, hint: h("copy_must_match label_for_input") do + visit "/colorize" + + expect(page).to have_css("button", text: 'Colorize') + end +end + +describe "/colorize" do + it "correctly displays the image", points: 3 do + #==================== Begin setup ===========================# + # create fake Algorithmia objects to speed up tests + Algorithmia = class_double("Algorithmia") + client_obj = double(:client) + algo_obj = double(:algo) + pipe_obj = double(:pipe) + allow(Algorithmia).to receive(:client).and_return(client_obj) + allow(client_obj).to receive(:algo).and_return(algo_obj) + allow(algo_obj).to receive(:pipe).and_return(pipe_obj) + allow(pipe_obj).to receive(:result).and_return({'output' => 'data://.algo/deeplearning/ColorfulImageColorization/temp/rand-M.png'}) + #==================== End setup =============================# + + visit "/colorize" + fill_in "Image URL", with: 'image.png' + click_button "Colorize" + expect(page).to have_css("img[src*='rand-M.png']") + end +end From 5aaddf8b3869feb19e23a7ba34d0546427e0e35f Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 14:35:56 -0600 Subject: [PATCH 13/18] updates readme --- README.md | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8c31310..9c1b1f5 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,9 @@ The way it should work is: - [Word Count](http://omnicalc-target.herokuapp.com/word_count/new) - [Descriptive Statistics](http://omnicalc-target.herokuapp.com/descriptive_statistics/new) -## Part IV: Homework Setup +## Part IV: Homework + +### Setup For our homework, we're going to be exploring a machine learning API marketplace called [Algorithmia](https://algorithmia.com/). @@ -148,10 +150,35 @@ and we should see output of You can use this pattern throughout your Rails app to pull up any sensitive info. Practice by using the `.env` file to store your actual Algorithmia API key. +### Problem 1 - Auto-tagging + +The first service we'll use auto-tags blocks of text. + +Here's how it should work: + +- If I visit `/colorize`, I should see a form that has a single textarea element which lets me enter text for tagging. If you'd like an example, you can use this excerpt from the Paul Graham essay, [Do Things That Don't Scale](http://www.paulgraham.com/ds.html): + +``` +One of the most common types of advice we give at Y Combinator is to do things that don't scale. A lot of would-be founders believe that startups either take off or don't. You build something, make it available, and if you've made a better mousetrap, people beat a path to your door as promised. Or they don't, in which case the market must not exist. +``` +- The textarea should have a label of `Text` and the button you click to submit the form should be called `Generate Tags`. +- When the form is submitted, I should see an unordered list of tags corresponding to the submitted text. If you used the example text, you should see the following tags: +``` +beat +case +door +exist +market +path +people +promise +``` + +Visit the [AutoTag page](https://algorithmia.com/algorithms/nlp/AutoTag), and follow the instructions at the bottom of the page to integrate the API in your controller. ** You do not need to include the `require 'algorithmia'` statement from the instructions** -## Part V: Homework 1: Colorize API +### Problem 2 - Colorize Images -The first API we'll use is a service that colorizes black and white images. +The next service we'll use colorizes black and white images. Here's how it should work: @@ -161,7 +188,10 @@ Here's how it should work: The API needs a bit of time to do it's work, so expect it to take about 30 seconds or so for the request to complete. -Visit the [Image Colorization API](https://algorithmia.com/algorithms/deeplearning/ColorfulImageColorization), and follow the instructions at the bottom of the page to integrate the API in your controller. ** You do not need to include the `require 'algorithmia'` statement from the instructions** +Visit the [Image Colorization page](https://algorithmia.com/algorithms/deeplearning/ColorfulImageColorization), and follow the instructions at the bottom of the page to integrate the API in your controller. + + + ## Stretch Goals From 240710bd72c33d9e79d3382d739d3e1b715c665c Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 14:36:27 -0600 Subject: [PATCH 14/18] adds hw problem 2 --- spec/features/algorithmia_spec.rb | 61 ++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/spec/features/algorithmia_spec.rb b/spec/features/algorithmia_spec.rb index 47bbc8a..2d28c62 100644 --- a/spec/features/algorithmia_spec.rb +++ b/spec/features/algorithmia_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" describe "/colorize" do - it "has a label named 'Image URL'", points: 1, hint: h("copy_must_match label_for_input") do + it "has a label named 'Image URL'", points: 1 do visit "/colorize" expect(page).to have_css("label", text: 'Image URL') @@ -17,7 +17,7 @@ end describe "/colorize" do - it "has a button named 'Colorize'", points: 1, hint: h("copy_must_match label_for_input") do + it "has a button named 'Colorize'", points: 1 do visit "/colorize" expect(page).to have_css("button", text: 'Colorize') @@ -25,7 +25,7 @@ end describe "/colorize" do - it "correctly displays the image", points: 3 do + it "displays the colorized image", points: 5 do #==================== Begin setup ===========================# # create fake Algorithmia objects to speed up tests Algorithmia = class_double("Algorithmia") @@ -35,12 +35,61 @@ allow(Algorithmia).to receive(:client).and_return(client_obj) allow(client_obj).to receive(:algo).and_return(algo_obj) allow(algo_obj).to receive(:pipe).and_return(pipe_obj) - allow(pipe_obj).to receive(:result).and_return({'output' => 'data://.algo/deeplearning/ColorfulImageColorization/temp/rand-M.png'}) + allow(pipe_obj).to receive(:result).and_return({'output' => 'data://.algo/deeplearning/ColorfulImageColorization/temp/grantpark-1.0.png'}) #==================== End setup =============================# visit "/colorize" - fill_in "Image URL", with: 'image.png' + fill_in "Image URL", with: "https://cdn.vox-cdn.com/uploads/chorus_asset/file/4863353/grantpark-1.0.jpg" click_button "Colorize" - expect(page).to have_css("img[src*='rand-M.png']") + expect(page).to have_css("img[src*='.algo/deeplearning/ColorfulImageColorization/temp/grantpark-1.0.png']") + end +end + +describe "/autotag" do + it "has a label named 'Text'", points: 1, hint: h("copy_must_match label_for_input") do + visit "/autotag" + + expect(page).to have_css("label", text: 'Text') + end +end + +describe "/autotag" do + it "has a textarea", points: 1, hint: h("copy_must_match label_for_input") do + visit "/autotag" + + expect(page).to have_css("textarea", count: 1) + end +end + +describe "/autotag" do + it "has a button named 'Generate Tags'", points: 1, hint: h("copy_must_match label_for_input") do + visit "/autotag" + + expect(page).to have_css("button", text: 'Generate Tags') + end +end + +describe "/autotag" do + it "correctly generates tags", points: 5 do + #==================== Begin setup ===========================# + # create fake Algorithmia objects to speed up tests + Algorithmia = class_double("Algorithmia2") + client_obj = double(:client) + algo_obj = double(:algo) + pipe_obj = double(:pipe) + allow(Algorithmia).to receive(:client).and_return(client_obj) + allow(client_obj).to receive(:algo).and_return(algo_obj) + allow(algo_obj).to receive(:pipe).and_return(pipe_obj) + allow(pipe_obj).to receive(:result).and_return([ + "beat", + "case" + ]) + #==================== End setup =============================# + + visit "/autotag" + fill_in "Text", with: "One of the most common types of advice we give at Y Combinator is to do things that don't scale. A lot of would-be founders believe that startups either take off or don't. You build something, make it available, and if you've made a better mousetrap, people beat a path to your door as promised. Or they don't, in which case the market must not exist." + click_button "Generate Tags" + expect(page).to have_css("li", text: "beat") + expect(page).to have_css("li", text: "case") end end From 3fc51624cf0320fec1a03eb80e1624c9c2f5037d Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 23:49:27 -0600 Subject: [PATCH 15/18] updates readme --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9c1b1f5..b824acd 100644 --- a/README.md +++ b/README.md @@ -150,13 +150,13 @@ and we should see output of You can use this pattern throughout your Rails app to pull up any sensitive info. Practice by using the `.env` file to store your actual Algorithmia API key. -### Problem 1 - Auto-tagging +### Problem 1 - Auto-tag Text The first service we'll use auto-tags blocks of text. Here's how it should work: -- If I visit `/colorize`, I should see a form that has a single textarea element which lets me enter text for tagging. If you'd like an example, you can use this excerpt from the Paul Graham essay, [Do Things That Don't Scale](http://www.paulgraham.com/ds.html): +- If I visit `/text-tag`, I should see a form that has a single textarea element which lets me enter text for tagging. If you'd like an example, you can use this excerpt from the Paul Graham essay, [Do Things That Don't Scale](http://www.paulgraham.com/ds.html): ``` One of the most common types of advice we give at Y Combinator is to do things that don't scale. A lot of would-be founders believe that startups either take off or don't. You build something, make it available, and if you've made a better mousetrap, people beat a path to your door as promised. Or they don't, in which case the market must not exist. @@ -190,8 +190,19 @@ The API needs a bit of time to do it's work, so expect it to take about 30 secon Visit the [Image Colorization page](https://algorithmia.com/algorithms/deeplearning/ColorfulImageColorization), and follow the instructions at the bottom of the page to integrate the API in your controller. +### Problem 3 - Auto-tag Images +The next service we'll use tags images. +Here's how it should work: + +- If I visit `/image-tag`, I should see a form that has a single input which lets me enter the URL of an image. You can use [http://www.pjproductions.co.uk/blog_images/Chicago-Booth-Group-photo-Pete-Jones.jpg](http://www.pjproductions.co.uk/blog_images/Chicago-Booth-Group-photo-Pete-Jones.jpg) as an example. +- The input should have a label of `Image URL` and the button you click to submit the form should be called `Colorize`. +- When the form is submitted, I should see a set of tags inside an unordered list. + +The API needs a bit of time to do it's work, so expect it to take about 30 seconds or so for the request to complete. + +Visit the [Illustration Tagger page](https://algorithmia.com/algorithms/deeplearning/IllustrationTagger), and follow the instructions at the bottom of the page to integrate the API in your controller. ## Stretch Goals From 4612e33546512683e4bc5d7f048b7a462c91a806 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Tue, 30 Jan 2018 23:49:45 -0600 Subject: [PATCH 16/18] adds problem 3 specs --- spec/features/algorithmia_spec.rb | 139 ++++++++++++++++++++---------- 1 file changed, 95 insertions(+), 44 deletions(-) diff --git a/spec/features/algorithmia_spec.rb b/spec/features/algorithmia_spec.rb index 2d28c62..74d74cc 100644 --- a/spec/features/algorithmia_spec.rb +++ b/spec/features/algorithmia_spec.rb @@ -1,5 +1,42 @@ require "rails_helper" +describe "/text-tag" do + it "has a label named 'Text'", points: 1, hint: h("copy_must_match label_for_input") do + visit "/text-tag" + + expect(page).to have_css("label", text: 'Text') + end +end + +describe "/text-tag" do + it "has a textarea", points: 1, hint: h("copy_must_match label_for_input") do + visit "/text-tag" + + expect(page).to have_css("textarea", count: 1) + end +end + +describe "/text-tag" do + it "has a button named 'Generate Tags'", points: 1, hint: h("copy_must_match label_for_input") do + visit "/text-tag" + + expect(page).to have_css("button", text: 'Generate Tags') + end +end + +describe "/text-tag" do + it "correctly generates tags", points: 5 do + Algorithmia = class_double("Algorithmia") + text_tag_setup + + visit "/text-tag" + fill_in "Text", with: "One of the most common types of advice we give at Y Combinator is to do things that don't scale. A lot of would-be founders believe that startups either take off or don't. You build something, make it available, and if you've made a better mousetrap, people beat a path to your door as promised. Or they don't, in which case the market must not exist." + click_button "Generate Tags" + expect(page).to have_css("li", text: "beat") + expect(page).to have_css("li", text: "case") + end +end + describe "/colorize" do it "has a label named 'Image URL'", points: 1 do visit "/colorize" @@ -26,17 +63,8 @@ describe "/colorize" do it "displays the colorized image", points: 5 do - #==================== Begin setup ===========================# - # create fake Algorithmia objects to speed up tests - Algorithmia = class_double("Algorithmia") - client_obj = double(:client) - algo_obj = double(:algo) - pipe_obj = double(:pipe) - allow(Algorithmia).to receive(:client).and_return(client_obj) - allow(client_obj).to receive(:algo).and_return(algo_obj) - allow(algo_obj).to receive(:pipe).and_return(pipe_obj) - allow(pipe_obj).to receive(:result).and_return({'output' => 'data://.algo/deeplearning/ColorfulImageColorization/temp/grantpark-1.0.png'}) - #==================== End setup =============================# + Algorithmia = class_double("Algorithmia2") + colorize_setup visit "/colorize" fill_in "Image URL", with: "https://cdn.vox-cdn.com/uploads/chorus_asset/file/4863353/grantpark-1.0.jpg" @@ -45,51 +73,74 @@ end end -describe "/autotag" do - it "has a label named 'Text'", points: 1, hint: h("copy_must_match label_for_input") do - visit "/autotag" +describe "/image-tag" do + it "has a label named 'Image URL'", points: 1 do + visit "/image-tag" - expect(page).to have_css("label", text: 'Text') + expect(page).to have_css("label", text: 'Image URL') end end -describe "/autotag" do - it "has a textarea", points: 1, hint: h("copy_must_match label_for_input") do - visit "/autotag" +describe "/image-tag" do + it "has an input", points: 1 do + visit "/image-tag" - expect(page).to have_css("textarea", count: 1) + expect(page).to have_css("input", count: 1) end end -describe "/autotag" do - it "has a button named 'Generate Tags'", points: 1, hint: h("copy_must_match label_for_input") do - visit "/autotag" +describe "/image-tag" do + it "has a button named 'Process'", points: 1 do + visit "/image-tag" - expect(page).to have_css("button", text: 'Generate Tags') + expect(page).to have_css("button", text: 'Process') end end -describe "/autotag" do +describe "/image-tag" do it "correctly generates tags", points: 5 do - #==================== Begin setup ===========================# - # create fake Algorithmia objects to speed up tests - Algorithmia = class_double("Algorithmia2") - client_obj = double(:client) - algo_obj = double(:algo) - pipe_obj = double(:pipe) - allow(Algorithmia).to receive(:client).and_return(client_obj) - allow(client_obj).to receive(:algo).and_return(algo_obj) - allow(algo_obj).to receive(:pipe).and_return(pipe_obj) - allow(pipe_obj).to receive(:result).and_return([ - "beat", - "case" - ]) - #==================== End setup =============================# - - visit "/autotag" - fill_in "Text", with: "One of the most common types of advice we give at Y Combinator is to do things that don't scale. A lot of would-be founders believe that startups either take off or don't. You build something, make it available, and if you've made a better mousetrap, people beat a path to your door as promised. Or they don't, in which case the market must not exist." - click_button "Generate Tags" - expect(page).to have_css("li", text: "beat") - expect(page).to have_css("li", text: "case") + Algorithmia = class_double("Algorithmia3") + image_tag_setup + + visit "/image-tag" + fill_in "Image URL", with: "http://www.pjproductions.co.uk/blog_images/Chicago-Booth-Group-photo-Pete-Jones.jpg" + click_button "Process" + + expect(page).to have_css("li", text: "formal") + expect(page).to have_css("li", text: "everyone") + expect(page).to have_css("li", text: "suit") end end + +def text_tag_setup + client_obj = double(:client) + algo_obj = double(:algo) + pipe_obj = double(:pipe) + allow(Algorithmia).to receive(:client).and_return(client_obj) + allow(client_obj).to receive(:algo).and_return(algo_obj) + allow(algo_obj).to receive(:pipe).and_return(pipe_obj) + allow(pipe_obj).to receive(:result).and_return([ + "beat", + "case" + ]) +end + +def colorize_setup + client_obj = double(:client) + algo_obj = double(:algo) + pipe_obj = double(:pipe) + allow(Algorithmia).to receive(:client).and_return(client_obj) + allow(client_obj).to receive(:algo).and_return(algo_obj) + allow(algo_obj).to receive(:pipe).and_return(pipe_obj) + allow(pipe_obj).to receive(:result).and_return({'output' => 'data://.algo/deeplearning/ColorfulImageColorization/temp/grantpark-1.0.png'}) +end + +def image_tag_setup + client_obj = double(:client) + algo_obj = double(:algo) + pipe_obj = double(:pipe) + allow(Algorithmia).to receive(:client).and_return(client_obj) + allow(client_obj).to receive(:algo).and_return(algo_obj) + allow(algo_obj).to receive(:pipe).and_return(pipe_obj) + allow(pipe_obj).to receive(:result).and_return({'general' => [{'formal': 0.7}, {'everyone': 0.8}, {'suit': 0.6}]}) +end From 31eae35c28f50e18d2473c593c7e3e798465c9d8 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Wed, 31 Jan 2018 09:13:18 -0600 Subject: [PATCH 17/18] adds solutions --- README.md | 5 -- app/controllers/algorithmia_controller.rb | 45 +++++++++++++ app/views/algorithmia/colorize_form.html.erb | 18 ++++++ app/views/algorithmia/image_tag_form.html.erb | 18 ++++++ .../algorithmia/process_colorize.html.erb | 7 +++ .../algorithmia/process_image_tag.html.erb | 11 ++++ .../algorithmia/process_text_tag.html.erb | 11 ++++ app/views/algorithmia/text_tag_form.html.erb | 18 ++++++ app/views/layouts/application.html.erb | 4 +- config/routes.rb | 8 +++ examples.txt | 63 +++++++++++++++++++ 11 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 app/controllers/algorithmia_controller.rb create mode 100644 app/views/algorithmia/colorize_form.html.erb create mode 100644 app/views/algorithmia/image_tag_form.html.erb create mode 100644 app/views/algorithmia/process_colorize.html.erb create mode 100644 app/views/algorithmia/process_image_tag.html.erb create mode 100644 app/views/algorithmia/process_text_tag.html.erb create mode 100644 app/views/algorithmia/text_tag_form.html.erb create mode 100644 examples.txt diff --git a/README.md b/README.md index b824acd..39e1464 100644 --- a/README.md +++ b/README.md @@ -203,8 +203,3 @@ Here's how it should work: The API needs a bit of time to do it's work, so expect it to take about 30 seconds or so for the request to complete. Visit the [Illustration Tagger page](https://algorithmia.com/algorithms/deeplearning/IllustrationTagger), and follow the instructions at the bottom of the page to integrate the API in your controller. - - -## Stretch Goals - - - [Bootstrap it](http://getbootstrap.com/components/#panels) to make it look like [the real Omnicalc](http://omnicalc-target.herokuapp.com/). We've already connected `bootstrap.css` and [Font Awesome](http://fontawesome.io/icons/) for you, so you can just start using them. diff --git a/app/controllers/algorithmia_controller.rb b/app/controllers/algorithmia_controller.rb new file mode 100644 index 0000000..02bd2d3 --- /dev/null +++ b/app/controllers/algorithmia_controller.rb @@ -0,0 +1,45 @@ +class AlgorithmiaController < ApplicationController + def text_tag_form + #code + end + + def process_text_tag + @text = params[:text] + client = Algorithmia.client(ENV['ALGORITHMIA_KEY']) + algo = client.algo('nlp/AutoTag/1.0.1') + @tags = algo.pipe(@text).result + end + + def image_tag_form + #code + end + + def process_image_tag + input = { + image: params[:image_url] + } + client = Algorithmia.client('simVbAuHzAns0iC7jNJJxE9sbDW1') + algo = client.algo('deeplearning/IllustrationTagger/0.4.0') + @original_image_url = params[:image_url] + @tag_hashes = algo.pipe(input).result['general'] + end + + def colorize_form + #code + end + + def process_colorize + input = { + image: params[:image_url] + } + client = Algorithmia.client(ENV['ALGORITHMIA_KEY']) + algo = client.algo('deeplearning/ColorfulImageColorization/1.1.7') + result_hash = algo.pipe(input).result + result_output = result_hash['output'] + algorithmia_path = result_output.split("data://")[1] + @original_image_url = params[:image_url] + @colorized_image_url = "https://algorithmia.com/v1/data/#{algorithmia_path}" + end + + +end diff --git a/app/views/algorithmia/colorize_form.html.erb b/app/views/algorithmia/colorize_form.html.erb new file mode 100644 index 0000000..610cb74 --- /dev/null +++ b/app/views/algorithmia/colorize_form.html.erb @@ -0,0 +1,18 @@ +

+ Colorize +

+ +
+
+ + + + +
+ + +
diff --git a/app/views/algorithmia/image_tag_form.html.erb b/app/views/algorithmia/image_tag_form.html.erb new file mode 100644 index 0000000..ef7ad73 --- /dev/null +++ b/app/views/algorithmia/image_tag_form.html.erb @@ -0,0 +1,18 @@ +

+ Image Tagger +

+ +
+
+ + + + +
+ + +
diff --git a/app/views/algorithmia/process_colorize.html.erb b/app/views/algorithmia/process_colorize.html.erb new file mode 100644 index 0000000..38f286a --- /dev/null +++ b/app/views/algorithmia/process_colorize.html.erb @@ -0,0 +1,7 @@ +

Colorizer

+ +

Your original image

+
+ +

Colorized image

+
diff --git a/app/views/algorithmia/process_image_tag.html.erb b/app/views/algorithmia/process_image_tag.html.erb new file mode 100644 index 0000000..dd0a563 --- /dev/null +++ b/app/views/algorithmia/process_image_tag.html.erb @@ -0,0 +1,11 @@ +

Colorizer

+ +

Your original image

+
+ +

Generated tags for your image

+
    +<% @tag_hashes.each do |tag_hash| %> +
  • <%= tag_hash.keys[0] %>
  • +<% end %> +
diff --git a/app/views/algorithmia/process_text_tag.html.erb b/app/views/algorithmia/process_text_tag.html.erb new file mode 100644 index 0000000..e49e288 --- /dev/null +++ b/app/views/algorithmia/process_text_tag.html.erb @@ -0,0 +1,11 @@ +

Auto-tagger

+ +

Your text

+

<%= @text %>

+ +

Generated tags for your text

+
    +<% @tags.each do |tag| %> +
  • <%= tag %>
  • +<% end %> +
diff --git a/app/views/algorithmia/text_tag_form.html.erb b/app/views/algorithmia/text_tag_form.html.erb new file mode 100644 index 0000000..ae099f0 --- /dev/null +++ b/app/views/algorithmia/text_tag_form.html.erb @@ -0,0 +1,18 @@ +

+ Autotag +

+ +
+
+ + + + +
+ + +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e13ef3d..4e28a7c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -20,7 +20,9 @@
- <%= yield %> +
+ <%= yield %> +
diff --git a/config/routes.rb b/config/routes.rb index 787824f..679d88e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,11 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + + get "/image-tag" => "algorithmia#image_tag_form" + get "/image-tag/results" => "algorithmia#process_image_tag" + get "/colorize" => "algorithmia#colorize_form" + get "/colorize/results" => "algorithmia#process_colorize" + get "/text-tag" => "algorithmia#text_tag_form" + get "/text-tag/results" => "algorithmia#process_text_tag" end diff --git a/examples.txt b/examples.txt new file mode 100644 index 0000000..d2c8f9f --- /dev/null +++ b/examples.txt @@ -0,0 +1,63 @@ +example_id | status | run_time | +------------------------------------------ | ------ | --------------- | +./spec/features/algorithmia_spec.rb[1:1] | passed | 0.42592 seconds | +./spec/features/algorithmia_spec.rb[2:1] | passed | 0.02373 seconds | +./spec/features/algorithmia_spec.rb[3:1] | passed | 0.10707 seconds | +./spec/features/algorithmia_spec.rb[4:1] | passed | 0.06595 seconds | +./spec/features/algorithmia_spec.rb[5:1] | passed | 0.04462 seconds | +./spec/features/algorithmia_spec.rb[6:1] | passed | 0.02967 seconds | +./spec/features/algorithmia_spec.rb[7:1] | passed | 0.05147 seconds | +./spec/features/algorithmia_spec.rb[8:1] | passed | 0.03795 seconds | +./spec/features/algorithmia_spec.rb[9:1] | passed | 0.02798 seconds | +./spec/features/algorithmia_spec.rb[10:1] | passed | 0.02208 seconds | +./spec/features/algorithmia_spec.rb[11:1] | passed | 0.01762 seconds | +./spec/features/algorithmia_spec.rb[12:1] | passed | 0.05064 seconds | +./spec/features/calculations_spec.rb[1:1] | failed | 0.00177 seconds | +./spec/features/calculations_spec.rb[2:1] | failed | 0.01092 seconds | +./spec/features/calculations_spec.rb[3:1] | failed | 0.01252 seconds | +./spec/features/calculations_spec.rb[4:1] | failed | 0.00236 seconds | +./spec/features/calculations_spec.rb[5:1] | failed | 0.00266 seconds | +./spec/features/calculations_spec.rb[6:1] | failed | 0.00329 seconds | +./spec/features/calculations_spec.rb[7:1] | failed | 0.00248 seconds | +./spec/features/calculations_spec.rb[8:1] | failed | 0.00186 seconds | +./spec/features/calculations_spec.rb[9:1] | failed | 0.00305 seconds | +./spec/features/calculations_spec.rb[10:1] | failed | 0.0018 seconds | +./spec/features/calculations_spec.rb[11:1] | failed | 0.00996 seconds | +./spec/features/calculations_spec.rb[12:1] | failed | 0.00451 seconds | +./spec/features/calculations_spec.rb[13:1] | failed | 0.00237 seconds | +./spec/features/calculations_spec.rb[14:1] | failed | 0.00178 seconds | +./spec/features/calculations_spec.rb[15:1] | failed | 0.00204 seconds | +./spec/features/calculations_spec.rb[16:1] | failed | 0.00338 seconds | +./spec/features/calculations_spec.rb[17:1] | failed | 0.00251 seconds | +./spec/features/calculations_spec.rb[18:1] | failed | 0.00189 seconds | +./spec/features/calculations_spec.rb[19:1] | failed | 0.00151 seconds | +./spec/features/calculations_spec.rb[20:1] | failed | 0.00165 seconds | +./spec/features/calculations_spec.rb[21:1] | failed | 0.00172 seconds | +./spec/features/calculations_spec.rb[22:1] | failed | 0.00156 seconds | +./spec/features/calculations_spec.rb[23:1] | failed | 0.00217 seconds | +./spec/features/calculations_spec.rb[24:1] | failed | 0.00172 seconds | +./spec/features/calculations_spec.rb[25:1] | failed | 0.00246 seconds | +./spec/features/calculations_spec.rb[26:1] | failed | 0.00374 seconds | +./spec/features/calculations_spec.rb[27:1] | failed | 0.01445 seconds | +./spec/features/calculations_spec.rb[28:1] | failed | 0.00421 seconds | +./spec/features/calculations_spec.rb[29:1] | failed | 0.00275 seconds | +./spec/features/calculations_spec.rb[30:1] | failed | 0.00284 seconds | +./spec/features/calculations_spec.rb[31:1] | failed | 0.00713 seconds | +./spec/features/calculations_spec.rb[32:1] | failed | 0.0046 seconds | +./spec/features/calculations_spec.rb[33:1] | failed | 0.00726 seconds | +./spec/features/calculations_spec.rb[34:1] | failed | 0.00275 seconds | +./spec/features/calculations_spec.rb[35:1] | failed | 0.00208 seconds | +./spec/features/calculations_spec.rb[36:1] | failed | 0.00158 seconds | +./spec/features/calculations_spec.rb[37:1] | failed | 0.00161 seconds | +./spec/features/calculations_spec.rb[38:1] | failed | 0.00151 seconds | +./spec/features/calculations_spec.rb[39:1] | failed | 0.00172 seconds | +./spec/features/calculations_spec.rb[40:1] | failed | 0.00175 seconds | +./spec/features/calculations_spec.rb[41:1] | failed | 0.00183 seconds | +./spec/features/calculations_spec.rb[42:1] | failed | 0.00247 seconds | +./spec/features/calculations_spec.rb[43:1] | failed | 0.00183 seconds | +./spec/features/calculations_spec.rb[44:1] | failed | 0.00168 seconds | +./spec/features/calculations_spec.rb[45:1] | failed | 0.00279 seconds | +./spec/features/calculations_spec.rb[46:1] | failed | 0.00196 seconds | +./spec/features/calculations_spec.rb[47:1] | failed | 0.00396 seconds | +./spec/features/calculations_spec.rb[48:1] | failed | 0.0039 seconds | +./spec/features/calculations_spec.rb[49:1] | failed | 0.00252 seconds | From 55bd4a8cb7b1fa4b09c8dad5600663c197d8fff2 Mon Sep 17 00:00:00 2001 From: Arjun Venkataswamy Date: Wed, 21 Feb 2018 09:27:44 -0600 Subject: [PATCH 18/18] adds random num copy spec --- spec/features/calculations_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/features/calculations_spec.rb b/spec/features/calculations_spec.rb index 7242ada..fbb9c78 100644 --- a/spec/features/calculations_spec.rb +++ b/spec/features/calculations_spec.rb @@ -64,6 +64,16 @@ end end +describe "/flexible/random/[MINIMUM]/[MAXIMUM]" do + it "contains the correct baseline copy", points: 1 do + visit "/flexible/random/1/10" + + pattern = /A random number between 1 and 10 is/ + matched_groups = pattern.match(page.text) + expect(matched_groups).to_not be_nil + end +end + describe "/flexible/random/[MINIMUM]/[MAXIMUM]" do it "creates a constrained random number", points: 1 do visit "/flexible/random/1/10"