Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/prateekkumarsingh/pscognitiveservice

Powershell module to access Microsoft Azure Machine learning RESTful API's or Microsoft cognitive services
https://github.com/prateekkumarsingh/pscognitiveservice

azure emotion entity face gender image-analysis keyphrases microsoft-cognitive-services powershell sentiment vision

Last synced: about 3 hours ago
JSON representation

Powershell module to access Microsoft Azure Machine learning RESTful API's or Microsoft cognitive services

Awesome Lists containing this project

README

        

[![Build status](https://ci.appveyor.com/api/projects/status/jgiom7ww0nhc5kt7?svg=true)](https://ci.appveyor.com/project/PrateekKumarSingh/pscognitiveservice)
[![PowershellGallery](https://img.shields.io/powershellgallery/v/PSCognitiveService.svg)](https://www.powershellgallery.com/packages/PSCognitiveService)

# PowerShell Module for Microsoft Cognitive Services (aka, ProjectOxford)
Microsoft Cognitive Services are some machine learning Artificial intelligent REST API's to give Human-like cognition abilities to your applications.

# What this module can do?

```PowerShell
# install module
Install-Module PSCognitiveService -Force -Scope CurrentUser -Verbose

# import module
Import-Module PSCognitiveService -Force -Verbose

# get module
Get-Command -Module PSCognitiveService

# login and obtain subscription keys, local config
New-LocalConfiguration -FromAzure -AddKeysToProfile | Out-Null

# face features & emotion recognitionc
Get-Face -Path 'C:\tmp\Bill.jpg' |Format-List *

# image analysis
Get-ImageAnalysis -Path 'C:\tmp\Bill.jpg'

# image description
Get-ImageDescription -Path 'C:\tmp\Bill.jpg' | ForEach-Object Description | Format-List

# tag image and convert to hashtags
Get-ImageTag -URL https://goo.gl/Q73Qtw |
ForEach-Object{$_.tags.name} | ForEach-Object {'#'+$_ -join ' '}

# optical character recognition
Get-ImageText -URL https://goo.gl/XyP6LJ |
ForEach-Object {$_.regions.lines.words.text -join ' '}

# convert to thumbnail
ConvertTo-Thumbnail -URL https://goo.gl/XyP6LJ -SmartCropping

# bing search
Search-Web 'powershell 6.1' -c 3 |
ForEach-Object {$_.webpages.value} | Format-List name, url, snippet
Search-Entity -Text 'brad pitt' |
ForEach-Object {$_.entities.value} | Format-List name, description, image, webSearchUrl

# text analytics
Get-Sentiment -Text "Hey good morning!","Such a wonderful day","I feel sad about you" | ForEach-Object documents
Get-KeyPhrase -Text "Hey good morning!","Such a wonderful day","I feel sad about these poor people" | ForEach-Object documents
Trace-Language -Text "Hey good morning!", "Bonjour tout le monde", "La carretera estaba atascada" | ForEach-Object {$_.documents.detectedlanguages}

# moderate content - text, image (path/url)
Test-AdultRacyContent -Text "Hello World" | ForEach-Object Classification # clean
Test-AdultRacyContent -Text "go eff yourself" | ForEach-Object Classification # not good/review required
Test-AdultRacyContent -Path 'C:\Tmp\test.png'
Test-AdultRacyContent -URL https://goo.gl/uY2PS6

```

# Pre-Requisites
You need to do one-time registration for each Microsoft Cognitive Services API from HERE, before start using the module, because it won’t work without an API Key.

## 1. Installation

### [PowerShell v5](https://www.microsoft.com/en-us/download/details.aspx?id=50395) and Later
You can install the `PSCognitiveService` module directly from the PowerShell Gallery

* **[Recommended]** Install to your personal PowerShell Modules folder
```PowerShell
Install-Module PSCognitiveService -scope CurrentUser
```
* **[Requires Elevation]** Install for Everyone (computer PowerShell Modules folder)
```PowerShell
Install-Module PSCognitiveService
```
### PowerShell v4 and Earlier
To install to your personal modules folder run:
```PowerShell
iex (new-object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/PrateekKumarSingh/PSCognitiveService/master/Install.ps1')
```

## 2. Subscribe
Microsoft Cognitive services are offered and subscribed through the Azure Portal to achieve that -

- **Create cognitive service accounts** in azure portal.
- **Obtain subscription keys**
- **Set $Env variables** locally, which would consumed by the module cmdlets to make REST API call's.

Personally, going to azure portal and obtaining subscription keys is a turn down for me.

But, ```New-CognitiveServiceAccount```cmdlet that is included in this module to create Azure cognitive service accounts/subscription from your console.

Example, if you want to use the ```Search-Web``` cmdlet that utlizes ```Bing Search``` capabilities, you need to subscribe to Cognitive Service account of type: ```Bing.Search.v7```, just run the below cmdlet.

```PowerShell
New-CognitiveServiceAccount -AccountType Bing.Search.v7

# alternatively, specify ResourceGroup, Location and SKU
New-CognitiveServiceAccount -AccountType ComputerVision -ResourceGroupName ResourceGroup1 -Location centralindia -SKUName S1
```

## 3. Configure Locally

Alright, you are now subscribed, but how to obtain the subscription key(s) and set-up ```$ENV``` variable(s) in the session to run these cmdlets.

It is as simple as a below cmdlet and Kaboom! you are subscribed and local configuration is complete!

```PowerShell
New-LocalConfiguration -FromAzure -AddKeysToProfile -Verbose
```
**NOTE** - Please add the subscription keys to your ```$Profile``` using ```-AddKeysToProfile``` switch for future use and to avoid above configuration step.