Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Example UI #77

Merged
merged 3 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions OnnxStack.Console/OnnxStack.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<PlatformTarget>x64</PlatformTarget>
<Configurations>Debug;Release;Debug-DirectML;Debug-Cuda;Debug-TensorRT;Release-DirectML;Release-Cuda;Release-TensorRT</Configurations>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.16.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OnnxStack.ImageUpscaler\OnnxStack.ImageUpscaler.csproj" />
<ProjectReference Include="..\OnnxStack.StableDiffusion\OnnxStack.StableDiffusion.csproj" />
<PackageReference Include="OnnxStack.StableDiffusion" Version="0.12.0" Condition=" '$(Configuration)' == 'Release' OR '$(Configuration)' == 'Release-DirectML' OR '$(Configuration)' == 'Release-Cuda' OR '$(Configuration)' == 'Release-TensorRT'" />
<ProjectReference Include="..\OnnxStack.StableDiffusion\OnnxStack.StableDiffusion.csproj" Condition=" '$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Debug-DirectML' OR '$(Configuration)' == 'Debug-Cuda' OR '$(Configuration)' == 'Debug-TensorRT'" />
<ProjectReference Include="..\OnnxStack.ImageUpscaler\OnnxStack.ImageUpscaler.csproj" Condition=" '$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Debug-DirectML' OR '$(Configuration)' == 'Debug-Cuda' OR '$(Configuration)' == 'Debug-TensorRT'" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Release' " />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug-TensorRT' OR '$(Configuration)' == 'Release-TensorRT'" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug-Cuda' OR '$(Configuration)' == 'Release-Cuda'" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug-DirectML' OR '$(Configuration)' == 'Release-DirectML'" />
</ItemGroup>

<ItemGroup>
Expand Down
1,841 changes: 12 additions & 1,829 deletions OnnxStack.UI/App.xaml

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions OnnxStack.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ public App()
builder.Services.AddTransient<UpdateModelDialog>();
builder.Services.AddTransient<AddUpscaleModelDialog>();
builder.Services.AddTransient<UpdateUpscaleModelDialog>();
builder.Services.AddTransient<UpdateModelSettingsDialog>();
builder.Services.AddTransient<UpdateModelMetadataDialog>();
builder.Services.AddTransient<ViewModelMetadataDialog>();
builder.Services.AddTransient<UpdateUpscaleModelSettingsDialog> ();
builder.Services.AddSingleton<IModelFactory, ModelFactory>();
builder.Services.AddSingleton<IDialogService, DialogService>();
builder.Services.AddSingleton<IModelDownloadService, ModelDownloadService>();

// Build App
_applicationHost = builder.Build();
Expand Down
30 changes: 0 additions & 30 deletions OnnxStack.UI/Converters/ComboBoxAllItemConverter.cs

This file was deleted.

21 changes: 3 additions & 18 deletions OnnxStack.UI/Dialogs/AddModelDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,14 @@
WindowStartupLocation="CenterOwner"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
Style="{StaticResource BaseWindow}"
ContentRendered="OnContentRendered"
Title="Add StableDiffusion Model">
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
<StackPanel DockPanel.Dock="Top">

<StackPanel Visibility="{Binding EnableTemplateSelection, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel >
<TextBlock Text="Model Type"/>
<ComboBox ItemsSource="{Binding ModelTemplates}" SelectedItem="{Binding ModelTemplate}" DisplayMemberPath="Name" >
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Category}" Value="Upscaler">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsUserTemplate}" Value="True">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>

</Style>
</ComboBox.ItemContainerStyle>

</ComboBox>
</StackPanel>

Expand All @@ -46,7 +31,7 @@
<userControls:FilePickerTextBox FileName="{Binding ModelFolder, Mode=TwoWay}" IsFolderPicker="True" />
</StackPanel>

<StackPanel Margin="0,10,0,0" Visibility="{Binding EnableNameSelection, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel Margin="0,10,0,0">
<TextBlock Text="Model Name"/>
<TextBox Text="{Binding ModelName, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
Expand Down
89 changes: 13 additions & 76 deletions OnnxStack.UI/Dialogs/AddModelDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using Microsoft.Extensions.Logging;
using OnnxStack.StableDiffusion.Config;
using OnnxStack.StableDiffusion.Enums;
using OnnxStack.UI.Commands;
using OnnxStack.UI.Models;
using OnnxStack.UI.Services;
using OnnxStack.UI.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
Expand All @@ -28,34 +27,27 @@ public partial class AddModelDialog : Window, INotifyPropertyChanged
private string _modelName;
private IModelFactory _modelFactory;
private OnnxStackUIConfig _settings;
private ModelTemplateViewModel _modelTemplate;
private StableDiffusionModelTemplate _modelTemplate;
private StableDiffusionModelSet _modelSetResult;

public AddModelDialog(OnnxStackUIConfig settings, IModelFactory modelFactory, ILogger<AddModelDialog> logger)
{
_logger = logger;
_settings = settings;
_modelFactory = modelFactory;
WindowCloseCommand = new AsyncRelayCommand(WindowClose);
WindowRestoreCommand = new AsyncRelayCommand(WindowRestore);
WindowMinimizeCommand = new AsyncRelayCommand(WindowMinimize);
WindowMaximizeCommand = new AsyncRelayCommand(WindowMaximize);
SaveCommand = new AsyncRelayCommand(Save, CanExecuteSave);
CancelCommand = new AsyncRelayCommand(Cancel);
ModelTemplates = _settings.Templates.Where(x => !x.IsUserTemplate).ToList();
InvalidOptions = _settings.Templates.Where(x => x.IsUserTemplate).Select(x => x.Name.ToLower()).ToList();
ModelTemplates = new List<StableDiffusionModelTemplate>( _modelFactory.GetStableDiffusionModelTemplates());
InvalidOptions = _settings.StableDiffusionModelSets.Select(x => x.Name.ToLower()).ToList();
InitializeComponent();
}
public AsyncRelayCommand WindowMinimizeCommand { get; }
public AsyncRelayCommand WindowRestoreCommand { get; }
public AsyncRelayCommand WindowMaximizeCommand { get; }
public AsyncRelayCommand WindowCloseCommand { get; }

