Created
July 20, 2020 18:30
-
-
Save northwestcoder/ab9eb9f82b3b0ffd401b3d1b8cc8de60 to your computer and use it in GitHub Desktop.
googlevisionml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onChange(e) { | |
var sSht = e.source; | |
var sht = sSht.getActiveSheet(); | |
var shtName = sht.getName(); | |
var activeRng = sht.getActiveRange(); | |
var activeRow = activeRng.getRow(); | |
var image = sht.getRange(activeRow,4).getValue(); | |
var folder = DriveApp.getFolderById("APPSHEET FOLDER ID WHERE IMAGES WERE UPLOADED"); | |
var blob = folder.getFilesByName(image.split("/")[1]).next().getBlob(); | |
var mlRequest = {payload: { | |
image: { | |
imageBytes: Utilities.base64Encode(blob.getBytes()) | |
} | |
} | |
} | |
var mlUrl = "https://YOURAPIGEEORGNAME.apigee.net/ml-use?apikey=YOURAPIGEEAPIKEY"; | |
var responseML = UrlFetchApp.fetch(mlUrl, { | |
method : 'POST', | |
contentType: 'application/json', | |
payload : JSON.stringify(mlRequest) | |
}); | |
var mlPayload = responseML.getContentText(); | |
var pparsed = JSON.parse(mlPayload); | |
var result = pparsed.payload[0].displayName; | |
sht.getRange(activeRow,5).setValue(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment