Browse Source

Preserve unknown keys in fooocus config

pull/438/head
Ionite 10 months ago
parent
commit
0b99879db6
No known key found for this signature in database
  1. 99
      StabilityMatrix.Core/Models/FooocusConfig.cs
  2. 72
      StabilityMatrix.Core/Models/Packages/Fooocus.cs

99
StabilityMatrix.Core/Models/FooocusConfig.cs

@ -1,99 +0,0 @@
using System.Text.Json.Serialization;
namespace StabilityMatrix.Core.Models;
public class FooocusConfig
{
[JsonPropertyName("path_checkpoints")]
public string PathCheckpoints { get; set; }
[JsonPropertyName("path_loras")]
public string PathLoras { get; set; }
[JsonPropertyName("path_embeddings")]
public string PathEmbeddings { get; set; }
[JsonPropertyName("path_vae_approx")]
public string PathVaeApprox { get; set; }
[JsonPropertyName("path_upscale_models")]
public string PathUpscaleModels { get; set; }
[JsonPropertyName("path_inpaint")]
public string PathInpaint { get; set; }
[JsonPropertyName("path_controlnet")]
public string PathControlnet { get; set; }
[JsonPropertyName("path_clip_vision")]
public string PathClipVision { get; set; }
[JsonPropertyName("path_fooocus_expansion")]
public string PathFooocusExpansion { get; set; }
[JsonPropertyName("path_outputs")]
public string PathOutputs { get; set; }
[JsonPropertyName("default_model")]
public string DefaultModel { get; set; }
[JsonPropertyName("default_refiner")]
public string DefaultRefiner { get; set; }
[JsonPropertyName("default_refiner_switch")]
public double DefaultRefinerSwitch { get; set; }
[JsonPropertyName("default_cfg_scale")]
public long DefaultCfgScale { get; set; }
[JsonPropertyName("default_sample_sharpness")]
public long DefaultSampleSharpness { get; set; }
[JsonPropertyName("default_sampler")]
public string DefaultSampler { get; set; }
[JsonPropertyName("default_scheduler")]
public string DefaultScheduler { get; set; }
[JsonPropertyName("default_styles")]
public string[] DefaultStyles { get; set; }
[JsonPropertyName("default_prompt_negative")]
public string DefaultPromptNegative { get; set; }
[JsonPropertyName("default_prompt")]
public string DefaultPrompt { get; set; }
[JsonPropertyName("default_performance")]
public string DefaultPerformance { get; set; }
[JsonPropertyName("default_advanced_checkbox")]
public bool DefaultAdvancedCheckbox { get; set; }
[JsonPropertyName("default_max_image_number")]
public long DefaultMaxImageNumber { get; set; }
[JsonPropertyName("default_image_number")]
public long DefaultImageNumber { get; set; }
[JsonPropertyName("available_aspect_ratios")]
public string[] AvailableAspectRatios { get; set; }
[JsonPropertyName("default_aspect_ratio")]
public string DefaultAspectRatio { get; set; }
[JsonPropertyName("default_inpaint_engine_version")]
public string DefaultInpaintEngineVersion { get; set; }
[JsonPropertyName("default_cfg_tsnr")]
public long DefaultCfgTsnr { get; set; }
[JsonPropertyName("default_overwrite_step")]
public long DefaultOverwriteStep { get; set; }
[JsonPropertyName("default_overwrite_switch")]
public long DefaultOverwriteSwitch { get; set; }
[JsonPropertyName("example_inpaint_prompts")]
public string[] ExampleInpaintPrompts { get; set; }
}

72
StabilityMatrix.Core/Models/Packages/Fooocus.cs

