Skip to content

Commit

Permalink
Allow scanning files with no metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
RupertAvery committed Jan 3, 2023
1 parent efdaf69 commit d56608a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions Diffusion.Database/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public class Image
public int? ClipSkip { get; set; }
public int? ENSD { get; set; }
public long FileSize { get; set; }
public bool NoMetadata { get; set; }
}
20 changes: 20 additions & 0 deletions Diffusion.Database/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static class QueryBuilder
private static readonly Regex FavoriteRegex = new Regex("\\b(?:favorite|fave):\\s*(?<value>(?:true|false))?\\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);

private static readonly Regex NSFWRegex = new Regex("\\b(?:nsfw):\\s*(?<value>(?:true|false))?\\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static readonly Regex NoMetadataRegex = new Regex("\\b(?:nometa|nometadata):\\s*(?<value>(?:true|false))?\\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);

private static readonly Regex NegativePromptRegex = new Regex("\\b(?:negative prompt|negative_prompt|negative):\\s*(?<value>.*)", RegexOptions.Compiled | RegexOptions.IgnoreCase);

Expand All @@ -62,6 +63,7 @@ public static (string, IEnumerable<object>) Parse(string prompt)
ParseFavorite(ref prompt, conditions);
ParseForDeletion(ref prompt, conditions);
ParseNSFW(ref prompt, conditions);
ParseNoMetadata(ref prompt, conditions);

ParseNegativePrompt(ref prompt, conditions);
ParsePrompt(ref prompt, conditions);
Expand Down Expand Up @@ -156,6 +158,24 @@ private static void ParseNSFW(ref string prompt, List<KeyValuePair<string, objec
//return false;
}

private static void ParseNoMetadata(ref string prompt, List<KeyValuePair<string, object>> conditions)
{
var match = NoMetadataRegex.Match(prompt);

if (match.Success)
{
prompt = NoMetadataRegex.Replace(prompt, String.Empty);

var value = true;

if (match.Groups["value"].Success)
{
value = match.Groups["value"].Value.ToLower() == "true";
}

conditions.Add(new KeyValuePair<string, object>("(NoMetadata = ?)", value));
}
}

private static void ParseFavorite(ref string prompt, List<KeyValuePair<string, object>> conditions)
{
Expand Down
1 change: 1 addition & 0 deletions Diffusion.Scanner/FileParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class FileParameters
public int? ENSD { get; set; }
public decimal? PromptStrength { get; set; }
public long FileSize { get; set; }
public bool NoMetadata { get; set; }
}
7 changes: 3 additions & 4 deletions Diffusion.Scanner/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,14 @@ public static List<string> GetDirectoryTextFileCache(string path)
}
}

fileParameters ??= new FileParameters()
{
NoMetadata = true
};


if (fileParameters != null)
{
FileInfo fileInfo = new FileInfo(file);
fileParameters.Path = file;
fileParameters.FileSize = fileInfo.Length;
}

return fileParameters;
}
Expand Down
1 change: 1 addition & 0 deletions Diffusion.Toolkit/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ await Dispatcher.Invoke(async () =>
HyperNetworkStrength = file.HyperNetworkStrength,
ClipSkip = file.ClipSkip,
FileSize = file.FileSize,
NoMetadata = file.NoMetadata
};

if (!string.IsNullOrEmpty(file.HyperNetwork) && !file.HyperNetworkStrength.HasValue)
Expand Down
7 changes: 7 additions & 0 deletions Diffusion.Toolkit/Tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ If you specify this term explicitly, it will override the **Hide NSFW from Resul

* `nsfw: [true|false]`

## No Metadata

This filter will show images that do not have metadata.

* `nometa: [true|false]`
* `nometadata: [true|false]`

## For Deletion

For Deletion is a Diffusion Toolkit metadata with a value of true or false, entered by the user. See [Deleting](#deleting)
Expand Down
2 changes: 1 addition & 1 deletion Diffusion.Toolkit/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
beta_v0.8.1
beta_v0.8.2

0 comments on commit d56608a

Please sign in to comment.