Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ end

gem 'jquery-rails'
gem "turbolinks"
gem 'algorithmia'
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -267,6 +274,7 @@ PLATFORMS
ruby

DEPENDENCIES
algorithmia
annotate
awesome_print
better_errors
Expand Down
84 changes: 82 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,86 @@ 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)

## Stretch Goals
## Part IV: Homework

- [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.
### 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. Create a new file at the root directory of your application and call it `.env`. In the file place, the following code:

```
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['ALGORITHMIA_KEY']
```

and we should see output of

```
"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 actual Algorithmia API key.

### 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 `/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.
```
- 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**

### Problem 2 - Colorize Images

The next service we'll use 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 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.
45 changes: 45 additions & 0 deletions app/controllers/algorithmia_controller.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions app/views/algorithmia/colorize_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1>
Colorize
</h1>

<form action="/colorize/results">
<div class="form-group">
<label for="image_url">
Image URL
</label>

<input id="image_url" text="text" name="image_url" class="form-control" placeholder="https://somewebsite.com/image.jpg">

</div>

<button class="btn btn-primary">
Colorize
</button>
</form>
18 changes: 18 additions & 0 deletions app/views/algorithmia/image_tag_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1>
Image Tagger
</h1>

<form action="/image-tag/results">
<div class="form-group">
<label for="image_url">
Image URL
</label>

<input id="image_url" text="text" name="image_url" class="form-control" placeholder="https://somewebsite.com/image.jpg">

</div>

<button class="btn btn-primary">
Process
</button>
</form>
7 changes: 7 additions & 0 deletions app/views/algorithmia/process_colorize.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Colorizer</h1>

<h4>Your original image</h4>
<div><img src="<%= @original_image_url %>"></div>

<h4>Colorized image</h4>
<div><img src="<%= @colorized_image_url %>"></div>
11 changes: 11 additions & 0 deletions app/views/algorithmia/process_image_tag.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Colorizer</h1>

<h4>Your original image</h4>
<div><img src="<%= @original_image_url %>"></div>

<h4>Generated tags for your image</h4>
<ul>
<% @tag_hashes.each do |tag_hash| %>
<li><%= tag_hash.keys[0] %></li>
<% end %>
</ul>
11 changes: 11 additions & 0 deletions app/views/algorithmia/process_text_tag.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Auto-tagger</h1>

<h4>Your text</h4>
<p><%= @text %></p>

<h4>Generated tags for your text</h4>
<ul>
<% @tags.each do |tag| %>
<li><%= tag %></li>
<% end %>
</ul>
18 changes: 18 additions & 0 deletions app/views/algorithmia/text_tag_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1>
Autotag
</h1>

<form action="/text-tag/results">
<div class="form-group">
<label for="text">
Text
</label>

<textarea id="text" name="text" class="form-control"></textarea>

</div>

<button class="btn btn-primary">
Generate Tags
</button>
</form>
4 changes: 3 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

<body>
<div class="container">
<%= yield %>
<div class="col">
<%= yield %>
</div>
</div>

<div class="rails-toolbar">
Expand Down
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
63 changes: 63 additions & 0 deletions examples.txt
Original file line number Diff line number Diff line change
@@ -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 |
Loading