forked from LykosAI/StabilityMatrix
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModelCardViewModel.cs
More file actions
686 lines (592 loc) · 24.8 KB
/
ModelCardViewModel.cs
File metadata and controls
686 lines (592 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Nodes;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Injectio.Attributes;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Languages;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.Models.Inference;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
using StabilityMatrix.Core.Models.Api.Comfy.NodeTypes;
using StabilityMatrix.Core.Models.Inference;
namespace StabilityMatrix.Avalonia.ViewModels.Inference;
[View(typeof(ModelCard))]
[ManagedService]
[RegisterTransient<ModelCardViewModel>]
public partial class ModelCardViewModel(
IInferenceClientManager clientManager,
IServiceManager<ViewModelBase> vmFactory,
TabContext tabContext
) : LoadableViewModelBase, IParametersLoadableState, IComfyStep
{
[ObservableProperty]
private HybridModelFile? selectedModel;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsGguf), nameof(ShowPrecisionSelection))]
private HybridModelFile? selectedUnetModel;
[ObservableProperty]
private bool isRefinerSelectionEnabled;
[ObservableProperty]
private bool showRefinerOption = true;
[ObservableProperty]
private HybridModelFile? selectedRefiner = HybridModelFile.None;
[ObservableProperty]
private HybridModelFile? selectedVae = HybridModelFile.Default;
[ObservableProperty]
private bool isVaeSelectionEnabled;
[ObservableProperty]
private bool disableSettings;
[ObservableProperty]
private bool isClipSkipEnabled;
[NotifyDataErrorInfo]
[ObservableProperty]
[Range(1, 24)]
private int clipSkip = 1;
[ObservableProperty]
private bool isExtraNetworksEnabled;
[ObservableProperty]
private bool isModelLoaderSelectionEnabled;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsStandaloneModelLoader))]
private ModelLoader selectedModelLoader;
[ObservableProperty]
private HybridModelFile? selectedClip1;
[ObservableProperty]
private HybridModelFile? selectedClip2;
[ObservableProperty]
private HybridModelFile? selectedClip3;
[ObservableProperty]
private HybridModelFile? selectedClip4;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsSd3Clip), nameof(IsHiDreamClip))]
private string? selectedClipType;
[ObservableProperty]
private string? selectedDType;
[ObservableProperty]
private bool enableModelLoaderSelection = true;
[ObservableProperty]
private bool isClipModelSelectionEnabled;
[ObservableProperty]
private double shift = 3.0d;
public List<string> WeightDTypes { get; set; } = ["default", "fp8_e4m3fn", "fp8_e5m2"];
public List<string> ClipTypes { get; set; } = ["flux", "sd3", "HiDream"];
public StackEditableCardViewModel ExtraNetworksStackCardViewModel { get; } =
new(vmFactory) { Title = Resources.Label_ExtraNetworks, AvailableModules = [typeof(LoraModule)] };
public IInferenceClientManager ClientManager { get; } = clientManager;
public List<ModelLoader> ModelLoaders { get; } =
Enum.GetValues<ModelLoader>().Except([ModelLoader.Gguf]).ToList();
public bool IsStandaloneModelLoader => SelectedModelLoader is ModelLoader.Unet;
public bool ShowPrecisionSelection => SelectedModelLoader is ModelLoader.Unet && !IsGguf;
public bool IsSd3Clip => SelectedClipType == "sd3";
public bool IsHiDreamClip => SelectedClipType == "HiDream";
public bool IsGguf => SelectedUnetModel?.RelativePath.EndsWith("gguf") ?? false;
protected override void OnInitialLoaded()
{
base.OnInitialLoaded();
ExtraNetworksStackCardViewModel.CardAdded += ExtraNetworksStackCardViewModelOnCardAdded;
}
public override void OnUnloaded()
{
base.OnUnloaded();
ExtraNetworksStackCardViewModel.CardAdded -= ExtraNetworksStackCardViewModelOnCardAdded;
}
private void ExtraNetworksStackCardViewModelOnCardAdded(object? sender, LoadableViewModelBase e)
{
OnSelectedModelChanged(SelectedModel);
}
[RelayCommand]
private static async Task OnConfigClickAsync()
{
await DialogHelper
.CreateMarkdownDialog(
"""
You can use a config (.yaml) file to load a model with specific settings.
Place the config file next to the model file with the same name:
```md
Models/
StableDiffusion/
my_model.safetensors
my_model.yaml <-
```
""",
"Using Model Configs",
TextEditorPreset.Console
)
.ShowAsync();
}
public async Task<bool> ValidateModel()
{
if (IsStandaloneModelLoader && SelectedUnetModel != null)
return true;
if (!IsStandaloneModelLoader && SelectedModel != null)
return true;
var dialog = DialogHelper.CreateMarkdownDialog(
"Please select a model to continue.",
"No Model Selected"
);
await dialog.ShowAsync();
return false;
}
private static ComfyTypedNodeBase<
ModelNodeConnection,
ClipNodeConnection,
VAENodeConnection
> GetDefaultModelLoader(ModuleApplyStepEventArgs e, string nodeName, HybridModelFile model)
{
// Check if config
if (model.Local?.ConfigFullPath is { } configPath)
{
// We'll need to upload the config file to `models/configs` later
var uploadConfigPath = e.AddFileTransferToConfigs(configPath);
return new ComfyNodeBuilder.CheckpointLoader
{
Name = nodeName,
// Only the file name is needed
ConfigName = Path.GetFileName(uploadConfigPath),
CkptName = model.RelativePath,
};
}
// Simple loader if no config
return new ComfyNodeBuilder.CheckpointLoaderSimple { Name = nodeName, CkptName = model.RelativePath };
}
/// <inheritdoc />
public virtual void ApplyStep(ModuleApplyStepEventArgs e)
{
if (SelectedModelLoader is ModelLoader.Default or ModelLoader.Nf4)
{
SetupDefaultModelLoader(e);
}
else // UNET/GGUF UNET workflow
{
SetupStandaloneModelLoader(e);
}
// Clip skip all models if enabled
if (IsClipSkipEnabled)
{
foreach (var (modelName, model) in e.Builder.Connections.Models)
{
if (model.Clip is not { } modelClip)
continue;
var clipSetLastLayer = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.CLIPSetLastLayer
{
Name = $"CLIP_Skip_{modelName}",
Clip = modelClip,
// Need to convert to negative indexing from (1 to 24) to (-1 to -24)
StopAtClipLayer = -ClipSkip,
}
);
model.Clip = clipSetLastLayer.Output;
}
}
// Load extra networks if enabled
if (IsExtraNetworksEnabled)
{
ExtraNetworksStackCardViewModel.ApplyStep(e);
}
}
/// <inheritdoc />
public override JsonObject SaveStateToJsonObject()
{
return SerializeModel(
new ModelCardModel
{
SelectedModelName = IsStandaloneModelLoader
? SelectedUnetModel?.RelativePath
: SelectedModel?.RelativePath,
SelectedVaeName = SelectedVae?.RelativePath,
SelectedRefinerName = SelectedRefiner?.RelativePath,
ClipSkip = ClipSkip,
IsVaeSelectionEnabled = IsVaeSelectionEnabled,
IsRefinerSelectionEnabled = IsRefinerSelectionEnabled,
IsClipSkipEnabled = IsClipSkipEnabled,
IsExtraNetworksEnabled = IsExtraNetworksEnabled,
IsModelLoaderSelectionEnabled = IsModelLoaderSelectionEnabled,
SelectedClip1Name = SelectedClip1?.RelativePath,
SelectedClip2Name = SelectedClip2?.RelativePath,
SelectedClip3Name = SelectedClip3?.RelativePath,
SelectedClip4Name = SelectedClip4?.RelativePath,
SelectedClipType = SelectedClipType,
IsClipModelSelectionEnabled = IsClipModelSelectionEnabled,
ModelLoader = SelectedModelLoader,
ShowRefinerOption = ShowRefinerOption,
ExtraNetworks = ExtraNetworksStackCardViewModel.SaveStateToJsonObject(),
}
);
}
/// <inheritdoc />
public override void LoadStateFromJsonObject(JsonObject state)
{
var model = DeserializeModel<ModelCardModel>(state);
// uwu 123
// :thinknom:
// :thinkcode:
SelectedModelLoader = model.ModelLoader is ModelLoader.Gguf ? ModelLoader.Unet : model.ModelLoader;
if (SelectedModelLoader is ModelLoader.Unet)
{
SelectedUnetModel = model.SelectedModelName is null
? null
: ClientManager.UnetModels.FirstOrDefault(x => x.RelativePath == model.SelectedModelName);
}
else
{
SelectedModel = model.SelectedModelName is null
? null
: ClientManager.Models.FirstOrDefault(x => x.RelativePath == model.SelectedModelName);
}
SelectedVae = model.SelectedVaeName is null
? HybridModelFile.Default
: ClientManager.VaeModels.FirstOrDefault(x => x.RelativePath == model.SelectedVaeName);
SelectedRefiner = model.SelectedRefinerName is null
? HybridModelFile.None
: ClientManager.Models.FirstOrDefault(x => x.RelativePath == model.SelectedRefinerName);
SelectedClip1 = model.SelectedClip1Name is null
? HybridModelFile.None
: ClientManager.ClipModels.FirstOrDefault(x => x.RelativePath == model.SelectedClip1Name);
SelectedClip2 = model.SelectedClip2Name is null
? HybridModelFile.None
: ClientManager.ClipModels.FirstOrDefault(x => x.RelativePath == model.SelectedClip2Name);
SelectedClip3 = model.SelectedClip3Name is null
? HybridModelFile.None
: ClientManager.ClipModels.FirstOrDefault(x => x.RelativePath == model.SelectedClip3Name);
SelectedClip4 = model.SelectedClip4Name is null
? HybridModelFile.None
: ClientManager.ClipModels.FirstOrDefault(x => x.RelativePath == model.SelectedClip4Name);
SelectedClipType = model.SelectedClipType;
ClipSkip = model.ClipSkip;
IsVaeSelectionEnabled = model.IsVaeSelectionEnabled;
IsRefinerSelectionEnabled = model.IsRefinerSelectionEnabled;
ShowRefinerOption = model.ShowRefinerOption;
IsClipSkipEnabled = model.IsClipSkipEnabled;
IsExtraNetworksEnabled = model.IsExtraNetworksEnabled;
IsModelLoaderSelectionEnabled = model.IsModelLoaderSelectionEnabled;
IsClipModelSelectionEnabled = model.IsClipModelSelectionEnabled;
if (model.ExtraNetworks is not null)
{
ExtraNetworksStackCardViewModel.LoadStateFromJsonObject(model.ExtraNetworks);
}
}
/// <inheritdoc />
public void LoadStateFromParameters(GenerationParameters parameters)
{
if (parameters.ModelName is not { } paramsModelName)
return;
var currentModels = ClientManager.Models.Concat(ClientManager.UnetModels).ToList();
var currentExtraNetworks = ClientManager.LoraModels.ToList();
HybridModelFile? model;
// First try hash match
if (parameters.ModelHash is not null)
{
model = currentModels.FirstOrDefault(m =>
m.Local?.ConnectedModelInfo?.Hashes.SHA256 is { } sha256
&& sha256.StartsWith(parameters.ModelHash, StringComparison.InvariantCultureIgnoreCase)
);
}
else if (parameters.ModelVersionId is not null)
{
model = currentModels.FirstOrDefault(m =>
m.Local?.ConnectedModelInfo?.VersionId == parameters.ModelVersionId
);
}
else
{
// Name matches
model = currentModels.FirstOrDefault(m => m.RelativePath.EndsWith(paramsModelName));
model ??= currentModels.FirstOrDefault(m => m.ShortDisplayName.StartsWith(paramsModelName));
}
ExtraNetworksStackCardViewModel.Clear();
if (parameters.ExtraNetworkModelVersionIds is not null)
{
IsExtraNetworksEnabled = true;
foreach (var versionId in parameters.ExtraNetworkModelVersionIds)
{
var module = ExtraNetworksStackCardViewModel.AddModule<LoraModule>();
module.GetCard<ExtraNetworkCardViewModel>().SelectedModel =
currentExtraNetworks.FirstOrDefault(m =>
m.Local?.ConnectedModelInfo?.VersionId == versionId
);
module.IsEnabled = true;
}
}
if (model is null)
return;
if (model.Local?.SharedFolderType is SharedFolderType.DiffusionModels)
{
SelectedUnetModel = model;
}
else
{
SelectedModel = model;
}
}
/// <inheritdoc />
public GenerationParameters SaveStateToParameters(GenerationParameters parameters)
{
if (IsStandaloneModelLoader)
{
return parameters with
{
ModelName = SelectedUnetModel?.FileName,
ModelHash = SelectedUnetModel?.Local?.ConnectedModelInfo?.Hashes.SHA256,
};
}
return parameters with
{
ModelName = SelectedModel?.FileName,
ModelHash = SelectedModel?.Local?.ConnectedModelInfo?.Hashes.SHA256,
};
}
partial void OnSelectedModelLoaderChanged(ModelLoader value)
{
if (value is ModelLoader.Unet)
{
if (!IsVaeSelectionEnabled)
IsVaeSelectionEnabled = true;
if (!IsClipModelSelectionEnabled)
IsClipModelSelectionEnabled = true;
}
}
partial void OnSelectedModelChanged(HybridModelFile? value)
{
// Update TabContext with the selected model
tabContext.SelectedModel = value;
if (!IsExtraNetworksEnabled)
return;
foreach (var card in ExtraNetworksStackCardViewModel.Cards)
{
if (card is not LoraModule loraModule)
continue;
if (loraModule.GetCard<ExtraNetworkCardViewModel>() is not { } cardViewModel)
continue;
cardViewModel.SelectedBaseModel = value;
}
}
partial void OnSelectedUnetModelChanged(HybridModelFile? value) => OnSelectedModelChanged(value);
private void SetupStandaloneModelLoader(ModuleApplyStepEventArgs e)
{
if (SelectedModelLoader is ModelLoader.Unet && IsGguf)
{
var checkpointLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.UnetLoaderGGUF
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.UNETLoader)),
UnetName =
SelectedUnetModel?.RelativePath
?? throw new ValidationException("Model not selected"),
}
);
e.Builder.Connections.Base.Model = checkpointLoader.Output;
}
else
{
var checkpointLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.UNETLoader
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.UNETLoader)),
UnetName =
SelectedUnetModel?.RelativePath
?? throw new ValidationException("Model not selected"),
WeightDtype = SelectedDType ?? "default",
}
);
e.Builder.Connections.Base.Model = checkpointLoader.Output;
}
if (SelectedModelLoader is ModelLoader.Unet && IsHiDreamClip)
{
var modelSamplingSd3 = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.ModelSamplingSD3
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.ModelSamplingSD3)),
Model = e.Builder.Connections.Base.Model,
Shift = Shift,
}
);
e.Builder.Connections.Base.Model = modelSamplingSd3.Output;
}
var vaeLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.VAELoader
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.VAELoader)),
VaeName = SelectedVae?.RelativePath ?? throw new ValidationException("No VAE Selected"),
}
);
e.Builder.Connections.Base.VAE = vaeLoader.Output;
if (SelectedClipType == "flux")
{
// DualCLIPLoader
var clipLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.DualCLIPLoader
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.DualCLIPLoader)),
ClipName1 =
SelectedClip1?.RelativePath ?? throw new ValidationException("No Clip1 Selected"),
ClipName2 =
SelectedClip2?.RelativePath ?? throw new ValidationException("No Clip2 Selected"),
Type = SelectedClipType ?? throw new ValidationException("No Clip Type Selected"),
}
);
e.Builder.Connections.Base.Clip = clipLoader.Output;
}
else
{
SetupClipLoaders(e);
}
}
private void SetupDefaultModelLoader(ModuleApplyStepEventArgs e)
{
// Load base checkpoint
var loaderNode =
SelectedModelLoader is ModelLoader.Default
? GetDefaultModelLoader(
e,
"CheckpointLoader_Base",
SelectedModel ?? throw new ValidationException("Model not selected")
)
: new ComfyNodeBuilder.CheckpointLoaderNF4
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.CheckpointLoaderNF4)),
CkptName =
SelectedModel?.RelativePath ?? throw new ValidationException("Model not selected"),
};
var baseLoader = e.Nodes.AddTypedNode(loaderNode);
e.Builder.Connections.Base.Model = baseLoader.Output1;
e.Builder.Connections.Base.VAE = baseLoader.Output3;
if (IsClipModelSelectionEnabled)
{
SetupClipLoaders(e);
}
else
{
e.Builder.Connections.Base.Clip = baseLoader.Output2;
}
// Load refiner if enabled
if (IsRefinerSelectionEnabled && SelectedRefiner is { IsNone: false })
{
var refinerLoader = e.Nodes.AddTypedNode(
GetDefaultModelLoader(
e,
"CheckpointLoader_Refiner",
SelectedRefiner ?? throw new ValidationException("Refiner Model enabled but not selected")
)
);
e.Builder.Connections.Refiner.Model = refinerLoader.Output1;
e.Builder.Connections.Refiner.Clip = refinerLoader.Output2;
e.Builder.Connections.Refiner.VAE = refinerLoader.Output3;
}
// Load VAE override if enabled
if (IsVaeSelectionEnabled && SelectedVae is { IsNone: false, IsDefault: false })
{
var vaeLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.VAELoader
{
Name = "VAELoader",
VaeName =
SelectedVae?.RelativePath
?? throw new ValidationException("VAE enabled but not selected"),
}
);
e.Builder.Connections.PrimaryVAE = vaeLoader.Output;
}
}
private void SetupClipLoaders(ModuleApplyStepEventArgs e)
{
if (
SelectedClip4 is { IsNone: false }
&& SelectedClip3 is { IsNone: false }
&& SelectedClip2 is { IsNone: false }
&& SelectedClip1 is { IsNone: false }
)
{
var clipLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.QuadrupleCLIPLoader
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.QuadrupleCLIPLoader)),
ClipName1 =
SelectedClip1?.RelativePath ?? throw new ValidationException("No Clip1 Selected"),
ClipName2 =
SelectedClip2?.RelativePath ?? throw new ValidationException("No Clip2 Selected"),
ClipName3 =
SelectedClip3?.RelativePath ?? throw new ValidationException("No Clip3 Selected"),
ClipName4 =
SelectedClip4?.RelativePath ?? throw new ValidationException("No Clip4 Selected"),
}
);
e.Builder.Connections.Base.Clip = clipLoader.Output;
}
else if (
SelectedClip3 is { IsNone: false }
&& SelectedClip2 is { IsNone: false }
&& SelectedClip1 is { IsNone: false }
)
{
var clipLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.TripleCLIPLoader
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.TripleCLIPLoader)),
ClipName1 =
SelectedClip1?.RelativePath ?? throw new ValidationException("No Clip1 Selected"),
ClipName2 =
SelectedClip2?.RelativePath ?? throw new ValidationException("No Clip2 Selected"),
ClipName3 =
SelectedClip3?.RelativePath ?? throw new ValidationException("No Clip3 Selected"),
}
);
e.Builder.Connections.Base.Clip = clipLoader.Output;
}
else if (SelectedClip2 is { IsNone: false } && SelectedClip1 is { IsNone: false })
{
var clipLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.DualCLIPLoader
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.DualCLIPLoader)),
ClipName1 =
SelectedClip1?.RelativePath ?? throw new ValidationException("No Clip1 Selected"),
ClipName2 =
SelectedClip2?.RelativePath ?? throw new ValidationException("No Clip2 Selected"),
Type = SelectedClipType ?? throw new ValidationException("No Clip Type Selected"),
}
);
e.Builder.Connections.Base.Clip = clipLoader.Output;
}
else if (SelectedClip1 is { IsNone: false })
{
var clipLoader = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.CLIPLoader()
{
Name = e.Nodes.GetUniqueName(nameof(ComfyNodeBuilder.CLIPLoader)),
ClipName =
SelectedClip1?.RelativePath ?? throw new ValidationException("No Clip1 Selected"),
Type = SelectedClipType ?? throw new ValidationException("No Clip Type Selected"),
}
);
e.Builder.Connections.Base.Clip = clipLoader.Output;
}
}
internal class ModelCardModel
{
public string? SelectedModelName { get; init; }
public string? SelectedRefinerName { get; init; }
public string? SelectedVaeName { get; init; }
public string? SelectedClip1Name { get; init; }
public string? SelectedClip2Name { get; init; }
public string? SelectedClip3Name { get; init; }
public string? SelectedClip4Name { get; init; }
public string? SelectedClipType { get; init; }
public ModelLoader ModelLoader { get; init; }
public int ClipSkip { get; init; } = 1;
public bool IsVaeSelectionEnabled { get; init; }
public bool IsRefinerSelectionEnabled { get; init; }
public bool IsClipSkipEnabled { get; init; }
public bool IsExtraNetworksEnabled { get; init; }
public bool IsModelLoaderSelectionEnabled { get; init; }
public bool IsClipModelSelectionEnabled { get; init; }
public bool ShowRefinerOption { get; init; }
public JsonObject? ExtraNetworks { get; init; }
}
}