Stability-AI / api-interfaces

Interface definitions for API interactions between components
140 stars 78 forks source link

Difference in the Images generated by UI and RestAPI #78

Closed HasnainKhanNiazi closed 1 year ago

HasnainKhanNiazi commented 1 year ago

hey guys, I am using the stable diffusion within C# and I have replicated the curl command within C# and it's working good but I am not satisfied with the generated image,

string new_text = "A fox in the jungle, low poly";
var request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.stability.ai/v1/generation/stable-diffusion-v1-5/text-to-image"),
            Headers =
            {
                { "Accept", "image/png" },
                { "Authorization", "API_KEY" },
                { "Cookie", "__cf_bm=FMRRcWzshoDLeugLIOuR49M55SurpuyHsp1trp5ooPk-1681039461-0-AXhrLXucsQywuiiyfV1/YKGADKSRzWJ6g5vbIozpe0xTpWYaYqM0eG2Nv778H6EuxdZqbHj0fPVUOdsrxxRIHqY=" }
            },
            Content = new StringContent($@"{{
            ""text_prompts"": [
                {{
                    ""text"": ""{new_text}""
                }}
            ],
            ""cfg_scale"": 8,
            ""height"": 512,
            ""width"": 512,
            ""samples"": 1,
            ""generation.sampler"": ""SAMPLER_K_DPMPP_2M"",
            ""steps"": 50,
            ""engine"": ""stable-diffusion-xl-beta-v2-2-2""
        }}", Encoding.UTF8, "application/json")
        };

And the generated image looks like this;

235674738-84a730ae-3955-49c4-8bd1-05c132a4b5a5

Now, I have also used the DreamStudio UI to generate the image with the same prompt and the parameters and the result looks much better, you can see the result below, what could be wrong in the above code.

4045498837_There is a fox in the jungle_xl-beta-v2-2-2

HasnainKhanNiazi commented 1 year ago

We solved the issue, the endpoint needs to be changed like this, "https://api.stability.ai/v1/generation/stable-diffusion-xl-beta-v2-2-2/text-to-imag"