Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoPR @azure/cognitiveservices-face] Fixes for FaceAPI #4864

Closed
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
105 changes: 50 additions & 55 deletions sdk/cognitiveservices/cognitiveservices-face/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,86 +15,81 @@ npm install @azure/cognitiveservices-face

### How to use

#### nodejs - Authentication, client creation and list personGroupPerson as an example written in TypeScript.
#### nodejs - client creation and list personGroupPerson as an example written in TypeScript.

##### Install @azure/ms-rest-azure-js
##### Install @azure/ms-rest-nodeauth

- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`.
```bash
npm install @azure/ms-rest-azure-js
npm install @azure/ms-rest-nodeauth@"^3.0.0"
```

##### Sample code
The following sample detects the facial features on the given image. To know more, refer to the [Azure Documentation on Face APIs](https://docs.microsoft.com/azure/cognitive-services/face/overview)

```javascript
const { FaceClient, FaceModels } = require("@azure/cognitiveservices-face");
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");

async function main() {
const faceKey = process.env["faceKey"] || "<faceKey>";
const faceEndPoint = process.env["faceEndPoint"] || "<faceEndPoint>";
const cognitiveServiceCredentials = new CognitiveServicesCredentials(faceKey);
const client = new FaceClient(cognitiveServiceCredentials, faceEndPoint);
const url =
"https://pbs.twimg.com/profile_images/3354326900/3a5168f2b45c07d0965098be1a4e3007.jpeg";
const options = {
returnFaceLandmarks: true
};
client.face
.detectWithUrl(url, options)
.then(result => {
console.log("The result is: ");
console.log(result);
})
.catch(err => {
console.log("An error occurred:");
console.error(err);
});
}

main();

