Skip to content

Commit

Permalink
A lot of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
RupertAvery committed Aug 26, 2024
1 parent f65b7d4 commit 6fa0e64
Show file tree
Hide file tree
Showing 36 changed files with 1,036 additions and 602 deletions.
5 changes: 5 additions & 0 deletions Diffusion.Database/DataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ await Task.Run(() =>
db.CreateIndex<Image>(image => image.FileSize);
db.CreateIndex<Image>(image => image.ModifiedDate);

db.CreateIndex<Image>(image => image.Prompt);
db.CreateIndex<Image>(image => image.NegativePrompt);
db.CreateIndex<Image>(image => image.Workflow);
db.CreateIndex<Image>(image => image.WorkflowId);

db.CreateIndex("Image", new[] { "ForDeletion", "CreatedDate" });
db.CreateIndex("Image", new[] { "NSFW", "CreatedDate" });
db.CreateIndex("Image", new[] { "Unavailable", "CreatedDate" });
Expand Down
2 changes: 2 additions & 0 deletions Diffusion.Database/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Image
public int? ENSD { get; set; }
public long FileSize { get; set; }
public bool NoMetadata { get; set; }
public string? Workflow { get; set; }
public string? WorkflowId { get; set; }
}


Expand Down
1 change: 0 additions & 1 deletion Diffusion.Database/QueryBuilder.Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static (string WhereClause, IEnumerable<object> Bindings, IEnumerable<str
FilterNegativePromptEx(filter, conditions);
FilterPromptEx(filter, conditions);


return (string.Join(" AND ", conditions.Select(c => c.Key)),
conditions.SelectMany(c =>
{
Expand Down
105 changes: 105 additions & 0 deletions Diffusion.Scanner/ComfyUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace Diffusion.IO
{
public class Node
{
public string Id { get; set; }
public string Name { get; set; }
public List<Input> Inputs { get; set; }

public override int GetHashCode()
{
var hash = Id.GetHashCode();

hash = (hash * 397) ^ Name.GetHashCode();

foreach (var input in Inputs)
{
hash = (hash * 397) ^ input.Name.GetHashCode();
}

return hash;
}
}

public class Input
{
public string Name { get; set; }
public object Value { get; set; }

public Input(string name, object value)
{
Name = name;
Value = value;
}
}

public class ComfyUIParser
{
public IReadOnlyCollection<Node> Parse(string workflow)
{
if (workflow == null) return null;
var root = System.Text.Json.JsonDocument.Parse(workflow);
var rootElements = root.RootElement.EnumerateObject().ToDictionary(n => n.Name, n => n.Value);

var nodes = new List<Node>();

foreach (var element in rootElements)
{
var node = new Node();
node.Id = element.Key;

foreach (var props in element.Value.EnumerateObject())
{

if (props.Name == "inputs")
{
node.Inputs = new List<Input>();
foreach (var prop2 in props.Value.EnumerateObject())
{
switch (prop2.Value.ValueKind)
{
case JsonValueKind.Undefined:
break;
case JsonValueKind.Object:
break;
case JsonValueKind.Array:
break;
case JsonValueKind.String:
node.Inputs.Add(new Input(prop2.Name.Replace("_", "__"), prop2.Value.GetString()));
break;
case JsonValueKind.Number:
node.Inputs.Add(new Input(prop2.Name.Replace("_", "__"), prop2.Value.GetDouble()));
break;
case JsonValueKind.True:
node.Inputs.Add(new Input(prop2.Name.Replace("_", "__"), prop2.Value.GetBoolean()));
break;
case JsonValueKind.False:
node.Inputs.Add(new Input(prop2.Name.Replace("_", "__"), prop2.Value.GetBoolean()));
break;
case JsonValueKind.Null:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
else if (props.Name == "class_type")
{
node.Name = props.Value.GetString().Replace("_", "__");
}
}
nodes.Add(node);
}

return nodes;
}
}
}
2 changes: 2 additions & 0 deletions Diffusion.Scanner/FileParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public class FileParameters
public decimal? PromptStrength { get; set; }
public long FileSize { get; set; }
public bool NoMetadata { get; set; }
public string? Workflow { get; set; }
public string? WorkflowId { get; set; }
}
Loading

0 comments on commit 6fa0e64

Please sign in to comment.