Skip to content

Commit

Permalink
- Ver104 Support latest version of Automatic1111
Browse files Browse the repository at this point in the history
  • Loading branch information
Invary authored and Invary committed Oct 31, 2022
1 parent 97e2b7a commit 3f6eeb9
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 59 deletions.
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# IvyPhotoshopDiffusion for Windows


# Attention
latest version of AUTOMATIC1111 cannot work,This is due to a change in the API specification.<br />
use old version of AUTOMATIC1111<br />
this version is work<br />
https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/9ceef81f77ecce89f0c8f412c4d849210d852e82
## Attention
Recently, Automatic1111 has been changing its API specification at the level of once every few days. <br />
As a result, there are times when an error occurs and the system does not work. <br />
In this case, please use the version of Automatic1111 that is a few days old. <br />

<br />


## About
IvyPhotoshopDiffusion is a tool for generating AI image on Photoshop for Windows.
The AI generating image process is done by [Stable Diffusion](https://github.com/CompVis/stable-diffusion) and [Automatic1111 Stable Diffusion web UI](https://github.com/AUTOMATIC1111/stable-diffusion-webui).
Expand Down Expand Up @@ -46,12 +46,6 @@ latest version of [IvyPhotoshopDiffusion](https://github.com/Invary/IvyPhotoshop

## Install

# Attention
latest version of AUTOMATIC1111 cannot work,This is due to a change in the API specification.<br />
use old version of AUTOMATIC1111<br />
this version is work<br />
https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/9ceef81f77ecce89f0c8f412c4d849210d852e82

1. [Download](https://github.com/AUTOMATIC1111/stable-diffusion-webui) latest version of **`Automatic1111 Stable Diffusion web UI (Automatic1111)`**
2. Install **`Automatic1111`** to the installation folder.
3. Check generate images on **`Automatic1111`**
Expand Down Expand Up @@ -87,11 +81,21 @@ see [Documents](https://github.com/Invary/IvyPhotoshopDiffusion/tree/main/doc) p

## Changelog

- 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


- Ver103 <br />
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


- Ver102 <br />
Support text2image. Use generate button with pressing [shift] key <br />
Expand Down
180 changes: 144 additions & 36 deletions src/IvyPhotoshopDiffusion/Automatic1111.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Invary.IvyPhotoshopDiffusion
Expand Down Expand Up @@ -71,7 +72,9 @@ public static JsonResponseTxt2Img SendTxt2Img(JsonRequestTxt2Img objJson)
string jsonresponse = reader.ReadToEnd();
//Debug.WriteLine(data);

return JsonSerializer.Deserialize<JsonResponseTxt2Img>(jsonresponse);
var ret = JsonSerializer.Deserialize<JsonResponseTxt2Img>(jsonresponse);
ret.Info = JsonSerializer.Deserialize<JsonResponseInfo>(ret.info);
return ret;
}
}
}
Expand Down Expand Up @@ -104,11 +107,11 @@ public static JsonResponseImg2Img SendImg2Img(JsonRequestImg2Img objJson)
using (var respStream = response.GetResponseStream())
using (var reader = new StreamReader(respStream))
{

string jsonresponse = reader.ReadToEnd();
//Debug.WriteLine(data);

return JsonSerializer.Deserialize<JsonResponseImg2Img>(jsonresponse);
var ret = JsonSerializer.Deserialize<JsonResponseImg2Img>(jsonresponse);
ret.Info = JsonSerializer.Deserialize<JsonResponseInfo>(ret.info);
return ret;
}
}
}
Expand All @@ -130,7 +133,8 @@ public static string Image2String(Image image)
var rawdata = new byte[ms.Length];
ms.Read(rawdata, 0, rawdata.Length);

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

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

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

using (FileStream fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
Expand Down Expand Up @@ -237,13 +242,81 @@ public class JsonRequestImg2Img : JsonRequestBase
















public class JsonResponseBase
{
public string[] images { get; set; }
public Info info { get; set; }
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
{
Expand Down Expand Up @@ -293,36 +366,36 @@ 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; }
}
//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 @@ -366,6 +439,41 @@ public class Extra_Generation_Params



public class JsonResponseInfo
{
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; }
}







}
33 changes: 22 additions & 11 deletions src/IvyPhotoshopDiffusion/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ private void buttonGenerate_Click(object sender, EventArgs e)
}

var responseObj = Automatic1111.Send(request);
int index = 0;
foreach (var encodedimg in responseObj.images)
{
if (_bAbort)
Expand All @@ -450,23 +451,33 @@ private void buttonGenerate_Click(object sender, EventArgs e)
var name = strLayerNameTemplate;
//"@seed, @prompt, @negative, @cfg, @steps, @clip, @strength, @sampler, @subseed, @subseedstrength";
name = name.Replace(@"@date", $"{DateTime.Now.ToString("yyyyMMdd_HHmmss")}");
name = name.Replace(@"@seed", $"{responseObj.info.seed}");
name = name.Replace(@"@prompt", $"{responseObj.info.prompt}");
name = name.Replace(@"@negative", $"{responseObj.info.negative_prompt}");
name = name.Replace(@"@cfg", $"{responseObj.info.cfg_scale}");
name = name.Replace(@"@steps", $"{responseObj.info.steps}");
name = name.Replace(@"@clip", $"{responseObj.info.clip_skip}");
name = name.Replace(@"@strength", $"{responseObj.info.denoising_strength}");
name = name.Replace(@"@sampler", $"{responseObj.info.sampler}");
name = name.Replace(@"@subseedstrength", $"{responseObj.info.subseed_strength}");
name = name.Replace(@"@subseed", $"{responseObj.info.subseed}");

ParametersBase param = null;
if (responseObj.GetType() == typeof(JsonResponseImg2Img))
param = (responseObj as JsonResponseImg2Img).parameters;
else if (responseObj.GetType() == typeof(JsonResponseTxt2Img))
param = (responseObj as JsonResponseTxt2Img).parameters;
if (param != null)
{
name = name.Replace(@"@seed", $"{responseObj.Info.all_seeds[index]}");
name = name.Replace(@"@prompt", $"{param.prompt}");
name = name.Replace(@"@negative", $"{param.negative_prompt}");
name = name.Replace(@"@cfg", $"{param.cfg_scale}");
name = name.Replace(@"@steps", $"{param.steps}");
name = name.Replace(@"@strength", $"{param.denoising_strength}");
name = name.Replace(@"@sampler", $"{param.sampler_index}");
name = name.Replace(@"@subseedstrength", $"{param.subseed_strength}");
name = name.Replace(@"@subseed", $"{responseObj.Info.all_subseeds[index]}");
name = name.Replace(@"@clip", $"{responseObj.Info.clip_skip}");
}
appRef.ActiveDocument.ActiveLayer.name = name;
LogMessage.WriteLine($"layer: {name}");
}

Photoshop.SetSelection(appRef, curSelection);
index++;
}
foreach (var item in responseObj.info.infotexts)
foreach (var item in responseObj.Info.infotexts)
{
LogMessage.WriteLine(item);
}
Expand Down
2 changes: 1 addition & 1 deletion src/IvyPhotoshopDiffusion/XmlSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class XmlSetting


[XmlIgnore]
public static int nVersion { get; } = 103;
public static int nVersion { get; } = 104;

[XmlIgnore]
public static string strVersion { get; } = $"Ver{nVersion}";
Expand Down

0 comments on commit 3f6eeb9

Please sign in to comment.