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

Commit d7b17a2

Browse files
committed
Update UI to new API
1 parent 79274cf commit d7b17a2

30 files changed

+1562
-380
lines changed

OnnxStack.UI/App.xaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.Extensions.Logging;
44
using OnnxStack.Core;
55
using OnnxStack.ImageUpscaler;
6+
using OnnxStack.StableDiffusion.Config;
67
using OnnxStack.UI.Dialogs;
78
using OnnxStack.UI.Models;
89
using OnnxStack.UI.Services;
@@ -26,7 +27,7 @@ public App()
2627
builder.Services.AddLogging((loggingBuilder) => loggingBuilder.AddWindowLogger());
2728

2829
// Add OnnxStackStableDiffusion
29-
builder.Services.AddOnnxStackStableDiffusion();
30+
builder.Services.AddOnnxStack();
3031
builder.Services.AddOnnxStackImageUpscaler();
3132
builder.Services.AddOnnxStackConfig<OnnxStackUIConfig>();
3233

@@ -45,6 +46,9 @@ public App()
4546
builder.Services.AddSingleton<IModelFactory, ModelFactory>();
4647
builder.Services.AddSingleton<IDialogService, DialogService>();
4748
builder.Services.AddSingleton<IDeviceService, DeviceService>();
49+
builder.Services.AddSingleton<IStableDiffusionService, StableDiffusionService>();
50+
51+
4852
// Build App
4953
_applicationHost = builder.Build();
5054
}

OnnxStack.UI/Dialogs/AddControlNetModelDialog.xaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
<userControls:FilePickerTextBox FileName="{Binding ModelFile, Mode=TwoWay}" IsFolderPicker="False" Filter="Onnx Models (*.onnx)|*.onnx" DefaultExt="onnx" />
3636
</StackPanel>
3737

38-
<StackPanel Margin="0,10,0,0">
39-
<TextBlock Text="Annotation Model File"/>
40-
<userControls:FilePickerTextBox FileName="{Binding AnnotationModelFile, Mode=TwoWay}" IsFolderPicker="False" Filter="Onnx Models (*.onnx)|*.onnx" DefaultExt="onnx" />
41-
</StackPanel>
42-
4338
<StackPanel Margin="0,10,0,0">
4439
<TextBlock Text="Model Name"/>
4540
<TextBox Text="{Binding ModelName, UpdateSourceTrigger=PropertyChanged}" />

OnnxStack.UI/Dialogs/AddControlNetModelDialog.xaml.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public partial class AddControlNetModelDialog : Window, INotifyPropertyChanged
2626
private readonly List<string> _invalidOptions;
2727
private string _modelName;
2828
private string _modelFile;
29-
private string _annotationModelFile;
3029
private ControlNetType _selectedControlNetType;
3130
private IModelFactory _modelFactory;
3231
private OnnxStackUIConfig _settings;
@@ -70,12 +69,6 @@ public string ModelFile
7069
}
7170
}
7271

73-
public string AnnotationModelFile
74-
{
75-
get { return _annotationModelFile; }
76-
set { _annotationModelFile = value; NotifyPropertyChanged(); CreateModelSet(); }
77-
}
78-
7972
public ControlNetType SelectedControlNetType
8073
{
8174
get { return _selectedControlNetType; }
@@ -111,14 +104,11 @@ private void CreateModelSet()
111104
if (string.IsNullOrEmpty(_modelFile))
112105
return;
113106

114-
_modelSetResult = _modelFactory.CreateControlNetModelSet(ModelName.Trim(), _selectedControlNetType, _selectedPipelineType, _modelFile, _annotationModelFile);
107+
_modelSetResult = _modelFactory.CreateControlNetModelSet(ModelName.Trim(), _selectedControlNetType, _selectedPipelineType, _modelFile);
115108

116109
// Validate
117110
ValidationResults.Add(new ValidationResult("Name", !_invalidOptions.Contains(_modelName, StringComparer.OrdinalIgnoreCase) && _modelName.Length > 2 && _modelName.Length < 50));
118-
foreach (var validationResult in _modelSetResult.ModelConfigurations.Select(x => new ValidationResult(x.Type.ToString(), File.Exists(x.OnnxModelPath))))
119-
{
120-
ValidationResults.Add(validationResult);
121-
}
111+
ValidationResults.Add(new ValidationResult("Model", File.Exists(_modelSetResult.ControlNetConfig.OnnxModelPath)));
122112
}
123113

124114

OnnxStack.UI/Dialogs/AddModelDialog.xaml.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Microsoft.Extensions.Logging;
22
using OnnxStack.StableDiffusion.Config;
3-
using OnnxStack.StableDiffusion.Enums;
43
using OnnxStack.UI.Commands;
54
using OnnxStack.UI.Models;
65
using OnnxStack.UI.Services;
@@ -37,7 +36,7 @@ public AddModelDialog(OnnxStackUIConfig settings, IModelFactory modelFactory, IL
3736
_modelFactory = modelFactory;
3837
SaveCommand = new AsyncRelayCommand(Save, CanExecuteSave);
3938
CancelCommand = new AsyncRelayCommand(Cancel);
40-
ModelTemplates = new List<StableDiffusionModelTemplate>( _modelFactory.GetStableDiffusionModelTemplates());
39+
ModelTemplates = new List<StableDiffusionModelTemplate>(_modelFactory.GetStableDiffusionModelTemplates());
4140
InvalidOptions = _settings.GetModelNames();
4241
InitializeComponent();
4342
}
@@ -86,9 +85,6 @@ public StableDiffusionModelSet ModelSetResult
8685
get { return _modelSetResult; }
8786
}
8887

