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

Commit 1926dec

Browse files
authored
Merge pull request #77 from saddam213/ExampleUI
Example UI
2 parents 8a8ae44 + a7d3569 commit 1926dec

File tree

73 files changed

+987
-8547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+987
-8547
lines changed

OnnxStack.Console/OnnxStack.Console.csproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>disable</Nullable>
88
<PlatformTarget>x64</PlatformTarget>
9+
<Configurations>Debug;Release;Debug-DirectML;Debug-Cuda;Debug-TensorRT;Release-DirectML;Release-Cuda;Release-TensorRT</Configurations>
910
</PropertyGroup>
1011

1112
<ItemGroup>
1213
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
1314
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
14-
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.16.3" />
1515
</ItemGroup>
1616

1717
<ItemGroup>
18-
<ProjectReference Include="..\OnnxStack.ImageUpscaler\OnnxStack.ImageUpscaler.csproj" />
19-
<ProjectReference Include="..\OnnxStack.StableDiffusion\OnnxStack.StableDiffusion.csproj" />
18+
<PackageReference Include="OnnxStack.StableDiffusion" Version="0.12.0" Condition=" '$(Configuration)' == 'Release' OR '$(Configuration)' == 'Release-DirectML' OR '$(Configuration)' == 'Release-Cuda' OR '$(Configuration)' == 'Release-TensorRT'" />
19+
<ProjectReference Include="..\OnnxStack.StableDiffusion\OnnxStack.StableDiffusion.csproj" Condition=" '$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Debug-DirectML' OR '$(Configuration)' == 'Debug-Cuda' OR '$(Configuration)' == 'Debug-TensorRT'" />
20+
<ProjectReference Include="..\OnnxStack.ImageUpscaler\OnnxStack.ImageUpscaler.csproj" Condition=" '$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Debug-DirectML' OR '$(Configuration)' == 'Debug-Cuda' OR '$(Configuration)' == 'Debug-TensorRT'" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug' OR '$(Configuration)' == 'Release' " />
25+
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug-TensorRT' OR '$(Configuration)' == 'Release-TensorRT'" />
26+
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug-Cuda' OR '$(Configuration)' == 'Release-Cuda'" />
27+
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.16.3" Condition=" '$(Configuration)' == 'Debug-DirectML' OR '$(Configuration)' == 'Release-DirectML'" />
2028
</ItemGroup>
2129

2230
<ItemGroup>

OnnxStack.UI/App.xaml

Lines changed: 12 additions & 1829 deletions
Large diffs are not rendered by default.

OnnxStack.UI/App.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,8 @@ public App()
3939
builder.Services.AddTransient<UpdateModelDialog>();
4040
builder.Services.AddTransient<AddUpscaleModelDialog>();
4141
builder.Services.AddTransient<UpdateUpscaleModelDialog>();
42-
builder.Services.AddTransient<UpdateModelSettingsDialog>();
43-
builder.Services.AddTransient<UpdateModelMetadataDialog>();
44-
builder.Services.AddTransient<ViewModelMetadataDialog>();
45-
builder.Services.AddTransient<UpdateUpscaleModelSettingsDialog> ();
4642
builder.Services.AddSingleton<IModelFactory, ModelFactory>();
4743
builder.Services.AddSingleton<IDialogService, DialogService>();
48-
builder.Services.AddSingleton<IModelDownloadService, ModelDownloadService>();
4944

5045
// Build App
5146
_applicationHost = builder.Build();

OnnxStack.UI/Converters/ComboBoxAllItemConverter.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

OnnxStack.UI/Dialogs/AddModelDialog.xaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,14 @@
1414
WindowStartupLocation="CenterOwner"
1515
SnapsToDevicePixels="True"
1616
UseLayoutRounding="True"
17-
Style="{StaticResource BaseWindow}"
18-
ContentRendered="OnContentRendered"
1917
Title="Add StableDiffusion Model">
2018
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
2119
<StackPanel DockPanel.Dock="Top">
2220

23-
<StackPanel Visibility="{Binding EnableTemplateSelection, Converter={StaticResource BooleanToVisibilityConverter}}">
21+
<StackPanel >
2422
<TextBlock Text="Model Type"/>
2523
<ComboBox ItemsSource="{Binding ModelTemplates}" SelectedItem="{Binding ModelTemplate}" DisplayMemberPath="Name" >
26-
<ComboBox.ItemContainerStyle>
27-
<Style TargetType="{x:Type ComboBoxItem}" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
28-
<Setter Property="Visibility" Value="Visible" />
29-
<Style.Triggers>
30-
<DataTrigger Binding="{Binding Category}" Value="Upscaler">
31-
<Setter Property="Visibility" Value="Collapsed"/>
32-
</DataTrigger>
33-
<DataTrigger Binding="{Binding IsUserTemplate}" Value="True">
34-
<Setter Property="Visibility" Value="Collapsed"/>
35-
</DataTrigger>
36-
</Style.Triggers>
37-
38-
</Style>
39-
</ComboBox.ItemContainerStyle>
24+
4025
</ComboBox>
4126
</StackPanel>
4227

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

