<!DOCTYPE html >
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="UTF-8">
<title>Microsoft ML with SAPUI5</title>
<script
id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-resourceroots='{"sapml.microsoftml": "./"}'>
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.xmlview({
viewName: "sapml.microsoftml.view.App"
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
<mvc:View displayBlock="true" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout"
controllerName="sapml.microsoftml.controller.App">
<App>
<pages>
<Page title="Microsoft Machine Learning\ Computer Vision"
icon="https://cpgeneralstore.blob.core.windows.net/icons/cognitiveservicescomputervision.png">
<subHeader height="150px">
<Toolbar>
<l:HorizontalLayout class="sapUiSmallMargin">
<Image class="sapUiSmallMarginEnd" src="https://cpgeneralstore.blob.core.windows.net/icons/cognitiveservicescomputervision.png"
densityAware="true" width="100px" height="100px" alignItems="Start"></Image>
</l:HorizontalLayout>
<FlexBox height="50px" width="90%" alignItems="End" justifyContent="End">
</FlexBox>
</Toolbar>
</subHeader>
<content>
<Panel expandable="true" expanded="false" headerText="Computer Vision" width="auto" class="sapUiResponsiveMargin">
<content>
<l:VerticalLayout width="100%">
<Label text='Image' level="H3" class="sapUiSmallMarginEnd" design="Bold"/>
<Input id="imgInput" type="Text" placeholder="Enter Image URL ..."/>
<Button text="Magic" icon="sap-icon://activate" width="150px" press="onClick"/>
<Text id="output" class="sapUiSmallMarginEnd"/>
<Text id="celebrity" class="sapUiSmallMarginEnd"/>
<Text id="landmark" class="sapUiSmallMarginEnd"/>
<Text id="responseTextArea" class="sapUiSmallMarginEnd"/>
<Image id="dispImage" class="sapUiSmallMarginEnd" width="100%" height="100%" densityAware="true" alignItems="Start"></Image>
</l:VerticalLayout>
</content>
</Panel>
</content>
</Page>
</pages>
</App>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast",
"jquery.sap.global"
], function(Controller, MessageToast) {
"use strict";
return Controller.extend("sapml.microsoftml.controller.App", {
onInit: function() {
// set mock model
MessageToast.show("Welcome Guest");
},
onClick: function() {
// set mock model
var url = this.getView().byId("imgInput").getValue();
MessageToast.show("Searching " + url);
var view = this.getView();
view.byId("responseTextArea").setText("");
view.byId("output").setText("");
view.byId("celebrity").setText("");
view.byId("landmark").setText("");
view.byId("dispImage").setSrc("");
// Replace the subscriptionKey string value with your valid subscription key.
var subscriptionKey = <replace this with your subscription key>;
// Replace or verify the region.
//
// You must use the same region in your REST API call as you used to obtain your subscription keys.
// For example, if you obtained your subscription keys from the westus region, replace
// "westcentralus" in the URI below with "westus".
//
// NOTE: Free trial subscription keys are generated in the westcentralus region, so if you are using
// a free trial subscription key, you should not need to change this region.
var uriBase = "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze";
// Request parameters.
var params = {
"visualFeatures": "Categories,Description,Color",
"details": "",
"language": "en"
};
// Display the image.
var sourceImageUrl = url;
// Perform the REST API call.
$.ajax({
url: uriBase + "?" + $.param(params),
// Request headers.
beforeSend: function(xhrObj) {
xhrObj.setRequestHeader("Content-Type", "application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
},
type: "POST",
// Request body.
data: '{"url": ' + '"' + sourceImageUrl + '"}'
})
.done(function(data) {
// Show formatted JSON on webpage.
var jsonModel = JSON.stringify(data, null, 2);
var description = JSON.parse(jsonModel);
view.byId("output").setText(description.description.captions[0].text);
view.byId("dispImage").setSrc(view.byId("imgInput").getValue());
if (JSON.stringify(description).indexOf("celebrities") > -1) {
view.byId("celebrity").setText("Celebrity: " + description.categories[0].detail.celebrities[0].name);
}
if (JSON.stringify(description).indexOf("landmarks") > -1) {
view.byId("landmark").setText("LandMark: " + description.categories[0].detail.landmarks[0].name);
}
})
.fail(function(jqXHR, textStatus, errorThrown) {
// Display error message.
var errorString = (errorThrown === "") ? "Error. " : errorThrown + " (" + jqXHR.status + "): ";
errorString += (jqXHR.responseText === "") ? "" : jQuery.parseJSON(jqXHR.responseText).message;
alert(errorString);
});
}
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |