Skip to content

Commit

Permalink
1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxmffg committed Jun 5, 2023
1 parent 6913786 commit fd7de47
Show file tree
Hide file tree
Showing 13 changed files with 966 additions and 827 deletions.
117 changes: 87 additions & 30 deletions Redream/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,73 @@ class AutomaticJsonGetModels
public string filename = "";
public string config = "";
}

public static async Task API_RefreshModels(string IP)
public static async Task AutomaticInterrupt(string URI)
{

var client = new HttpClient();
var content = new System.Net.Http.StringContent("", Encoding.UTF8, "application/json");
var request = new HttpRequestMessage


try
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/refresh-checkpoints"),
Method = HttpMethod.Get,
Content = content
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + URI + "/sdapi/v1/interrupt"),
Method = HttpMethod.Post,
Content = content
};
var response = await client.SendAsync(request);
}
catch { }

}

class AutomaticInterrogateStruct
{
public string image = "";
public string model = "clip";
}

public static async Task<string> AutomaticInterrogate(string URI, Bitmap image )
{
string base64Image = "data:image/png;base64," + Convert.ToBase64String(ImageToBytes(image));
var struc = new AutomaticInterrogateStruct
{
image = base64Image
};

try
{
string json = JsonConvert.SerializeObject(struc);
var client = new HttpClient();
var content = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json");
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + URI + "/sdapi/v1/interrogate"),
Method = HttpMethod.Post,
Content = content
};
var response = await client.SendAsync(request);
dynamic responseD = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
return responseD.caption.ToString();
}
catch { return null; }
}

public static async Task API_RefreshModels(string IP)
{
var client = new HttpClient();
var content = new System.Net.Http.StringContent("", Encoding.UTF8, "application/json");


try
{
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/refresh-checkpoints"),
Method = HttpMethod.Get,
Content = content
};
var response = await client.SendAsync(request);
}
catch { }
Expand All @@ -42,15 +95,16 @@ public static async Task<JArray> API_GetModels(string IP)
{
var client = new HttpClient();
var content = new System.Net.Http.StringContent("", Encoding.UTF8, "application/json");
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/sd-models"),
Method = HttpMethod.Get,
Content = content
};

try
{
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/sd-models"),
Method = HttpMethod.Get,
Content = content
};

var response = await client.SendAsync(request);
var jsonRaw = await response.Content.ReadAsStringAsync();
var jArray = JsonConvert.DeserializeObject<JArray>(jsonRaw);
Expand All @@ -62,15 +116,16 @@ public static async Task<string> API_GetCurrentModel(string IP)
{
var client = new HttpClient();
var content = new System.Net.Http.StringContent("", Encoding.UTF8, "application/json");
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/options"),
Method = HttpMethod.Get,
Content = content
};


try
{
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/options"),
Method = HttpMethod.Get,
Content = content
};
var response = await client.SendAsync(request);
var jsonRaw = await response.Content.ReadAsStringAsync();

Expand All @@ -97,14 +152,15 @@ public static async Task API_SetModel(string IP, string model)

var client = new HttpClient();
var content = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json");
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/options"),
Method = HttpMethod.Post,
Content = content
};

try
{
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/sdapi/v1/options"),
Method = HttpMethod.Post,
Content = content
};
var response = await client.SendAsync(request);
}
catch { }
Expand All @@ -115,15 +171,16 @@ public static async Task<string[]> Get_ControlNet_ModelList(string IP)
{
var client = new HttpClient();
var content = new System.Net.Http.StringContent("", Encoding.UTF8, "application/json");
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/controlnet/model_list"),
Method = HttpMethod.Get,
Content = content
};


try
{
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://" + IP + "/controlnet/model_list"),
Method = HttpMethod.Get,
Content = content
};
var response = await client.SendAsync(request);

var json = await response.Content.ReadAsStringAsync();
Expand Down
Loading

0 comments on commit fd7de47

Please sign in to comment.