public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log) { try { log.Info($"Webhook was triggered!"); // Get request body dynamic data = await req.Content.ReadAsAsync <object>(); log.Info(data.ToString()); // Get image url string imagePath = data.path; string imageUrl = $"https://{ConfigurationManager.AppSettings["StorageAccountName"]}.blob.core.windows.net{imagePath}"; log.Info(imageUrl); // Get image prediction results var predictionResult = await ImagePredictor.PredictImageUrl(imageUrl); // Validate image bool objectFound = ImagePredictor.ValidateImagePrediction(predictionResult); Models.Output output = new Models.Output() { ObjectFound = objectFound, ImageUrl = imageUrl, }; return(req.CreateResponse(HttpStatusCode.OK, output)); } catch (Exception e) { throw e; } }
public static async Task <object> Run([HttpTrigger(WebHookType = "genericJson")] HttpRequestMessage req, TraceWriter log) { try { log.Info($"Webhook was triggered!"); // Get request body dynamic data = await req.Content.ReadAsAsync <object>(); // Complete image url string imagePath = data.path; string imageUrl = $"https://{ConfigurationManager.AppSettings["ImagesStorageAccountName"]}.blob.core.windows.net{imagePath}"; log.Info(imageUrl); // evaluate image bool objectFound = await ObjectFound(imageUrl); log.Info($"object found? {objectFound}"); // Track event on Application Insights string instrumentationKey = ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"]; if (!string.IsNullOrEmpty(instrumentationKey)) { log.Info("Tracking event to Application Insights"); TelemetryClient _telemetryClient = new TelemetryClient( new Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration(instrumentationKey)); if (objectFound) { _telemetryClient.TrackEvent("Object"); } else { _telemetryClient.TrackEvent("Oean"); } } // Create output object Models.Output output = new Models.Output() { ObjectFound = objectFound, ImageUrl = imageUrl, }; // return result return(req.CreateResponse(HttpStatusCode.OK, output)); } catch (Exception e) { throw e; } }