89-
90-
91-
9288
public new bool ShowDialog()
9389
{
9490
return base.ShowDialog() ?? false;
@@ -106,12 +102,17 @@ private void CreateModelSet()
106102

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

109-
// Validate
105+
//// Validate
110106
ValidationResults.Add(new ValidationResult("Name", !InvalidOptions.Contains(_modelName.ToLower()) && _modelName.Length > 2 && _modelName.Length < 50));
111-
foreach (var validationResult in _modelSetResult.ModelConfigurations.Select(x => new ValidationResult(x.Type.ToString(), File.Exists(x.OnnxModelPath))))
112-
{
113-
ValidationResults.Add(validationResult);
114-
}
107+
ValidationResults.Add(new ValidationResult("Unet Model", File.Exists(_modelSetResult.UnetConfig.OnnxModelPath)));
108+
ValidationResults.Add(new ValidationResult("Tokenizer Model", File.Exists(_modelSetResult.TokenizerConfig.OnnxModelPath)));
109+
if (_modelSetResult.Tokenizer2Config is not null)
110+
ValidationResults.Add(new ValidationResult("Tokenizer2 Model", File.Exists(_modelSetResult.Tokenizer2Config.OnnxModelPath)));
111+
ValidationResults.Add(new ValidationResult("TextEncoder Model", File.Exists(_modelSetResult.TextEncoderConfig.OnnxModelPath)));
112+
if (_modelSetResult.TextEncoder2Config is not null)
113+
ValidationResults.Add(new ValidationResult("TextEncoder2 Model", File.Exists(_modelSetResult.TextEncoder2Config.OnnxModelPath)));
114+
ValidationResults.Add(new ValidationResult("VaeDecoder Model", File.Exists(_modelSetResult.VaeDecoderConfig.OnnxModelPath)));
115+
ValidationResults.Add(new ValidationResult("VaeEncoder Model", File.Exists(_modelSetResult.VaeEncoderConfig.OnnxModelPath)));
115116
}
116117

117118

OnnxStack.UI/Dialogs/AddUpscaleModelDialog.xaml.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Microsoft.Extensions.Logging;
2-
using OnnxStack.StableDiffusion.Config;
2+
using OnnxStack.ImageUpscaler.Common;
33
using OnnxStack.UI.Commands;
44
using OnnxStack.UI.Models;
55
using OnnxStack.UI.Services;
@@ -102,12 +102,9 @@ private void CreateModelSet()
102102

103103
_modelSetResult = _modelFactory.CreateUpscaleModelSet(ModelName.Trim(), _modelFile, _modelTemplate);
104104

105-
// Validate
105+
//// Validate
106106
ValidationResults.Add(new ValidationResult("Name", !InvalidOptions.Contains(_modelName.ToLower()) && _modelName.Length > 2 && _modelName.Length < 50));
107-
foreach (var validationResult in _modelSetResult.ModelConfigurations.Select(x => new ValidationResult(x.Type.ToString(), File.Exists(x.OnnxModelPath))))
108-
{
109-
ValidationResults.Add(validationResult);
110-
}
107+
ValidationResults.Add(new ValidationResult("Model", File.Exists(_modelSetResult.UpscaleModelConfig.OnnxModelPath)));
111108
}
112109

113110

OnnxStack.UI/Dialogs/UpdateControlNetModelDialog.xaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@
5050
<userControls:FilePickerTextBox FileName="{Binding UpdateModelSet.ModelFiles[0].OnnxModelPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Filter="Onnx files (*.onnx)|*.onnx" DefaultExt="onnx" />
5151
</StackPanel>
5252

53-
<StackPanel Margin="0,10,0,0">
54-
<TextBlock Text="Annotation Model File"/>
55-
<userControls:FilePickerTextBox FileName="{Binding UpdateModelSet.ModelFiles[1].OnnxModelPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Filter="Onnx files (*.onnx)|*.onnx" DefaultExt="onnx" />
56-
</StackPanel>
53+
5754

5855
</StackPanel>
5956
</GroupBox>

OnnxStack.UI/Dialogs/UpdateControlNetModelDialog.xaml.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,12 @@ private bool Validate()
7474
return false;
7575
}
7676

77-
foreach (var modelFile in _modelSetResult.ModelConfigurations)
77+
if (!File.Exists(_modelSetResult.ControlNetConfig.OnnxModelPath))
7878
{
79-
if (!File.Exists(modelFile.OnnxModelPath))
80-
{
81-
ValidationError = $"'{modelFile.Type}' model file not found";
82-
return false;
83-
}
79+
ValidationError = $"ContolNet model file not found";
80+
return false;
8481
}
82+
8583
ValidationError = null;
8684
return true;
8785
}

0 commit comments

Comments
 (0)