@ -1,6 +1,6 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using StabilityMatrix.Core.Attributes;
@ -299,26 +299,26 @@ public class Fooocus(
private async Task SetupModelFoldersConfig(DirectoryPath installDirectory)
{
var fooocusConfigPath = installDirectory.JoinFile("config.txt");
var fooocusConfig = new FooocusConfig();
var fooocusConfig = new JsonObject();
if (fooocusConfigPath.Exists)
{
var configText = await fooocusConfigPath.ReadAllTextAsync().ConfigureAwait(false);
fooocusConfig = JsonSerializer.Deserialize<FooocusConfig>(configText) ?? new FooocusConfig();
}
else
{
fooocusConfigPath.Create();
fooocusConfig =
await JsonSerializer
.DeserializeAsync<JsonObject>(fooocusConfigPath.Info.OpenRead())
.ConfigureAwait(false) ?? new JsonObject();
}
fooocusConfig.PathCheckpoints = Path.Combine(settingsManager.ModelsDirectory, "StableDiffusion");
fooocusConfig.PathLoras = Path.Combine(settingsManager.ModelsDirectory, "Lora");
fooocusConfig.PathEmbeddings = Path.Combine(settingsManager.ModelsDirectory, "TextualInversion");
fooocusConfig.PathVaeApprox = Path.Combine(settingsManager.ModelsDirectory, "ApproxVAE");
fooocusConfig.PathUpscaleModels = Path.Combine(settingsManager.ModelsDirectory, "ESRGAN");
fooocusConfig.PathInpaint = Path.Combine(installDirectory, "models", "inpaint");
fooocusConfig.PathControlnet = Path.Combine(settingsManager.ModelsDirectory, "ControlNet");
fooocusConfig.PathClipVision = Path.Combine(settingsManager.ModelsDirectory, "CLIP");
fooocusConfig.PathFooocusExpansion = Path.Combine(
fooocusConfig["path_checkpoints"] = Path.Combine(settingsManager.ModelsDirectory, "StableDiffusion");
fooocusConfig["path_loras"] = Path.Combine(settingsManager.ModelsDirectory, "Lora");
fooocusConfig["path_embeddings"] = Path.Combine(settingsManager.ModelsDirectory, "TextualInversion");
fooocusConfig["path_vae_approx"] = Path.Combine(settingsManager.ModelsDirectory, "ApproxVAE");
fooocusConfig["path_upscale_models"] = Path.Combine(settingsManager.ModelsDirectory, "ESRGAN");
fooocusConfig["path_inpaint"] = Path.Combine(installDirectory, "models", "inpaint");
fooocusConfig["path_controlnet"] = Path.Combine(settingsManager.ModelsDirectory, "ControlNet");
fooocusConfig["path_clip_vision"] = Path.Combine(settingsManager.ModelsDirectory, "CLIP");
fooocusConfig["path_fooocus_expansion"] = Path.Combine(
installDirectory,
"models",
"prompt_expansion",
@ -329,7 +329,7 @@ public class Fooocus(
// doesn't always exist on first install
Directory.CreateDirectory(outputsPath);
fooocusConfig.PathOutputs = outputsPath;
fooocusConfig["path_outputs"] = outputsPath;
await fooocusConfigPath
.WriteAllTextAsync(JsonSerializer.Serialize(fooocusConfig, jsonSerializerOptions))
@ -339,32 +339,32 @@ public class Fooocus(
private async Task WriteDefaultConfig(DirectoryPath installDirectory)
{
var fooocusConfigPath = installDirectory.JoinFile("config.txt");
var fooocusConfig = new FooocusConfig();
var fooocusConfig = new JsonObject();
if (fooocusConfigPath.Exists)
{
var configText = await fooocusConfigPath.ReadAllTextAsync().ConfigureAwait(false);
fooocusConfig = JsonSerializer.Deserialize<FooocusConfig>(configText) ?? new FooocusConfig();
}
else
{
fooocusConfigPath.Create();
fooocusConfig =
await JsonSerializer
.DeserializeAsync<JsonObject>(fooocusConfigPath.Info.OpenRead())
.ConfigureAwait(false) ?? new JsonObject();
}
fooocusConfig.PathCheckpoints = Path.Combine(installDirectory, "models", "checkpoints");
fooocusConfig.PathLoras = Path.Combine(installDirectory, "models", "loras");
fooocusConfig.PathEmbeddings = Path.Combine(installDirectory, "models", "embeddings");
fooocusConfig.PathVaeApprox = Path.Combine(installDirectory, "models", "vae_approx");
fooocusConfig.PathUpscaleModels = Path.Combine(installDirectory, "models", "upscale_models");
fooocusConfig.PathInpaint = Path.Combine(installDirectory, "models", "inpaint");
fooocusConfig.PathControlnet = Path.Combine(installDirectory, "models", "controlnet");
fooocusConfig.PathClipVision = Path.Combine(installDirectory, "models", "clip_vision");
fooocusConfig.PathFooocusExpansion = Path.Combine(
fooocusConfig["path_checkpoints"] = Path.Combine(installDirectory, "models", "checkpoints");
fooocusConfig["path_loras"] = Path.Combine(installDirectory, "models", "loras");
fooocusConfig["path_embeddings"] = Path.Combine(installDirectory, "models", "embeddings");
fooocusConfig["path_vae_approx"] = Path.Combine(installDirectory, "models", "vae_approx");
fooocusConfig["path_upscale_models"] = Path.Combine(installDirectory, "models", "upscale_models");
fooocusConfig["path_inpaint"] = Path.Combine(installDirectory, "models", "inpaint");
fooocusConfig["path_controlnet"] = Path.Combine(installDirectory, "models", "controlnet");
fooocusConfig["path_clip_vision"] = Path.Combine(installDirectory, "models", "clip_vision");
fooocusConfig["path_fooocus_expansion"] = Path.Combine(
installDirectory,
"models",
"prompt_expansion",
"fooocus_expansion"
);
fooocusConfig.PathOutputs = Path.Combine(installDirectory, OutputFolderName);
fooocusConfig["path_outputs"] = Path.Combine(installDirectory, OutputFolderName);
await fooocusConfigPath
.WriteAllTextAsync(JsonSerializer.Serialize(fooocusConfig, jsonSerializerOptions))

Loading…
Cancel
Save