public static async Task <IActionResult> RunByGenre(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var     requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  lyrics      = data?.lyrics;
            string  genreName   = data?.genre;
            string  warmup      = data?.warmup;

            // Can call function to warm it up
            if (!string.IsNullOrEmpty(warmup))
            {
                log.LogInformation($"Warmup called");
                return(new OkObjectResult("OK"));
            }

            var result = new GenreResult();

            try
            {
                if (!string.IsNullOrWhiteSpace(lyrics) && !string.IsNullOrWhiteSpace(genreName) && Enum.TryParse(genreName, true, out Genre genre))
                {
                    result = await GenreClassification.GetGenreResult(genre, lyrics, log);

                    return(new JsonResult(result));
                }
            }
            catch (Exception ex)
            {
                log.LogInformation($"Error: {ex.Message}");
            }

            return(new JsonResult(result));
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var     requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);
            string  lyrics      = data?.lyrics;
            string  warmup      = data?.warmup;

            // Can call function to warm it up
            if (!string.IsNullOrEmpty(warmup))
            {
                log.LogInformation($"Warmup called");
                return(new OkObjectResult("OK"));
            }

            var result = new GenreResults();

            try
            {
                if (!string.IsNullOrWhiteSpace(lyrics))
                {
                    // These have enough data to form a prediction
                    var genres = new List <Genre>
                    {
                        Genre.Rock,
                        Genre.Electronic,
                        Genre.Alternative,
                        Genre.Indie,
                        Genre.Pop,
                        Genre.Metal,
                        Genre.Folk,
                        Genre.Punk,
                        Genre.HipHop,
                        Genre.SingerSongWriter,
                        Genre.Dance,
                        Genre.Soul,
                        Genre.Acoustic,
                        Genre.Funk
                    };

                    var bag = new ConcurrentBag <GenreResult>();

                    await genres.ParallelForEachAsync(async genre =>
                    {
                        var genreResult = await GenreClassification.GetGenreResult(genre, lyrics, log);
                        bag.Add(genreResult);
                    });

                    result.Results = bag.OrderByDescending(g => g.Result.Probability).ToList();

                    result.Message = "Success";
                }
                else
                {
                    result.Message = "No lyrics submitted";
                }
            }
            catch (Exception ex)
            {
                log.LogInformation($"Error: {ex.Message}");
                result.Message = ex.Message;
            }

            return(new JsonResult(result));
        }