Browse Source

Add module adding for StackEditableCard

pull/333/head
Ionite 1 year ago
parent
commit
2e72fd8684
No known key found for this signature in database
  1. 25
      StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs
  2. 4
      StabilityMatrix.Avalonia/ViewModels/Inference/Modules/HiresFixModule.cs
  3. 1
      StabilityMatrix.Avalonia/ViewModels/Inference/Modules/UpscalerModule.cs
  4. 44
      StabilityMatrix.Avalonia/ViewModels/Inference/StackEditableCardViewModel.cs

25
StabilityMatrix.Avalonia/ViewModels/Inference/InferenceTextToImageViewModel.cs

@ -14,6 +14,7 @@ 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.Extensions;
using StabilityMatrix.Core.Helper;
@ -41,6 +42,9 @@ public class InferenceTextToImageViewModel
[JsonIgnore]
public StackCardViewModel StackCardViewModel { get; }
[JsonPropertyName("Modules")]
public StackEditableCardViewModel ModulesCardViewModel { get; }
[JsonPropertyName("Model")]
public ModelCardViewModel ModelCardViewModel { get; }
@ -68,7 +72,11 @@ public class InferenceTextToImageViewModel
[JsonPropertyName("Seed")]
public SeedCardViewModel SeedCardViewModel { get; }
public bool IsFreeUEnabled
public bool IsFreeUEnabled => false;
public bool IsHiresFixEnabled => false;
public bool IsUpscaleEnabled => false;
/*public bool IsFreeUEnabled
{
get => StackCardViewModel.GetCard<StackExpanderViewModel>().IsEnabled;
set => StackCardViewModel.GetCard<StackExpanderViewModel>().IsEnabled = value;
@ -84,7 +92,7 @@ public class InferenceTextToImageViewModel
{
get => StackCardViewModel.GetCard<StackExpanderViewModel>(2).IsEnabled;
set => StackCardViewModel.GetCard<StackExpanderViewModel>(2).IsEnabled = value;
}
}*/
public InferenceTextToImageViewModel(
INotificationService notificationService,
@ -123,14 +131,21 @@ public class InferenceTextToImageViewModel
FreeUCardViewModel = vmFactory.Get<FreeUCardViewModel>();
BatchSizeCardViewModel = vmFactory.Get<BatchSizeCardViewModel>();
StackCardViewModel = vmFactory.Get<StackCardViewModel>();
ModulesCardViewModel = vmFactory.Get<StackEditableCardViewModel>(modulesCard =>
{
modulesCard.AvailableModules = new[] { typeof(HiresFixModule), typeof(UpscalerModule) };
modulesCard.DefaultModules = modulesCard.AvailableModules;
modulesCard.InitializeDefaults();
});
StackCardViewModel = vmFactory.Get<StackCardViewModel>();
StackCardViewModel.AddCards(
new LoadableViewModelBase[]
{
ModelCardViewModel,
SamplerCardViewModel,
// Free U
ModulesCardViewModel,
/*// Free U
vmFactory.Get<StackExpanderViewModel>(stackExpander =>
{
stackExpander.Title = "FreeU";
@ -152,7 +167,7 @@ public class InferenceTextToImageViewModel
{
stackExpander.Title = "Upscale";
stackExpander.AddCards(new LoadableViewModelBase[] { UpscalerCardViewModel });
}),
}),*/
SeedCardViewModel,
BatchSizeCardViewModel,
}

4
StabilityMatrix.Avalonia/ViewModels/Inference/Modules/HiresFixModule.cs

@ -8,7 +8,7 @@ using StabilityMatrix.Core.Models.Api.Comfy.Nodes;
namespace StabilityMatrix.Avalonia.ViewModels.Inference.Modules;
public class HiresFixModule : StackExpanderViewModel, IComfyStep
public class HiresFixModule : ModuleBase
{
/// <inheritdoc />
public HiresFixModule(ServiceManager<ViewModelBase> vmFactory)
@ -25,7 +25,7 @@ public class HiresFixModule : StackExpanderViewModel, IComfyStep
}
/// <inheritdoc />
public void ApplyStep(ModuleApplyStepEventArgs e)
protected override void OnApplyStep(ModuleApplyStepEventArgs e)
{
var builder = e.Builder;

1
StabilityMatrix.Avalonia/ViewModels/Inference/Modules/UpscalerModule.cs

@ -1,5 +1,4 @@
using System;
using AvaloniaEdit.Utils;
using StabilityMatrix.Avalonia.Models.Inference;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Avalonia.ViewModels.Base;

44
StabilityMatrix.Avalonia/ViewModels/Inference/StackEditableCardViewModel.cs

@ -1,18 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Text.Json.Nodes;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Helpers;
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.Extensions;
using StabilityMatrix.Core.Models;
namespace StabilityMatrix.Avalonia.ViewModels.Inference;
@ -22,21 +16,15 @@ public partial class StackEditableCardViewModel : StackViewModelBase
private readonly ServiceManager<ViewModelBase> vmFactory;
/// <summary>
/// Available card types resolvers for creation / serialization
/// - The Types must be annotated with <see cref="PolymorphicKeyAttribute"/>
/// Available module types for user creation
/// </summary>
public IReadOnlyList<EditableModule> AvailableModules { get; set; } =
Array.Empty<EditableModule>();
public IReadOnlyList<Type> AvailableModules { get; set; } = Array.Empty<Type>();
/// <summary>
/// Default modules that are used when no modules are loaded
/// This is a subset of <see cref="AvailableModules"/>
/// </summary>
public IReadOnlyList<EditableModule> DefaultModules { get; set; } =
Array.Empty<EditableModule>();
/*[ObservableProperty]
private IReadOnlyList<EditableModule> currentModules = Array.Empty<EditableModule>();*/
public IReadOnlyList<Type> DefaultModules { get; set; } = Array.Empty<Type>();
/// <inheritdoc />
public StackEditableCardViewModel(ServiceManager<ViewModelBase> vmFactory)
@ -47,27 +35,21 @@ public partial class StackEditableCardViewModel : StackViewModelBase
public void InitializeDefaults()
{
AddCards(DefaultModules.Select(m => m.Build(vmFactory)).Cast<LoadableViewModelBase>());
AddCards(DefaultModules.Select(t => vmFactory.Get(t)).Cast<LoadableViewModelBase>());
}
/*private ViewModelBase? GetViewModelFromTypeKey(string key)
[RelayCommand]
private void AddModule(Type type)
{
return AvailableModules.FirstOrDefault(x => x.Value == key)?.Builder(vmFactory);
}
private EditableModule? GetModuleFromViewModel(ViewModelBase vm)
if (!type.IsSubclassOf(typeof(ModuleBase)))
{
return AvailableModules.FirstOrDefault(x => x.Builder(vmFactory).GetType() == vm.GetType());
throw new ArgumentException($"Type {type} must be subclass of {nameof(ModuleBase)}");
}
private void AppendNewCard<T>()
where T : LoadableViewModelBase
{
var card = vmFactory.Get<T>();
AddCards(card);
var card = vmFactory.Get(type) as LoadableViewModelBase;
AddCards(card!);
}
/// <inheritdoc />
/*/// <inheritdoc />
public override void LoadStateFromJsonObject(JsonObject state)
{
var derivedTypes = ViewModelSerializer.GetDerivedTypes(typeof(LoadableViewModelBase));

Loading…
Cancel
Save