How would i load a png into a sprite on runtime

I have a editor script triggering this part of code

for (int i = 0; i < 4; i++)
            {
                string regular = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-iii/firered-leafgreen/" + pokemonId.ToString() + ".png";
                string back = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-iii/firered-leafgreen/back/" + pokemonId.ToString() + ".png";
                string regularShiny = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-iii/firered-leafgreen/shiny/" + pokemonId.ToString() + ".png";
                string backShiny = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/versions/generation-iii/firered-leafgreen/back/shiny/" + pokemonId.ToString() + ".png";
                string spriteUrl = string.Empty;
                if (i == 0)
                {
                    spriteUrl = regular;
                }
                else if (i == 1)
                {
                    spriteUrl = back;
                }
                else if (i == 2)
                {
                    spriteUrl = regularShiny;
                }
                else if (i == 3)
                {
                    spriteUrl = backShiny;
                }
                UnityWebRequest www = UnityWebRequestTexture.GetTexture(spriteUrl);
                string frontShinyPath = "Assets/Resources/Art/Pokemons/FrontShiny/" + ConversionStuff.CapFirstLetter(pokemonData.name) + ".png";
                string backShinyPath = "Assets/Resources/Art/Pokemons/BackShiny/" + ConversionStuff.CapFirstLetter(pokemonData.name) + ".png";
                string frontPath = "Assets/Resources/Art/Pokemons/Front/" + ConversionStuff.CapFirstLetter(pokemonData.name) + ".png";
                string backPath = "Assets/Resources/Art/Pokemons/Back/" + ConversionStuff.CapFirstLetter(pokemonData.name) + ".png";

                // Send the request and wait for it to complete
                yield return www.SendWebRequest();

                if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
                {
                    Debug.LogError(www.error);
                }
                else
                {
                    // Retrieve the image from the response and set it as the sprite image's texture
                    Texture2D texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
                    texture.filterMode = FilterMode.Point;
                    byte[] pngData = texture.EncodeToPNG();
                    if (i == 0)
                    {
                        File.WriteAllBytes(frontPath, pngData);
                        newPokemon.frontSprite = (Sprite)Resources.Load(frontPath, typeof(Sprite));
                    }
                    else if (i == 1)
                    {
                        File.WriteAllBytes(backPath, pngData);
                        newPokemon.backSprite = (Sprite)Resources.Load(backPath, typeof(Sprite));
                    }
                    else if (i == 2)
                    {
                        File.WriteAllBytes(frontShinyPath, pngData);
                        newPokemon.frontShinySprite = (Sprite)Resources.Load(frontShinyPath, typeof(Sprite));
                    }
                    else if (i == 3)
                    {
                        File.WriteAllBytes(backShinyPath, pngData);
                        newPokemon.backShinySprite = (Sprite)Resources.Load(backShinyPath, typeof(Sprite));
                    }
                }
            }

where it’s getting a pokemon sprite from pokeapi and saving it, which is working. The problem is when i try and load that png into a sprite going into a scriptableobject, it just doesn’t return anything. I’ve tried just putting in the texture itself, but it doesn’t work. How would i fix this?

With something like this:

 private Sprite LoadSprite(string path)
    {
        if (string.IsNullOrEmpty(path)) return null;
        if (System.IO.File.Exists(path))
        {
            var sprite_width, sprite_height = 100f;
            byte[] bytes = System.IO.File.ReadAllBytes(path);
            Texture2D texture = new Texture2D(sprite_width, sprite_height, TextureFormat.RGB24, false);
            texture.LoadImage(bytes);
            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            return sprite;
        }
        return null;
    }