Skip to content

Commit

Permalink
Ver105
Browse files Browse the repository at this point in the history
Support restore faces, tiling, ENSD, clip skip<br />
Set/get photoshop forground/background color <br />
Bug fix json request/response <br />
Ver105 work for Automatic1111 2022/11/01 03:00 UTC version<br />
https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/5c9b3625fa03f18649e1843b5e9f2df2d4de94f9
  • Loading branch information
Invary authored and Invary committed Nov 1, 2022
1 parent 3f6eeb9 commit b03f0d8
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 97 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ see [Documents](https://github.com/Invary/IvyPhotoshopDiffusion/tree/main/doc) p

## Changelog

- Ver105 <br />
Support restore faces, tiling, ENSD, clip skip<br />
Set/get photoshop forground/background color <br />
Bug fix json request/response <br />
Ver105 work for Automatic1111 2022/11/01 03:00 UTC version<br />
https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/5c9b3625fa03f18649e1843b5e9f2df2d4de94f9

- Ver104 <br />
Support latest version of Automatic1111's API <br />

Ver104 work for Automatic1111 2022/10/31 06:00 UTC version<br />
https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/17a2076f72562b428052ee3fc8c43d19c03ecd1e

Expand All @@ -92,7 +98,6 @@ https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/17a2076f72562b42805
Save last prompt/negative/layername setting for default value <br />
Add setting layer name function <br />
Bug fix image processing exception <br />

Ver103 work for Automatic1111 2022/10/28 version<br />
https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/9ceef81f77ecce89f0c8f412c4d849210d852e82

Expand Down
213 changes: 122 additions & 91 deletions src/IvyPhotoshopDiffusion/Automatic1111.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ namespace Invary.IvyPhotoshopDiffusion
// https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API


//progress api
//
//https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/3722
//
//Call /sdapi/v1/txt2img like this:
//{
// override_settings: { show_progress_every_n_steps: 5 },
//}
//And /sdapi/v1/progress will respond with a valid current_image field.




internal class Automatic1111
{
Expand Down Expand Up @@ -120,6 +132,57 @@ public static JsonResponseImg2Img SendImg2Img(JsonRequestImg2Img objJson)



//extra check code
//{
// JsonRequestExtra objJson = new JsonRequestExtra();
// objJson.image = Automatic1111.Image2String(new Bitmap(512, 512));
// Automatic1111.SendExtra(objJson);
//}


////TODO: current version of Automatic1111, extra api cannot work??
//public static JsonResponseImg2Img SendExtra(JsonRequestExtra objJson)
//{
// string jsonString = JsonSerializer.Serialize(objJson);

// var url = $"{XmlSetting.Current.Automatic1111ApiUrl}/sdapi/v1/extra-single-image";

// var request = WebRequest.Create(url);
// request.Method = "POST";

// string json = jsonString;
// byte[] byteArray = Encoding.UTF8.GetBytes(json);

// request.ContentType = "application/json";
// request.ContentLength = byteArray.Length;

// using (var reqStream = request.GetRequestStream())
// {
// reqStream.Write(byteArray, 0, byteArray.Length);

// using (var response = request.GetResponse())
// {
// Debug.WriteLine(((HttpWebResponse)response).StatusDescription);

// using (var respStream = response.GetResponseStream())
// using (var reader = new StreamReader(respStream))
// {
// string jsonresponse = reader.ReadToEnd();

// //TODO: response json is unknown
// Debug.Assert(false);
// var ret = JsonSerializer.Deserialize<JsonResponseImg2Img>(jsonresponse);
// ret.Info = JsonSerializer.Deserialize<JsonResponseInfo>(ret.info);
// return ret;
// }
// }
// }
//}





public static string Image2String(Image image)
{
if (image == null)
Expand All @@ -134,7 +197,6 @@ public static string Image2String(Image image)
ms.Read(rawdata, 0, rawdata.Length);

return "data:image/png;base64," + Convert.ToBase64String(rawdata);
//return Convert.ToBase64String(rawdata);
}
}

Expand All @@ -143,6 +205,7 @@ public static string Image2String(Image image)

public static bool SaveBase64EncodingData(string file, string text)
{
//TODO: fixed image type
text = text.Replace("data:image/png;base64,", "");
var rawdata = Convert.FromBase64String(text);

Expand All @@ -169,6 +232,7 @@ public class JsonRequestBase
public float denoising_strength { get; set; } = 0.75f;

public decimal seed { get; set; } = -1;

public decimal subseed { get; set; } = -1;
public float subseed_strength { get; set; } = 0.0f;
public int seed_resize_from_h { get; set; } = -1;
Expand All @@ -187,12 +251,27 @@ public class JsonRequestBase

public string negative_prompt { get; set; } = "";

public int eta { get; set; } = 0;
public float eta { get; set; } = 0;

/// <summary>
/// Sigma Churn
/// </summary>
public float s_churn { get; set; } = 0;

/// <summary>
/// Sigma max
/// </summary>
public float s_tmax { get; set; } = 0;

/// <summary>
/// Sigma min
/// </summary>
public float s_tmin { get; set; } = 0;

public int s_churn { get; set; } = 0;
public int s_tmax { get; set; } = 0;
public int s_tmin { get; set; } = 0;
public int s_noise { get; set; } = 1;
/// <summary>
/// Sigma noise
/// </summary>
public float s_noise { get; set; } = 1;

public Override_Settings override_settings { get; set; }

Expand All @@ -203,6 +282,8 @@ public class JsonRequestBase

public class Override_Settings
{
public int eta_noise_seed_delta { get; set; } = 0;
public int CLIP_stop_at_last_layers { get; set; } = 1;
}


Expand Down Expand Up @@ -258,66 +339,20 @@ public class JsonRequestImg2Img : JsonRequestBase
public class JsonResponseBase
{
public string[] images { get; set; }

//automatic1111's bug. response is json text, not object. so need to deserialize this
public string info { get; set; }

[JsonIgnore]
public JsonResponseInfo Info { get; set; }
}


//public class Parameters
//{
// public bool enable_hr { get; set; }
// public float denoising_strength { get; set; }
// public int firstphase_width { get; set; }
// public int firstphase_height { get; set; }
// public string prompt { get; set; }
// public object styles { get; set; }
// public int seed { get; set; }
// public int subseed { get; set; }
// public float subseed_strength { get; set; }
// public int seed_resize_from_h { get; set; }
// public int seed_resize_from_w { get; set; }
// public int batch_size { get; set; }
// public int n_iter { get; set; }
// public int steps { get; set; }
// public float cfg_scale { get; set; }
// public int width { get; set; }
// public int height { get; set; }
// public bool restore_faces { get; set; }
// public bool tiling { get; set; }
// public string negative_prompt { get; set; }
// public float eta { get; set; }
// public float s_churn { get; set; }
// public float s_tmax { get; set; }
// public float s_tmin { get; set; }
// public float s_noise { get; set; }
// public object override_settings { get; set; }
// public string sampler_index { get; set; }
//}















//public class JsonResponseBase
//{
// public string[] images { get; set; }
// public Info info { get; set; }
//}



public class JsonResponseTxt2Img : JsonResponseBase
{
public ParametersTxt2Img parameters { get; set; }
Expand Down Expand Up @@ -347,12 +382,12 @@ public class ParametersBase
public bool restore_faces { get; set; }
public bool tiling { get; set; }
public string negative_prompt { get; set; }
public object eta { get; set; }
public float eta { get; set; }
public float s_churn { get; set; }
public object s_tmax { get; set; }
public float s_tmax { get; set; }
public float s_tmin { get; set; }
public float s_noise { get; set; }
public object override_settings { get; set; }
public Override_Settings override_settings { get; set; }
public string sampler_index { get; set; }
}

Expand All @@ -366,40 +401,6 @@ public class ParametersTxt2Img : ParametersBase
}


//public class Info
//{
// public string prompt { get; set; }
// public string[] all_prompts { get; set; }
// public string negative_prompt { get; set; }
// public decimal seed { get; set; }
// public decimal[] all_seeds { get; set; }
// public decimal subseed { get; set; }
// public decimal[] all_subseeds { get; set; }
// public float subseed_strength { get; set; }
// public int width { get; set; }
// public int height { get; set; }
// public int sampler_index { get; set; }
// public string sampler { get; set; }
// public float cfg_scale { get; set; }
// public int steps { get; set; }
// public int batch_size { get; set; }
// public bool restore_faces { get; set; }
// public object face_restoration_model { get; set; }
// public string sd_model_hash { get; set; }
// public int seed_resize_from_w { get; set; }
// public int seed_resize_from_h { get; set; }
// public float denoising_strength { get; set; }
// public Extra_Generation_Params extra_generation_params { get; set; }
// public int index_of_first_image { get; set; }
// public string[] infotexts { get; set; }
// public object[] styles { get; set; }
// public string job_timestamp { get; set; }
// public int clip_skip { get; set; }
//}







Expand Down Expand Up @@ -476,4 +477,34 @@ public class JsonResponseInfo







//public class JsonRequestExtra
//{
// public bool upscale_first { get; set; } = true;

// public int resize_mode { get; set; } = 0;
// public bool show_extras_results { get; set; } = true;
// public float gfpgan_visibility { get; set; } = 0;
// public float codeformer_visibility { get; set; } = 0;
// public float codeformer_weight { get; set; } = 0;
// public int upscaling_resize { get; set; } = 2;
// public int upscaling_resize_w { get; set; } = 512;
// public int upscaling_resize_h { get; set; } = 512;
// public bool upscaling_crop { get; set; } = true;
// public string upscaler_1 { get; set; } = "None";
// public string upscaler_2 { get; set; } = "None";
// public int extras_upscaler_2_visibility { get; set; } = 0;

// public string image { get; set; }
//}







}
Loading

0 comments on commit b03f0d8

Please sign in to comment.