Skip to content

Commit

Permalink
Adding a free trial Microsoft Cognitive Vision API key.
Browse files Browse the repository at this point in the history
  • Loading branch information
kgrashad committed Sep 29, 2016
1 parent 137a25e commit 43625dd
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 47 deletions.
1 change: 1 addition & 0 deletions CSharp/intelligence-ImageCaption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A sample bot that illustrates how to use the [Microsoft Cognitive Services Compu
The minimum prerequisites to run this sample are:
* The latest update of Visual Studio 2015. You can download the community version [here](http://www.visualstudio.com) for free.
* The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://aka.ms/bf-bc-emulator). Please refer to [this documentation article](https://docs.botframework.com/en-us/csharp/builder/sdkreference/gettingstarted.html#emulator) to know more about the Bot Framework Emulator.
* This sample currently uses a free trial Microsoft Cognitive service key with limited QPS. Please subscribe to Vision API services [here](https://www.microsoft.com/cognitive-services/en-us/subscriptions) and update the `MicrosoftVisionApiKey` key in [Web.config](Web.config) file to try it out further.

### Code Highlights
Microsoft Computer Vision API provides a number of methods that allows you to analyze an image. Check out [IVisionServiceClient.cs](https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/Vision/Windows/ClientLibrary/IVisionServiceClient.cs) for a complete reference of the methods available. In this sample we are using `AnalyzeImageAsync(string url, ...)` and `AnalyzeImageAsync(Stream imageStream, ...)` to analyze an image from a URL and stream respectively. The `AnalyzeImageAsync` method returns [AnalysisResult.cs](https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/Vision/Windows/ClientLibrary/Contract/AnalysisResult.cs) class which contains rich information about the image:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ public class MicrosoftCognitiveCaptionService : ICaptionService
/// </summary>
private static readonly string ApiKey = WebConfigurationManager.AppSettings["MicrosoftVisionApiKey"];

/// <summary>
/// Error message to be shown to developer if MicrosoftVisionApiKey is missing
/// </summary>
private const string MissingApiKeyMessage = "MicrosoftVisionApiKey is missing in web.config. " +
"You can obtain one from https://www.microsoft.com/cognitive-services/en-us/subscriptions?productId=/products/54d873dd5eefd00dc474a0f4";

/// <summary>
/// The set of visual features we want from the Vision API.
/// </summary>
Expand All @@ -43,13 +37,6 @@ public class MicrosoftCognitiveCaptionService : ICaptionService
/// <returns>Description if caption found, null otherwise.</returns>
public async Task<string> GetCaptionAsync(string url)
{
#if DEBUG
if (string.IsNullOrEmpty(ApiKey))
{
return MissingApiKeyMessage;
}
#endif

var client = new VisionServiceClient(ApiKey);
var result = await client.AnalyzeImageAsync(url, VisualFeatures);
return ProcessAnalysisResult(result);
Expand All @@ -66,13 +53,6 @@ public async Task<string> GetCaptionAsync(string url)
/// <returns>Description if caption found, null otherwise.</returns>
public async Task<string> GetCaptionAsync(Stream stream)
{
#if DEBUG
if (string.IsNullOrEmpty(ApiKey))
{
return MissingApiKeyMessage;
}
#endif

var client = new VisionServiceClient(ApiKey);
var result = await client.AnalyzeImageAsync(stream, VisualFeatures);
return ProcessAnalysisResult(result);
Expand Down
8 changes: 7 additions & 1 deletion CSharp/intelligence-ImageCaption/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<add key="BotId" value="YourBotId" />
<add key="MicrosoftAppId" value="" />
<add key="MicrosoftAppPassword" value="" />
<add key="MicrosoftVisionApiKey" value="" />

<!--
This is a free trial Microsoft Cognitive service key with limited QPS.
Please subscribe to Vision API services to try it out further.
Subscription URL: https://www.microsoft.com/cognitive-services/en-us/subscriptions
-->
<add key="MicrosoftVisionApiKey" value="da64bb75525b430bb8ebd695b5684b71" />
</appSettings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
Expand Down
9 changes: 1 addition & 8 deletions CSharp/intelligence-ImageCaption/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@
},
"Project": {
"type": "string",
"defaultValue": "CSharp/intelligennce-ImageCaption"
"defaultValue": "CSharp/intelligence-ImageCaption"
},
"MicrosoftAppId": {
"type": "string"
},
"MicrosoftAppPassword": {
"type": "string"
},
"MicrosoftVisionApiKey": {
"type": "string"
}
},
"resources": [
Expand Down Expand Up @@ -100,10 +97,6 @@
{
"name": "MicrosoftAppPassword",
"value": "[parameters('MicrosoftAppPassword')]"
},
{
"name": "MicrosoftVisionApiKey",
"value": "[parameters('MicrosoftVisionApiKey')]"
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions Node/intelligence-ImageCaption/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MICROSOFT_APP_ID=
MICROSOFT_APP_PASSWORD=

# Vision Api Variables
# You need to add the MICROSOFT_VISION_API_KEY value in order for the bot to work.
# You can obtain one from https://www.microsoft.com/cognitive-services/en-us/subscriptions?productId=/products/54d873dd5eefd00dc474a0f4
MICROSOFT_VISION_API_KEY=
# This is a free trial Microsoft Cognitive service key with limited QPS.
# Please subscribe to Vision API services to try it out further.
# Subscription URL: https://www.microsoft.com/cognitive-services/en-us/subscriptions
MICROSOFT_VISION_API_KEY=da64bb75525b430bb8ebd695b5684b71
1 change: 1 addition & 0 deletions Node/intelligence-ImageCaption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The minimum prerequisites to run this sample are:
* The Bot Framework Emulator. To install the Bot Framework Emulator, download it from [here](https://aka.ms/bf-bc-emulator). Please refer to [this documentation article](https://docs.botframework.com/en-us/csharp/builder/sdkreference/gettingstarted.html#emulator) to know more about the Bot Framework Emulator.
* Computer Vision App ID. You can obtain one from [Microsoft Cognitive Services Subscriptions Page](https://www.microsoft.com/cognitive-services/en-us/subscriptions?productId=/products/54d873dd5eefd00dc474a0f4).
* **[Recommended]** Visual Studio Code for IntelliSense and debugging, download it from [here](https://code.visualstudio.com/) for free.
* This sample currently uses a free trial Microsoft Cognitive service key with limited QPS. Please subscribe to Vision API services [here](https://www.microsoft.com/cognitive-services/en-us/subscriptions) and update the `MicrosoftVisionApiKey` key in [.env](.env) file to try it out further.


### Code Highlights
Expand Down
5 changes: 0 additions & 5 deletions Node/intelligence-ImageCaption/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ An image caption bot for the Microsoft Bot Framework.
// This loads the environment variables from the .env file
require('dotenv-extended').load();

if (!process.env.MICROSOFT_VISION_API_KEY) {
console.error("Missing MICROSOFT_VISION_API_KEY. Please set it in the '.env' file. You can obtain one from https://www.microsoft.com/cognitive-services/en-us/subscriptions?productId=/products/54d873dd5eefd00dc474a0f4");
process.exit()
}

const builder = require('botbuilder'),
captionService = require('./caption-service'),
needle = require("needle"),
Expand Down
9 changes: 1 addition & 8 deletions Node/intelligence-ImageCaption/azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"Project": {
"type": "string",
"defaultValue": "Node/intelligennce-ImageCaption"
"defaultValue": "Node/intelligence-ImageCaption"
},
"WEBSITE_NODE_DEFAULT_VERSION": {
"type": "string",
Expand All @@ -50,9 +50,6 @@
},
"MicrosoftAppPassword": {
"type": "string"
},
"MicrosoftVisionApiKey": {
"type": "string"
}
},
"resources": [
Expand Down Expand Up @@ -108,10 +105,6 @@
{
"name": "MICROSOFT_APP_PASSWORD",
"value": "[parameters('MicrosoftAppPassword')]"
},
{
"name": "MICROSOFT_VISION_API_KEY",
"value": "[parameters('MicrosoftVisionApiKey')]"
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion Node/intelligence-ImageCaption/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"botbuilder": "^3.2.3",
"dotenv-extended": "^1.0.3",
"needle": "^1.1.2",
"request": "^2.75.0",
"restify": "^4.1.1",
"valid-url": "^1.0.9"
}
}
}

0 comments on commit 43625dd

Please sign in to comment.