public AsyncRelayCommand SaveCommand { get; }
public AsyncRelayCommand CancelCommand { get; }
public ObservableCollection<ValidationResult> ValidationResults { get; set; } = new ObservableCollection<ValidationResult>();
public List<ModelTemplateViewModel> ModelTemplates { get; set; }
public List<StableDiffusionModelTemplate> ModelTemplates { get; set; }

public ModelTemplateViewModel ModelTemplate
public StableDiffusionModelTemplate ModelTemplate
{
get { return _modelTemplate; }
set { _modelTemplate = value; NotifyPropertyChanged(); CreateModelSet(); }
Expand All @@ -78,7 +70,7 @@ public string ModelFolder
set
{
_modelFolder = value;
if (_modelTemplate is not null && !_modelTemplate.IsUserTemplate)
if (_modelTemplate is not null)
_modelName = string.IsNullOrEmpty(_modelFolder)
? string.Empty
: Path.GetFileName(_modelFolder);
Expand All @@ -94,31 +86,11 @@ public StableDiffusionModelSet ModelSetResult
get { return _modelSetResult; }
}

private bool _enableTemplateSelection = true;

public bool EnableTemplateSelection
{
get { return _enableTemplateSelection; }
set { _enableTemplateSelection = value; NotifyPropertyChanged(); }
}

private bool _enableNameSelection = true;
public bool EnableNameSelection
{
get { return _enableNameSelection; }
set { _enableNameSelection = value; NotifyPropertyChanged(); }
}


public bool ShowDialog(ModelTemplateViewModel selectedTemplate = null)
public new bool ShowDialog()
{
if (selectedTemplate is not null)
{
EnableNameSelection = !selectedTemplate.IsUserTemplate;
EnableTemplateSelection = false;
ModelTemplate = selectedTemplate;
ModelName = selectedTemplate.IsUserTemplate ? selectedTemplate.Name : string.Empty;
}
return base.ShowDialog() ?? false;
}

Expand All @@ -127,15 +99,15 @@ private void CreateModelSet()
{
_modelSetResult = null;
ValidationResults.Clear();
if (_modelTemplate is null)
return;
if (string.IsNullOrEmpty(_modelFolder))
return;

_modelSetResult = _modelFactory.CreateStableDiffusionModelSet(ModelName.Trim(), ModelFolder, _modelTemplate.StableDiffusionTemplate);
_modelSetResult = _modelFactory.CreateStableDiffusionModelSet(ModelName.Trim(), ModelFolder, _modelTemplate);

// Validate
if (_enableNameSelection)
ValidationResults.Add(new ValidationResult("Name", !InvalidOptions.Contains(_modelName.ToLower()) && _modelName.Length > 2 && _modelName.Length < 50));

ValidationResults.Add(new ValidationResult("Name", !InvalidOptions.Contains(_modelName.ToLower()) && _modelName.Length > 2 && _modelName.Length < 50));
foreach (var validationResult in _modelSetResult.ModelConfigurations.Select(x => new ValidationResult(x.Type.ToString(), File.Exists(x.OnnxModelPath))))
{
ValidationResults.Add(validationResult);
Expand Down Expand Up @@ -168,41 +140,6 @@ private Task Cancel()
return Task.CompletedTask;
}

#region BaseWindow

private Task WindowClose()
{
Close();
return Task.CompletedTask;
}

private Task WindowRestore()
{
if (WindowState == WindowState.Maximized)
WindowState = WindowState.Normal;
else
WindowState = WindowState.Maximized;
return Task.CompletedTask;
}

private Task WindowMinimize()
{
WindowState = WindowState.Minimized;
return Task.CompletedTask;
}

private Task WindowMaximize()
{
WindowState = WindowState.Maximized;
return Task.CompletedTask;
}

private void OnContentRendered(object sender, EventArgs e)
{
InvalidateVisual();
}
#endregion

#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] string property = "")
Expand Down
6 changes: 2 additions & 4 deletions OnnxStack.UI/Dialogs/AddUpscaleModelDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
WindowStartupLocation="CenterOwner"
SnapsToDevicePixels="True"
UseLayoutRounding="True"
Style="{StaticResource BaseWindow}"
ContentRendered="OnContentRendered"
Title="Add Upscale Model">
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
<StackPanel DockPanel.Dock="Top">

<StackPanel Visibility="{Binding EnableTemplateSelection, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel>
<TextBlock Text="Model Type"/>
<ComboBox ItemsSource="{Binding ModelTemplates}" SelectedItem="{Binding ModelTemplate}" DisplayMemberPath="Name" >
<ComboBox.ItemContainerStyle>
Expand All @@ -46,7 +44,7 @@
<userControls:FilePickerTextBox FileName="{Binding ModelFile, Mode=TwoWay}" IsFolderPicker="False" Filter="Onnx Models (*.onnx)|*.onnx" DefaultExt="onnx" />
</StackPanel>

<StackPanel Margin="0,10,0,0" Visibility="{Binding EnableNameSelection, Converter={StaticResource BooleanToVisibilityConverter}}">
<StackPanel Margin="0,10,0,0">
<TextBlock Text="Model Name"/>
<TextBox Text="{Binding ModelName, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
Expand Down
Loading