Giter Club home page Giter Club logo

vista's Introduction

Vista Demo

logo

Running Locally

This demo is designed to be run outside of a corporate firewall. The moving parts have not been instrumented to run with proxies.

Step 1: Get prerequisite accounts

Step 2: Set required env vars

  1. Copy envs-example.sh to envs.sh and fill in all the required values.
  2. Run: . ./envs.sh - NOTE: You NEED the initial .

Step 2: Install Fn CLI and start Fn server

Ensure Docker is running. Ensure you are logged in with docker login.

Install fn CLI:

curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh

Then start fn server:

fn start

(Easy huh?)

Step 3: Set everything up

Use the local arg to do everything locally (ie: doesn't push to docker registry).

./setup.sh [local]

Step 4: Run the demo!

./run.sh

This will open a browser window to view the results.

You should also see activity in the server logs, and output to the vista.html screen. As the draw function finishes, the final images will push to the screen. Plate detection will also Tweet out from the alert function.

Future Work Ideas

  • All counts will be moved to Functions UI so can simplify by removing those graphs.
  • Video stream (split-video) added. Could do more work around this. TBD.
  • Also see issues

Other ideas: Feel free to create GitHub issues or contact Chad

Understanding How This Works

In this sort of mashup, the most important thing to understand are the boxes and the lines. The boxes are the services and the lines are the wiring between the services. Let's look at the wiring first.

Wiring

The demo uses minio as a stand-in for Amazon S3 storage. This enables the demo to be written for the S3 API, yet not have to actually use S3 for the storage.

The functions themselves are set up and "routed" when the make deploy happens.

The act of running the setenv.sh script pushes the current set of env vars into the function runtimes. This includes mashup keys, tokens, and secrets vital to the success of the demo.

After this completes, you can do

fn routes list myapp
path  image     endpoint
/alert  <dockerid>/alert:0.1.18  f8cb781a.ngrok.io/r/myapp/alert
/detect-faces <dockerid>/detect-faces:0.1.12 f8cb781a.ngrok.io/r/myapp/detect-faces
/detect-plates <dockerid>/detect-plates:0.1.15 f8cb781a.ngrok.io/r/myapp/detect-plates
/draw  <dockerid>/draw:0.1.20  f8cb781a.ngrok.io/r/myapp/draw
/publish <dockerid>/publish:0.1.13  f8cb781a.ngrok.io/r/myapp/publish
/scraper <dockerid>/scraper:0.1.13  f8cb781a.ngrok.io/r/myapp/scraper

Finally, the minio wiring. I'm a bit foggy on this, but it basically sets up something that looks like an Amazon S3 bucket.

Services

scraper

This Ruby based service service uses the Flickr API, as exposed to Ruby by <https://github.com/hanklords/flickraw>. The service is built from the Dockerfile, which includes a Gemfile that pulls in the required dependencies flickraw, json, and rest-client. The Dockerfile lists func.rb as the entrypoint.

Looking at func.rb, it pulls in the "payload" from stdin, expecting it to be JSON that looks like

{
  "query": "license plate car usa",
  "num": "20",
  "countrycode": "us",
  "service_to_call": "detect-plates"
  }

The function does the secret sauce call here:

photos = flickr.photos.search(
    :text => search_text,
    :per_page => num_results,
  :page => page,
    :extras => 'original_format',
    :safe_search => 1,
    :content_type => 1
)

For each photo in the result set, do a POST to FUNC_SERVER_URL/detect-plates. Post data is the following:

payload = {:id => photo.id, 
           :image_url => image_url,
           :countrycode => payload_in["countrycode"],
           :bucket => payload_in["bucket"]
}

detect-plates

This service is a go based service that uses two dependencies, as well as a whole passel of standard go packages.

Looking at the main.go, it looks like this service reads the POST payload, calls fnstart(), passing the BUCKET env var and the photo id. Simply appears to fob the request off to pubnub. I think this may be a way to allow other services to asynchronously consume the result of this service's plate detection. The secret sauce function is here:

results, err := alpr.RecognizeByBlob(imageBytes)

For each entry in results, build another payload, adding a "rectangles" array and the text of the plate number. The payload looks like:

pout := &payloadOut{
    ID:         p.ID,
    ImageURL:   p.URL,
    Rectangles: []rectangle{{StartX: plate.PlatePoints[0].X, StartY: plate.PlatePoints[0].Y, EndX: plate.PlatePoints[2].X, EndY: plate.PlatePoints[2].Y}},
    Plate:      plate.BestPlate,
}

This is posted further downstream to the draw function at

postURL := os.Getenv("FUNC_SERVER_URL") + "/draw"

and also a copy of the same payload is posted to the alert service.

alertPostURL := os.Getenv("FUNC_SERVER_URL") + "/alert"

Draw service

We're back in Ruby for this one. But the runtime of the func.yaml is "" instead of ruby. This means to use the Dockerfile to build the function. This ruby service uses alpine-sdk and imagemagick. Upon receipt of a payload, first we send a message to pubnub saying we are running an image. The image is downloaded from the payload. We use ImageMagick to draw the rectangles in the payload on the image. We then upload the new image to MINIO, which looks like it is acting as a standin to Amazon S3. Finally we send a message to pubnub saying this run is done.

Alert service

This one is in Go again. Runtime is the empty string. Again, is this picked up from the func.go? This uses the Anaconda go twitter client library https://github.com/ChimeraCoder/anaconda. It also uses pubnub.

Recall that the payload coming to us is the same one sent to the image service. It downloads the image from the URL, converts it to base64, and composes a tweet including the image and the plate text. As with detect-plates, this uses pubnub to update the status.

vista.html

It looks like this entirely relies on pubnub to draw the fancy dynamically updating line chart and the images as they come along.

This uses the pubnub javascript API, as well as highcharts.

vista's People

Contributors

carimura avatar hibooboo2 avatar termie avatar treeder avatar tteggel avatar zootalures avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.