Consume Microsoft Cognitive Services API from Spring Boot application
- Face API [1] example with age and emotion attributes:
- Git clone
FaceAPIDemo/mvn clean install
java -jar target/FaceAPIDemo-0.0.1-SNAPSHOT.jar --subscription.key=<key> --sample.url=<picture url> --face.attributes=<csv>
- UI mode: Just hit root deployment url (e.g. http://localhost:8080)
- API mode:
- Make sure environment variables
subscription.key
,sample.url
andface.attributes
are populated - Hit /detect endpoint (e.g.http://localhost:8080/detect)
- Make sure environment variables
- Replace the placeholders in application.properties as required
- Deploy to Pivotal Cloud Foundry (PCF)
- Launch cf cli from e.g. Azure Cloud Shell
- cf push (sample manifest provided)
- User provided services to bind Congnitive Services to an app running in PCF:
- create UPSI:
cf cups cognitive -p '{"key":"--- API key goes here ---"}'
- bind the service to the app. Make sure to use
cognitive
as the service name for the binding to work:cf bind-service face-api cognitive
- restage the app
cf restage face-api
- create UPSI:
[1] https://docs.microsoft.com/en-us/azure/cognitive-services/face/overview