Exemple #1
0
        public async Task <IActionResult> DescriptionAndHashTags(IFormFile file)
        {
            var tempPhotoPath = string.Empty;

            if (!file.ContentType.StartsWith("image/"))
            {
                return(BadRequestJsonResult(JsonResponse.ErrorResponse("Uploaded file must be an image.")));
            }

            try
            {
                tempPhotoPath = await _fileService.SaveAsync(file, _tempPhotosAddress);

                var prediction  = (await _photoProcessingService.ComputePredictionsAsync(tempPhotoPath)).ToArray();
                var description = await _photoService.ComputeDescriptionAsync(prediction);

                var hashTags = await _photoService.ComputeHashTagsAsync(prediction);

                var response = new { description, hashTags = $"#{string.Join("#", hashTags)}" };

                return(OkJsonResult(JsonResponse.SuccessResponse(response)));
            }
            catch (Exception exception)
            {
                _appLogger.LogError(exception);
                return(InternalServerErrorJsonResult(JsonResponse.ErrorResponse(GenericErrorMessage)));
            }
            finally
            {
                await _fileService.DeleteAsync(tempPhotoPath);
            }
        }