Added A Little AI to My Prototype

Since the app can take pictures and share them within their respective lists I thought it would be best to ensure no nefarious picture sharing was going on. So I added Azure’s Cognitive ComputerVision AI service to my app to scan for Adult Images and the like and stop them from being uploaded or shared.

It was pretty easy, here is the Gist:

try
{
var connectionString = AppSettings.VisionEndPoint;
var visionKey = AppSettings.VisionKey;
List<VisualFeatureTypes?> features = new List<VisualFeatureTypes?>()
{
VisualFeatureTypes.Categories, VisualFeatureTypes.Description,
VisualFeatureTypes.Faces, VisualFeatureTypes.ImageType,
VisualFeatureTypes.Tags, VisualFeatureTypes.Adult,
VisualFeatureTypes.Color, VisualFeatureTypes.Brands,
VisualFeatureTypes.Objects
};
ComputerVisionClient computerVisionClient = new ComputerVisionClient(
new ApiKeyServiceClientCredentials(visionKey),
new DelegatingHandler[] { }
)
{
Endpoint = connectionString
};
using var myStream2 = File.OpenRead(PhotoPath);
using (var fs = myStream2)
{
ImageAnalysis result = computerVisionClient.AnalyzeImageInStreamAsync(image: fs, features)
.Result;
Debug.WriteLine(result.Adult.IsAdultContent + " :: " + result.Adult.IsRacyContent + " :: " + result.Adult.IsGoryContent);
{
if (result.Adult.IsAdultContent || result.Adult.IsRacyContent ||
result.Adult.IsGoryContent)
{
DependencyService.Get<iToast>().Show("Adult Content Is Not Allowed!");
donotrun = true;
}
}
myStream2.Close();
}
if (!donotrun)
{
using var myStream = File.OpenRead(PhotoPath);
await blobClient.UploadAsync(myStream);
myStream.Close();
}
}
catch (RequestFailedException e)
{
Crashes.TrackError(e);
Debug.WriteLine("Something Occurred: " + e.Status);
}

John


Discover more from Spindlecrank.com

Subscribe to get the latest posts sent to your email.

Leave a Reply