49-
<StackPanel Margin="0,10,0,0" Visibility="{Binding EnableNameSelection, Converter={StaticResource BooleanToVisibilityConverter}}">
34+
<StackPanel Margin="0,10,0,0">
5035
<TextBlock Text="Model Name"/>
5136
<TextBox Text="{Binding ModelName, UpdateSourceTrigger=PropertyChanged}" />
5237
</StackPanel>

OnnxStack.UI/Dialogs/AddModelDialog.xaml.cs

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using Microsoft.Extensions.Logging;
22
using OnnxStack.StableDiffusion.Config;
3+
using OnnxStack.StableDiffusion.Enums;
34
using OnnxStack.UI.Commands;
45
using OnnxStack.UI.Models;
56
using OnnxStack.UI.Services;
6-
using OnnxStack.UI.Views;
7-
using System;
87
using System.Collections.Generic;
98
using System.Collections.ObjectModel;
109
using System.ComponentModel;
@@ -28,34 +27,27 @@ public partial class AddModelDialog : Window, INotifyPropertyChanged
2827
private string _modelName;
2928
private IModelFactory _modelFactory;
3029
private OnnxStackUIConfig _settings;
31-
private ModelTemplateViewModel _modelTemplate;
30+
private StableDiffusionModelTemplate _modelTemplate;
3231
private StableDiffusionModelSet _modelSetResult;
3332

3433
public AddModelDialog(OnnxStackUIConfig settings, IModelFactory modelFactory, ILogger<AddModelDialog> logger)
3534
{
3635
_logger = logger;
3736
_settings = settings;
3837
_modelFactory = modelFactory;
39-
WindowCloseCommand = new AsyncRelayCommand(WindowClose);
40-
WindowRestoreCommand = new AsyncRelayCommand(WindowRestore);
41-
WindowMinimizeCommand = new AsyncRelayCommand(WindowMinimize);
42-
WindowMaximizeCommand = new AsyncRelayCommand(WindowMaximize);
4338
SaveCommand = new AsyncRelayCommand(Save, CanExecuteSave);
4439
CancelCommand = new AsyncRelayCommand(Cancel);
45-
ModelTemplates = _settings.Templates.Where(x => !x.IsUserTemplate).ToList();
46-
InvalidOptions = _settings.Templates.Where(x => x.IsUserTemplate).Select(x => x.Name.ToLower()).ToList();
40+
ModelTemplates = new List<StableDiffusionModelTemplate>( _modelFactory.GetStableDiffusionModelTemplates());
41+
InvalidOptions = _settings.StableDiffusionModelSets.Select(x => x.Name.ToLower()).ToList();
4742
InitializeComponent();
4843
}
49-
public AsyncRelayCommand WindowMinimizeCommand { get; }
50-
public AsyncRelayCommand WindowRestoreCommand { get; }
51-
public AsyncRelayCommand WindowMaximizeCommand { get; }
52-
public AsyncRelayCommand WindowCloseCommand { get; }
44+
5345
public AsyncRelayCommand SaveCommand { get; }
5446
public AsyncRelayCommand CancelCommand { get; }
5547
public ObservableCollection<ValidationResult> ValidationResults { get; set; } = new ObservableCollection<ValidationResult>();
56-
public List<ModelTemplateViewModel> ModelTemplates { get; set; }
48+
public List<StableDiffusionModelTemplate> ModelTemplates { get; set; }
5749

