<mvc:View controllerName="com.sap.mlProductClassificationML.controller.View" xmlns:l="sap.ui.layout" xmlns:mvc="sap.ui.core.mvc"
xmlns:semantic="sap.m.semantic" xmlns:smart="sap.ui.comp.smartfield" xmlns="sap.m" xmlns:u="sap.ui.unified" xmlns:f="sap.ui.layout.form"
xmlns:core="sap.ui.core" class="viewPadding">
<App>
<pages>
<Page id="mainPageId" titleLevel="Auto" title="{i18n>createTitle}">
<content>
<VBox class="sapUiSmallMargin">
<f:SimpleForm id="newEntitySimpleForm" minWidth="1024" maxContainerCols="2" editable="true" layout="ResponsiveGridLayout" labelSpanL="3"
labelSpanM="3" emptySpanL="4" emptySpanM="4" columnsL="1" columnsM="1" class="editableForm">
<f:content>
<Label id="fileNameId" text="Upload Image"/>
<u:FileUploader id="fileUploader" name="FILENAME" placeholder="Upload image to search a product" change="processFile"
sameFilenameAllowed="false" liveChange="onSelectInput" width="350px"/>
</f:content>
</f:SimpleForm>
</VBox>
<FlexBox width="70%" id="__box2" justifyContent="Center">
<items>
<Button visible="true" text="Route to Shopping" enabled="true" press="handleUploadPress" width="200px"/>
</items>
</FlexBox>
</content>
<Table id="idProductsTable" inset="false" items="{ path: '/results', sorter: { path: 'score', descending: 'true' } }">
<headerToolbar>
<Toolbar>
<Title text="Image Classification Probablities" level="H2"/>
</Toolbar>
</headerToolbar>
<columns>
<Column >
<Text text="Label"/>
</Column>
<Column >
<Text text="Score"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectIdentifier title="{label}"/>
<Text text="{score}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</Page>
</pages>
</App>
</mvc:View>
var data = new FormData();
//add a 'files' key inside a FormData object
data.append('files', file, filename);
handleUploadPress: function(oEvent) {
var oFileUploader = this.getView().byId("fileUploader");
if (!oFileUploader.getValue()) {
MessageToast.show("Choose a file first");
return;
}
var that = this;
var f = document.querySelector('input[type="file"]').files[0];
//Create form object and append file to the same
var data = new FormData();
data.append('files', document.getElementById("__xmlview0--fileUploader-fu").files[0], document.getElementById(
"__xmlview0--fileUploader-fu").files[0].name);
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
var vjson = JSON.parse(this.responseText);
//set the model for the UI5 table to populate product classification results
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(vjson.predictions[0]);
that.getView().setModel(oModel);
var label = vjson.predictions[0].results[0].label;
var score = vjson.predictions[0].results[0].score;
}
});
xhr.open("POST", "https://sandbox.api.sap.com/ml/prodimgclassifier/inference_sync");
xhr.setRequestHeader("apikey", "xxxxxxxxxxxxxxxxxxx");
xhr.setRequestHeader("accept", "application/json");
xhr.send(data);
}
var label = vjson.predictions[0].results[0].label;
var score = vjson.predictions[0].results[0].score;
sap.m.URLHelper.redirect("http://www.site.com/search?Ntt="+ vjson.predictions[0].results[0].label +"&N=", true);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 |