|
|
@ -9,8 +9,10 @@ using StabilityMatrix.Core.Models.Progress; |
|
|
|
using StabilityMatrix.Core.Processes; |
|
|
|
using StabilityMatrix.Core.Processes; |
|
|
|
using StabilityMatrix.Core.Python; |
|
|
|
using StabilityMatrix.Core.Python; |
|
|
|
using StabilityMatrix.Core.Services; |
|
|
|
using StabilityMatrix.Core.Services; |
|
|
|
|
|
|
|
using YamlDotNet.RepresentationModel; |
|
|
|
using YamlDotNet.Serialization; |
|
|
|
using YamlDotNet.Serialization; |
|
|
|
using YamlDotNet.Serialization.NamingConventions; |
|
|
|
using YamlDotNet.Serialization.NamingConventions; |
|
|
|
|
|
|
|
using YamlDotNet.Serialization.TypeInspectors; |
|
|
|
|
|
|
|
|
|
|
|
namespace StabilityMatrix.Core.Models.Packages; |
|
|
|
namespace StabilityMatrix.Core.Models.Packages; |
|
|
|
|
|
|
|
|
|
|
@ -233,11 +235,6 @@ public class ComfyUI : BaseGitPackage |
|
|
|
var extraPathsYamlPath = installDirectory + "extra_model_paths.yaml"; |
|
|
|
var extraPathsYamlPath = installDirectory + "extra_model_paths.yaml"; |
|
|
|
var modelsDir = SettingsManager.ModelsDirectory; |
|
|
|
var modelsDir = SettingsManager.ModelsDirectory; |
|
|
|
|
|
|
|
|
|
|
|
var deserializer = new DeserializerBuilder() |
|
|
|
|
|
|
|
.WithNamingConvention(UnderscoredNamingConvention.Instance) |
|
|
|
|
|
|
|
.IgnoreUnmatchedProperties() |
|
|
|
|
|
|
|
.Build(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var exists = File.Exists(extraPathsYamlPath); |
|
|
|
var exists = File.Exists(extraPathsYamlPath); |
|
|
|
if (!exists) |
|
|
|
if (!exists) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -245,34 +242,87 @@ public class ComfyUI : BaseGitPackage |
|
|
|
File.WriteAllText(extraPathsYamlPath, string.Empty); |
|
|
|
File.WriteAllText(extraPathsYamlPath, string.Empty); |
|
|
|
} |
|
|
|
} |
|
|
|
var yaml = File.ReadAllText(extraPathsYamlPath); |
|
|
|
var yaml = File.ReadAllText(extraPathsYamlPath); |
|
|
|
var comfyModelPaths = |
|
|
|
using var sr = new StringReader(yaml); |
|
|
|
deserializer.Deserialize<ComfyModelPathsYaml>(yaml) |
|
|
|
var yamlStream = new YamlStream(); |
|
|
|
?? |
|
|
|
yamlStream.Load(sr); |
|
|
|
// ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract |
|
|
|
|
|
|
|
// cuz it can actually be null lol |
|
|
|
if (!yamlStream.Documents.Any()) |
|
|
|
new ComfyModelPathsYaml(); |
|
|
|
{ |
|
|
|
|
|
|
|
yamlStream.Documents.Add(new YamlDocument(new YamlMappingNode())); |
|
|
|
comfyModelPaths.StabilityMatrix ??= new ComfyModelPathsYaml.SmData(); |
|
|
|
} |
|
|
|
comfyModelPaths.StabilityMatrix.Checkpoints = Path.Combine(modelsDir, "StableDiffusion"); |
|
|
|
|
|
|
|
comfyModelPaths.StabilityMatrix.Vae = Path.Combine(modelsDir, "VAE"); |
|
|
|
var root = yamlStream.Documents[0].RootNode; |
|
|
|
comfyModelPaths.StabilityMatrix.Loras = |
|
|
|
if (root is not YamlMappingNode mappingNode) |
|
|
|
$"{Path.Combine(modelsDir, "Lora")}\n" + $"{Path.Combine(modelsDir, "LyCORIS")}"; |
|
|
|
{ |
|
|
|
comfyModelPaths.StabilityMatrix.UpscaleModels = |
|
|
|
throw new Exception("Invalid extra_model_paths.yaml"); |
|
|
|
$"{Path.Combine(modelsDir, "ESRGAN")}\n" |
|
|
|
} |
|
|
|
+ $"{Path.Combine(modelsDir, "RealESRGAN")}\n" |
|
|
|
// check if we have a child called "stability_matrix" |
|
|
|
+ $"{Path.Combine(modelsDir, "SwinIR")}"; |
|
|
|
var stabilityMatrixNode = mappingNode.Children.FirstOrDefault( |
|
|
|
comfyModelPaths.StabilityMatrix.Embeddings = Path.Combine(modelsDir, "TextualInversion"); |
|
|
|
c => c.Key.ToString() == "stability_matrix" |
|
|
|
comfyModelPaths.StabilityMatrix.Hypernetworks = Path.Combine(modelsDir, "Hypernetwork"); |
|
|
|
); |
|
|
|
comfyModelPaths.StabilityMatrix.Controlnet = Path.Combine(modelsDir, "ControlNet"); |
|
|
|
|
|
|
|
comfyModelPaths.StabilityMatrix.Clip = Path.Combine(modelsDir, "CLIP"); |
|
|
|
if (stabilityMatrixNode.Key != null) |
|
|
|
comfyModelPaths.StabilityMatrix.Diffusers = Path.Combine(modelsDir, "Diffusers"); |
|
|
|
{ |
|
|
|
comfyModelPaths.StabilityMatrix.Gligen = Path.Combine(modelsDir, "GLIGEN"); |
|
|
|
if (stabilityMatrixNode.Value is not YamlMappingNode nodeValue) |
|
|
|
comfyModelPaths.StabilityMatrix.VaeApprox = Path.Combine(modelsDir, "ApproxVAE"); |
|
|
|
return Task.CompletedTask; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nodeValue.Children["checkpoints"] = Path.Combine(modelsDir, "StableDiffusion"); |
|
|
|
|
|
|
|
nodeValue.Children["vae"] = Path.Combine(modelsDir, "VAE"); |
|
|
|
|
|
|
|
nodeValue.Children["loras"] = |
|
|
|
|
|
|
|
$"{Path.Combine(modelsDir, "Lora")}\n" + $"{Path.Combine(modelsDir, "LyCORIS")}"; |
|
|
|
|
|
|
|
nodeValue.Children["upscale_models"] = |
|
|
|
|
|
|
|
$"{Path.Combine(modelsDir, "ESRGAN")}\n" |
|
|
|
|
|
|
|
+ $"{Path.Combine(modelsDir, "RealESRGAN")}\n" |
|
|
|
|
|
|
|
+ $"{Path.Combine(modelsDir, "SwinIR")}"; |
|
|
|
|
|
|
|
nodeValue.Children["embeddings"] = Path.Combine(modelsDir, "TextualInversion"); |
|
|
|
|
|
|
|
nodeValue.Children["hypernetworks"] = Path.Combine(modelsDir, "Hypernetwork"); |
|
|
|
|
|
|
|
nodeValue.Children["controlnet"] = Path.Combine(modelsDir, "ControlNet"); |
|
|
|
|
|
|
|
nodeValue.Children["clip"] = Path.Combine(modelsDir, "CLIP"); |
|
|
|
|
|
|
|
nodeValue.Children["diffusers"] = Path.Combine(modelsDir, "Diffusers"); |
|
|
|
|
|
|
|
nodeValue.Children["gligen"] = Path.Combine(modelsDir, "GLIGEN"); |
|
|
|
|
|
|
|
nodeValue.Children["vae_approx"] = Path.Combine(modelsDir, "ApproxVAE"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
stabilityMatrixNode = new KeyValuePair<YamlNode, YamlNode>( |
|
|
|
|
|
|
|
new YamlScalarNode("stability_matrix"), |
|
|
|
|
|
|
|
new YamlMappingNode |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
{ "checkpoints", Path.Combine(modelsDir, "StableDiffusion") }, |
|
|
|
|
|
|
|
{ "vae", Path.Combine(modelsDir, "VAE") }, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"loras", |
|
|
|
|
|
|
|
$"{Path.Combine(modelsDir, "Lora")}\n{Path.Combine(modelsDir, "LyCORIS")}" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"upscale_models", |
|
|
|
|
|
|
|
$"{Path.Combine(modelsDir, "ESRGAN")}\n{Path.Combine(modelsDir, "RealESRGAN")}\n{Path.Combine(modelsDir, "SwinIR")}" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ "embeddings", Path.Combine(modelsDir, "TextualInversion") }, |
|
|
|
|
|
|
|
{ "hypernetworks", Path.Combine(modelsDir, "Hypernetwork") }, |
|
|
|
|
|
|
|
{ "controlnet", Path.Combine(modelsDir, "ControlNet") }, |
|
|
|
|
|
|
|
{ "clip", Path.Combine(modelsDir, "CLIP") }, |
|
|
|
|
|
|
|
{ "diffusers", Path.Combine(modelsDir, "Diffusers") }, |
|
|
|
|
|
|
|
{ "gligen", Path.Combine(modelsDir, "GLIGEN") }, |
|
|
|
|
|
|
|
{ "vae_approx", Path.Combine(modelsDir, "ApproxVAE") } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newRootNode = new YamlMappingNode(); |
|
|
|
|
|
|
|
foreach ( |
|
|
|
|
|
|
|
var child in mappingNode.Children.Where(c => c.Key.ToString() != "stability_matrix") |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
newRootNode.Children.Add(child); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newRootNode.Children.Add(stabilityMatrixNode); |
|
|
|
|
|
|
|
|
|
|
|
var serializer = new SerializerBuilder() |
|
|
|
var serializer = new SerializerBuilder() |
|
|
|
.WithNamingConvention(UnderscoredNamingConvention.Instance) |
|
|
|
.WithNamingConvention(UnderscoredNamingConvention.Instance) |
|
|
|
.Build(); |
|
|
|
.Build(); |
|
|
|
var yamlData = serializer.Serialize(comfyModelPaths); |
|
|
|
var yamlData = serializer.Serialize(newRootNode); |
|
|
|
File.WriteAllText(extraPathsYamlPath, yamlData); |
|
|
|
File.WriteAllText(extraPathsYamlPath, yamlData); |
|
|
|
|
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
return Task.CompletedTask; |
|
|
|