58-
public ModelTemplateViewModel ModelTemplate
50+
public StableDiffusionModelTemplate ModelTemplate
5951
{
6052
get { return _modelTemplate; }
6153
set { _modelTemplate = value; NotifyPropertyChanged(); CreateModelSet(); }
@@ -78,7 +70,7 @@ public string ModelFolder
7870
set
7971
{
8072
_modelFolder = value;
81-
if (_modelTemplate is not null && !_modelTemplate.IsUserTemplate)
73+
if (_modelTemplate is not null)
8274
_modelName = string.IsNullOrEmpty(_modelFolder)
8375
? string.Empty
8476
: Path.GetFileName(_modelFolder);
@@ -94,31 +86,11 @@ public StableDiffusionModelSet ModelSetResult
9486
get { return _modelSetResult; }
9587
}
9688

97-
private bool _enableTemplateSelection = true;
98-
99-
public bool EnableTemplateSelection
100-
{
101-
get { return _enableTemplateSelection; }
102-
set { _enableTemplateSelection = value; NotifyPropertyChanged(); }
103-
}
10489

105-
private bool _enableNameSelection = true;
106-
public bool EnableNameSelection
107-
{
108-
get { return _enableNameSelection; }
109-
set { _enableNameSelection = value; NotifyPropertyChanged(); }
110-
}
11190

11291

113-
public bool ShowDialog(ModelTemplateViewModel selectedTemplate = null)
92+
public new bool ShowDialog()
11493
{
115-
if (selectedTemplate is not null)
116-
{
117-
EnableNameSelection = !selectedTemplate.IsUserTemplate;
118-
EnableTemplateSelection = false;
119-
ModelTemplate = selectedTemplate;
120-
ModelName = selectedTemplate.IsUserTemplate ? selectedTemplate.Name : string.Empty;
121-
}
12294
return base.ShowDialog() ?? false;
12395
}
12496

@@ -127,15 +99,15 @@ private void CreateModelSet()
12799
{
128100
_modelSetResult = null;
129101
ValidationResults.Clear();
102+
if (_modelTemplate is null)
103+
return;
130104
if (string.IsNullOrEmpty(_modelFolder))
131105
return;
132106

133-
_modelSetResult = _modelFactory.CreateStableDiffusionModelSet(ModelName.Trim(), ModelFolder, _modelTemplate.StableDiffusionTemplate);
107+
_modelSetResult = _modelFactory.CreateStableDiffusionModelSet(ModelName.Trim(), ModelFolder, _modelTemplate);
134108

135109
// Validate
136-
if (_enableNameSelection)
137-
ValidationResults.Add(new ValidationResult("Name", !InvalidOptions.Contains(_modelName.ToLower()) && _modelName.Length > 2 && _modelName.Length < 50));
138-
110+
ValidationResults.Add(new ValidationResult("Name", !InvalidOptions.Contains(_modelName.ToLower()) && _modelName.Length > 2 && _modelName.Length < 50));
139111
foreach (var validationResult in _modelSetResult.ModelConfigurations.Select(x => new ValidationResult(x.Type.ToString(), File.Exists(x.OnnxModelPath))))
140112
{
141113
ValidationResults.Add(validationResult);
@@ -168,41 +140,6 @@ private Task Cancel()
168140
return Task.CompletedTask;
169141
}
170142

171-
#region BaseWindow
172-
173-
private Task WindowClose()
174-
{
175-
Close();
176-
return Task.CompletedTask;
177-
}
178-
179-
private Task WindowRestore()
180-
{
181-
if (WindowState == WindowState.Maximized)
182-
WindowState = WindowState.Normal;
183-
else
184-
WindowState = WindowState.Maximized;
185-
return Task.CompletedTask;
186-
}
187-
188-
private Task WindowMinimize()
189-
{
190-
WindowState = WindowState.Minimized;
191-
return Task.CompletedTask;
192-
}
193-
194-
private Task WindowMaximize()
195-
{
196-
WindowState = WindowState.Maximized;
197-
return Task.CompletedTask;
198-
}
199-
200-
private void OnContentRendered(object sender, EventArgs e)
201-
{
202-
InvalidateVisual();
203-
}
204-
#endregion
205-
206143
#region INotifyPropertyChanged
207144
public event PropertyChangedEventHandler PropertyChanged;
208145
public void NotifyPropertyChanged([CallerMemberName] string property = "")

OnnxStack.UI/Dialogs/AddUpscaleModelDialog.xaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
WindowStartupLocation="CenterOwner"
1515
SnapsToDevicePixels="True"
1616
UseLayoutRounding="True"
17-
Style="{StaticResource BaseWindow}"
18-
ContentRendered="OnContentRendered"
1917
Title="Add Upscale Model">
2018
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
2119
<StackPanel DockPanel.Dock="Top">
2220

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

49-
<StackPanel Margin="0,10,0,0" Visibility="{Binding EnableNameSelection, Converter={StaticResource BooleanToVisibilityConverter}}">
47+
<StackPanel Margin="0,10,0,0">
5048
<TextBlock Text="Model Name"/>
5149
<TextBox Text="{Binding ModelName, UpdateSourceTrigger=PropertyChanged}" />
5250
</StackPanel>

0 commit comments

Comments
 (0)