Skip to content

Commit

Permalink
Add support for Stable Swarm
Browse files Browse the repository at this point in the history
Update MetadataExtractor with Unicode fix for tag descirption decoding
  • Loading branch information
RupertAvery committed Jun 12, 2024
1 parent 9269cd0 commit 66ead3e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion Diffusion.Scanner/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,23 @@ private static FileType GetFileType(Stream stream)
var isFoocus = false;
foreach (var directory in directories)
{
if (directory.Name == "Exif IFD0")
if (directory.Name == "Exif SubIFD")
{
foreach (var tag in directory.Tags)
{
switch (tag.Name)
{
case "User Comment":
var description = tag.Description;
if (description.Contains("sui_image_params"))
{
fileParameters = ReadStableSwarmParameters(description);
}
break;
}
}
}
else if (directory.Name == "Exif IFD0")
{
foreach (var tag in directory.Tags)
{
Expand Down Expand Up @@ -998,6 +1014,46 @@ private static FileParameters ReadFooocusMREParameters(string data)
return fp;
}


private static FileParameters ReadStableSwarmParameters(string data)
{
var json = JsonDocument.Parse(data);

var root = json.RootElement;

var fp = new FileParameters();

var suiRoot = root.GetProperty("sui_image_params");

fp.Prompt = suiRoot.GetProperty("prompt").GetString();
fp.NegativePrompt = suiRoot.GetProperty("negativeprompt").GetString();
fp.Steps = suiRoot.GetProperty("steps").GetInt32();
fp.CFGScale = suiRoot.GetProperty("cfgscale").GetDecimal();

//var resolution = root.GetProperty("resolution").GetString();
//resolution = resolution.Substring(1, resolution.Length - 2);
//var parts = resolution.Split(new[] { ',' }, StringSplitOptions.TrimEntries);

fp.Width = suiRoot.GetProperty("width").GetInt32();
fp.Height = suiRoot.GetProperty("height").GetInt32();
fp.Seed = suiRoot.GetProperty("seed").GetInt64();

if (suiRoot.TryGetProperty("sampler", out var sampler))
{
fp.Sampler = sampler.GetString();
}

if (suiRoot.TryGetProperty("model", out var model))
{
fp.Model = model.GetString();
}

//fp.ModelHash = root.GetProperty("base_model_hash").GetString();
fp.OtherParameters = $"Steps: {fp.Steps} Sampler: {fp.Sampler} CFG Scale: {fp.CFGScale} Seed: {fp.Seed} Size: {fp.Width}x{fp.Height}";

return fp;
}

private static FileParameters ReadFooocusParameters(string data)
{
var json = JsonDocument.Parse(data);
Expand Down
Binary file modified lib/MetadataExtractor.dll
Binary file not shown.

0 comments on commit 66ead3e

Please sign in to comment.