Skip to content

SergeyZa/CoderCardsV2

 
 

Repository files navigation

CoderCards - Class Libary Version

This is a precompiled function version of the Azure Functions sample CoderCards.

About the sample

  • This sample uses the new precompiled function feature. The project is a regular ASP.NET Web Application project. With a few tweaks, you can run and debug the project locally using the Azure Functions CLI. (See intructions below.)

  • The function is triggered when a new .jpg file appears in the container in the app setting/environment variable input-container. See function.json.

  • Based on an input image, one of 4 card templates is chosen based on emotion

  • The filename of the input image is used to draw the name and title on the card.

  • In order for the name and title to be drawn, the filename must be in the form Name of person-Title of person.jpg

  • A score based on the predominant emotion (e.g., anger, happiness) is drawn on the top

  • The card is written to the output blob container specified by the app setting output-container. See function.json.

Required App Settings

Key Description
AzureWebJobsStorage Storage account connection string
EmotionAPIKey Key for Cognitive Services Emotion API
input-container Name of Storage container for input images. Use a value like "local-card-input" locally and "card-input" on Azure
input-container Name of Storage container for output images. Use a value like "local-card-output" locally and "card-output" on Azure
HOME Set to "." when running locally. Is automatically set on Azure
SITE_PATH Use "." when running locally. Use site\\wwwroot on Azure

Local debugging in Visual Studio

Since the project is a Web App, by default F5 will launch IIS Express. With a few simple changes to the project settings, you can run the Azure Functions CLI and attach a debugger:

  • Right-click CoderCardsWebsite and open Properties.

  • In the Web tab, choose Start External Program

  • For the program path, enter the path to func.exe for the Azure Functions CLI.

    • If you've installed the Visual Studio Tools for Azure Functions, the path will look something like C:\Users\USERNAME\AppData\Local\Azure.Functions.Cli\1.0.0-beta.91\func.exe
    • If you've installed the Azure Functions CLI through NPM, the path will be something like C:\Users\USERNAME\AppData\Roaming\npm\node_modules\azure-functions-cli\bin\func.exe
  • For Command line arguments set host start

  • For Working directory, specify the root of the project CoderCardsWebsite on your machine.

Start external program settings

Running the demo

  1. Choose images that are square with a filename in the form Name of person-Title of person.jpg. The filename is parsed to produce text on the card.

  2. Drop images into the card-input container. Once the function runs, you'll see generated cards in card-output.

Notes

Talking points about Azure Functions

  • The code is triggered off a new blob in a container. We automatically get a binding for both the byte array and the blob name

  • The blob name is used to generate the text on the image

  • The input binding is just a byte array, which makes it easy to manipulate with memory streams (no need to create new ones)

  • Other binding types for C# are Stream, CloudBlockBlob, etc, which is very flexible.

  • The output binding is just a stream that you just write to

  • This is a very declarative model, details of binding are in a separate json file that can be edited manually or through the Integrate UX

  • In general, functions will scale based on the amount of events in input. A real system would probably use something like Azure Queue or Service Bus triggers, in order to track messages more closely.

About

Class library version of CoderCards

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%