While the below sample uses the interactive login, other authentication options can be found in the [README.md file of @azure/ms-rest-nodeauth](https://www.npmjs.com/package/@azure/ms-rest-nodeauth) package
```typescript
const msRestNodeAuth = require("@azure/ms-rest-nodeauth");
const { FaceClient } = require("@azure/cognitiveservices-face");
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];

msRestNodeAuth.interactiveLogin().then((creds) => {
const client = new FaceClient(creds, subscriptionId);
const personGroupId = "testpersonGroupId";
const start = "teststart";
const top = 1;
client.personGroupPerson.list(personGroupId, start, top).then((result) => {
console.log("The result is:");
console.log(result);
});
}).catch((err) => {
console.error(err);
});
```

#### browser - Authentication, client creation and list personGroupPerson as an example written in JavaScript.

##### Install @azure/ms-rest-browserauth

```bash
npm install @azure/ms-rest-browserauth
```

##### Sample code

See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser.

- index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>@azure/cognitiveservices-face sample</title>
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
<script src="node_modules/@azure/ms-rest-browserauth/dist/msAuth.js"></script>
<script src="node_modules/@azure/cognitiveservices-face/dist/cognitiveservices-face.js"></script>
<script type="text/javascript">
const faceKey = "<YOUR_FACE_KEY>";
const faceEndPoint = "<YOUR_FACE_ENDPOINT>";
const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
inHeader: {
"Ocp-Apim-Subscription-Key": faceKey
}
const subscriptionId = "<Subscription_Id>";
const authManager = new msAuth.AuthManager({
clientId: "<client id for your Azure AD app>",
tenant: "<optional tenant for your organization>"
});
const client = new Azure.CognitiveservicesFace.FaceClient(
cognitiveServiceCredentials,
faceEndPoint
);

const url =
"https://pbs.twimg.com/profile_images/3354326900/3a5168f2b45c07d0965098be1a4e3007.jpeg";
const options = {
returnFaceLandmarks: true
};
client.face
.detectWithUrl(url, options)
.then(result => {
console.log("The result is: ");
authManager.finalizeLogin().then((res) => {
if (!res.isLoggedIn) {
// may cause redirects
authManager.login();
}
const client = new Azure.CognitiveservicesFace.FaceClient(res.creds, subscriptionId);
const personGroupId = "testpersonGroupId";
const start = "teststart";
const top = 1;
client.personGroupPerson.list(personGroupId, start, top).then((result) => {
console.log("The result is:");
console.log(result);
})
.catch(err => {
}).catch((err) => {
console.log("An error occurred:");
console.error(err);
});
});
</script>
</head>
<body></body>
Expand All @@ -105,4 +100,4 @@ main();

- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcognitiveservices%2Fcognitiveservices-face%2FREADME.png)
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-face/README.png)
4 changes: 2 additions & 2 deletions sdk/cognitiveservices/cognitiveservices-face/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const config = {
"@azure/ms-rest-azure-js": "msRestAzure"
},
banner: `/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand All @@ -15,6 +15,7 @@ export {
LargePersonGroup,
MetaDataContract,
NameAndUserDataContract,
NonNullableNameAndNullableUserDataContract,
PersistedFace,
Person,
PersonGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down
41 changes: 20 additions & 21 deletions sdk/cognitiveservices/cognitiveservices-face/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand Down Expand Up @@ -574,11 +574,11 @@ export interface PersistedFace {
* A combination of user defined name and user specified data for the person,
* largePersonGroup/personGroup, and largeFaceList/faceList.
*/
export interface NameAndUserDataContract {
export interface NonNullableNameAndNullableUserDataContract {
/**
* User defined name, maximum length is 128.
*/
name?: string;
name: string;
/**
* User specified data. Length should not exceed 16KB.
*/
Expand All @@ -589,7 +589,7 @@ export interface NameAndUserDataContract {
* A combination of user defined name and user specified data and recognition model name for
* largePersonGroup/personGroup, and largeFaceList/faceList.
*/
export interface MetaDataContract extends NameAndUserDataContract {
export interface MetaDataContract extends NonNullableNameAndNullableUserDataContract {
/**
* Possible values include: 'recognition_01', 'recognition_02', 'recognition_03',
* 'recognition_04'. Default value: 'recognition_01'.
Expand Down Expand Up @@ -621,6 +621,21 @@ export interface PersonGroup extends MetaDataContract {
personGroupId: string;
}

/**
* A combination of user defined name and user specified data for the person,
* largePersonGroup/personGroup, and largeFaceList/faceList.
*/
export interface NameAndUserDataContract {
/**
* User defined name, maximum length is 128.
*/
name?: string;
/**
* User specified data. Length should not exceed 16KB.
*/
userData?: string;
}

/**
* Person object.
*/
Expand Down Expand Up @@ -1141,10 +1156,6 @@ export interface PersonGroupPersonAddFaceFromStreamOptionalParams extends msRest
* Optional Parameters.
*/
export interface PersonGroupCreateOptionalParams extends msRest.RequestOptionsBase {
/**
* User defined name, maximum length is 128.
*/
name?: string;
/**
* User specified data. Length should not exceed 16KB.
*/
Expand Down Expand Up @@ -1204,10 +1215,6 @@ export interface PersonGroupListOptionalParams extends msRest.RequestOptionsBase
* Optional Parameters.
*/
export interface FaceListCreateOptionalParams extends msRest.RequestOptionsBase {
/**
* User defined name, maximum length is 128.
*/
name?: string;
/**
* User specified data. Length should not exceed 16KB.
*/
Expand Down Expand Up @@ -1411,10 +1418,6 @@ export interface LargePersonGroupPersonAddFaceFromStreamOptionalParams extends m
* Optional Parameters.
*/
export interface LargePersonGroupCreateOptionalParams extends msRest.RequestOptionsBase {
/**
* User defined name, maximum length is 128.
*/
name?: string;
/**
* User specified data. Length should not exceed 16KB.
*/
Expand Down Expand Up @@ -1474,10 +1477,6 @@ export interface LargePersonGroupListOptionalParams extends msRest.RequestOption
* Optional Parameters.
*/
export interface LargeFaceListCreateOptionalParams extends msRest.RequestOptionsBase {
/**
* User defined name, maximum length is 128.
*/
name?: string;
/**
* User specified data. Length should not exceed 16KB.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand All @@ -15,6 +15,7 @@ export {
LargePersonGroup,
MetaDataContract,
NameAndUserDataContract,
NonNullableNameAndNullableUserDataContract,
PersistedFace,
Person,
PersonGroup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand All @@ -14,6 +14,7 @@ export {
LargePersonGroup,
MetaDataContract,
NameAndUserDataContract,
NonNullableNameAndNullableUserDataContract,
PersistedFace,
Person,
PersonGroup,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
Expand All @@ -9,14 +9,9 @@
export {
APIError,
ErrorModel,
FaceList,
ImageUrl,
LargeFaceList,
LargePersonGroup,
MetaDataContract,
NameAndUserDataContract,
PersistedFace,
Person,
PersonGroup,
UpdateFaceRequest
} from "../models/mappers";
Loading