You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If anyone is having trouble to get this to work with the API, here is the json that worked for me :
{
"prompt": "<PROMPT>", // Your prompt here"steps": 20,
"model": "dreamshaper_8", // Your model here"script_name": "ABG Remover",
"script_args": [
true,
false,
"",
"FFFFFF",
false
]
}
Complete example (C#) :
usingSystem.Text;usingSystem.Text.Json;namespaceADG_ImageGenerator;publicinterfaceIImageGenerator{publicTask<string?>GenerateImage(stringprompt);}publicclassImageGenerator:IImageGenerator{privateconststringApiUrl="http://127.0.0.1:7860";privateconststringText2ImageEndpoint="/sdapi/v1/txt2img";/// <summary>/// Generates an image from the given prompt using the API./// </summary>/// <param name="prompt">The prompt to generate the image</param>/// <returns>The base64 image string</returns>publicasyncTask<string?>GenerateImage(stringprompt){using(varclient=newHttpClient()){try{varrequestJson=""" { "prompt": "<PROMPT>", "steps": 20, "model": "dreamshaper_8", "script_name": "ABG Remover", "script_args": [ true, false, "", "FFFFFF", false ] } """;requestJson=requestJson.Replace("<PROMPT>",prompt);varjsonContent=newStringContent(requestJson,Encoding.UTF8,"application/json");varresponse=awaitclient.PostAsync($"{ApiUrl}{Text2ImageEndpoint}",jsonContent);if(response.IsSuccessStatusCode){varresponseBody=awaitresponse.Content.ReadAsStringAsync();// Assuming response contains base64 image string under "image" keyvarjsonResponse=JsonDocument.Parse(responseBody);if(jsonResponse.RootElement.TryGetProperty("images",outvarimageProperty)){// Extract the first image from the array of imagesvarbase64Image=imageProperty[0].GetString();returnbase64Image;}Console.WriteLine("Image not found in the response.");}else{Console.WriteLine($"API call failed with status code: {response.StatusCode}");}}catch(Exceptionex){Console.WriteLine($"Exception occurred: {ex.Message}");}}returnnull;}}
Maybe we could include the json somewhere in the documentation?
Thank you
The text was updated successfully, but these errors were encountered:
If anyone is having trouble to get this to work with the API, here is the json that worked for me :
Complete example (C#) :
Maybe we could include the json somewhere in the documentation?
Thank you
The text was updated successfully, but these errors were encountered: