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

Commit a213a17

Browse files
committed
GUI support for LCM Diffusion
1 parent 08466f6 commit a213a17

File tree

9 files changed

+89
-9
lines changed

9 files changed

+89
-9
lines changed

OnnxStack.UI/Converters/DiffuserVisibilityConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur
1414
{
1515
if (values.Length == 2 && values[0] is List<DiffuserType> viewTypes && values[1] is List<DiffuserType> modelTypes)
1616
{
17-
return viewTypes.Any(modelTypes.Contains) ? Visibility.Visible : Visibility.Hidden;
17+
return viewTypes.Any(modelTypes.Contains) ? Visibility.Visible : Visibility.Collapsed;
1818
}
1919

20-
return Visibility.Hidden;
20+
return Visibility.Collapsed;
2121
}
2222

2323
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

OnnxStack.UI/UserControls/ModelPickerControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
IsEnabled="{Binding SelectedModel.IsLoading, FallbackValue=True, TargetNullValue=True, Converter={StaticResource InverseBoolConverter}}" >
5757
<ComboBox.ItemContainerStyle>
5858
<Style TargetType="{x:Type ComboBoxItem}">
59-
<Setter Property="Visibility" Value="Hidden" />
59+
<Setter Property="Visibility" Value="Collapsed" />
6060
<Style.Triggers>
6161
<DataTrigger Binding="{Binding IsEnabled}" Value="True">
6262
<Setter Property="Visibility">

OnnxStack.UI/UserControls/PromptControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</StackPanel>
2525
<StackPanel>
2626
<Label>Scheduler</Label>
27-
<ComboBox ItemsSource="{Binding Source={StaticResource SchedulerType}}" SelectedItem="{Binding PromptOptions.SchedulerType}"/>
27+
<ComboBox ItemsSource="{Binding SchedulerTypes}" SelectedItem="{Binding PromptOptions.SchedulerType}"/>
2828
</StackPanel>
2929
</StackPanel>
3030
</DockPanel>

OnnxStack.UI/UserControls/PromptControl.xaml.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
using OnnxStack.UI.Commands;
1+
using Models;
2+
using OnnxStack.StableDiffusion.Enums;
3+
using OnnxStack.UI.Commands;
24
using OnnxStack.UI.Models;
5+
using System.Collections.ObjectModel;
6+
using System;
37
using System.ComponentModel;
48
using System.Runtime.CompilerServices;
59
using System.Windows;
610
using System.Windows.Controls;
711
using System.Windows.Input;
12+
using System.Linq;
813

914
namespace OnnxStack.UI.UserControls
1015
{
@@ -13,6 +18,7 @@ namespace OnnxStack.UI.UserControls
1318
/// </summary>
1419
public partial class PromptControl : UserControl, INotifyPropertyChanged
1520
{
21+
private ObservableCollection<SchedulerType> _schedulerTypes = new();
1622

1723
/// <summary>Initializes a new instance of the <see cref="PromptControl" /> class.</summary>
1824
public PromptControl()
@@ -43,6 +49,46 @@ public PromptOptionsModel PromptOptions
4349
DependencyProperty.Register("PromptOptions", typeof(PromptOptionsModel), typeof(PromptControl));
4450

4551

52+
public ModelOptionsModel SelectedModel
53+
{
54+
get { return (ModelOptionsModel)GetValue(SelectedModelProperty); }
55+
set { SetValue(SelectedModelProperty, value); }
56+
}
57+
58+
public static readonly DependencyProperty SelectedModelProperty =
59+
DependencyProperty.Register("SelectedModel", typeof(ModelOptionsModel), typeof(PromptControl), new PropertyMetadata((d, e) =>
60+
{
61+
if (d is PromptControl schedulerControl)
62+
schedulerControl.OnModelChanged(e.NewValue as ModelOptionsModel);
63+
}));
64+
65+
public ObservableCollection<SchedulerType> SchedulerTypes
66+
{
67+
get { return _schedulerTypes; }
68+
set { _schedulerTypes = value; NotifyPropertyChanged(); }
69+
}
70+
71+
72+
/// <summary>
73+
/// Called when the selected model has changed.
74+
/// </summary>
75+
/// <param name="modelOptionsModel">The model options model.</param>
76+
private void OnModelChanged(ModelOptionsModel model)
77+
{
78+
SchedulerTypes.Clear();
79+
if (model.ModelOptions.PipelineType == DiffuserPipelineType.StableDiffusion)
80+
{
81+
foreach (SchedulerType type in Enum.GetValues<SchedulerType>().Where(x => x != SchedulerType.LCM))
82+
SchedulerTypes.Add(type);
83+
}
84+
else if (model.ModelOptions.PipelineType == DiffuserPipelineType.LatentConsistency)
85+
{
86+
SchedulerTypes.Add(SchedulerType.LCM);
87+
}
88+
89+
PromptOptions.SchedulerType = SchedulerTypes.FirstOrDefault();
90+
}
91+
4692
/// <summary>
4793
/// Resets the parameters.
4894
/// </summary>

OnnxStack.UI/UserControls/SchedulerControl.xaml.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using OnnxStack.Core;
1+
using Models;
2+
using OnnxStack.Core;
23
using OnnxStack.StableDiffusion.Enums;
34
using OnnxStack.UI.Commands;
45
using OnnxStack.UI.Models;
56
using System;
67
using System.Collections.ObjectModel;
78
using System.ComponentModel;
9+
using System.Linq;
810
using System.Runtime.CompilerServices;
911
using System.Windows;
1012
using System.Windows.Controls;
@@ -34,6 +36,20 @@ public SchedulerControl()
3436
public ObservableCollection<int> ValidSizes { get; }
3537

3638

39+
public ModelOptionsModel SelectedModel
40+
{
41+
get { return (ModelOptionsModel)GetValue(SelectedModelProperty); }
42+
set { SetValue(SelectedModelProperty, value); }
43+
}
44+
45+
public static readonly DependencyProperty SelectedModelProperty =
46+
DependencyProperty.Register("SelectedModel", typeof(ModelOptionsModel), typeof(SchedulerControl), new PropertyMetadata((d, e) =>
47+
{
48+
if (d is SchedulerControl schedulerControl)
49+
schedulerControl.OnModelChanged(e.NewValue as ModelOptionsModel);
50+
}));
51+
52+
3753
public DiffuserType DiffuserType
3854
{
3955
get { return (DiffuserType)GetValue(DiffuserTypeProperty); }
@@ -62,6 +78,17 @@ public SchedulerOptionsModel SchedulerOptions
6278
DependencyProperty.Register("SchedulerOptions", typeof(SchedulerOptionsModel), typeof(SchedulerControl));
6379

6480

81+
82+
/// <summary>
83+
/// Called when the selected model has changed.
84+
/// </summary>
85+
/// <param name="modelOptionsModel">The model options model.</param>
86+
private void OnModelChanged(ModelOptionsModel model)
87+
{
88+
89+
}
90+
91+
6592
/// <summary>
6693
/// Resets the parameters.
6794
/// </summary>

OnnxStack.UI/Views/ImageInpaint.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
<userControls:ModelPickerControl
2525
SupportedDiffusers="{Binding SupportedDiffusers}"
2626
SelectedModel="{Binding SelectedModel, Mode=TwoWay}" Models="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=Models}" />
27-
<userControls:PromptControl
27+
<userControls:PromptControl
28+
SelectedModel="{Binding SelectedModel}"
2829
PromptOptions="{Binding PromptOptions}"
2930
IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}"/>
3031
<userControls:SchedulerControl
32+
SelectedModel="{Binding SelectedModel}"
3133
DiffuserType="ImageInpaint"
3234
SchedulerOptions="{Binding SchedulerOptions, Mode=TwoWay}"
3335
IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}"

OnnxStack.UI/Views/ImageToImage.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
SupportedDiffusers="{Binding SupportedDiffusers}"
2626
SelectedModel="{Binding SelectedModel, Mode=TwoWay}" Models="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=Models}"/>
2727
<userControls:PromptControl
28+
SelectedModel="{Binding SelectedModel}"
2829
PromptOptions="{Binding PromptOptions}"
2930
IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}"/>
3031
<userControls:SchedulerControl
32+
SelectedModel="{Binding SelectedModel}"
3133
DiffuserType="ImageToImage"
3234
SchedulerOptions="{Binding SchedulerOptions, Mode=TwoWay}"
3335
IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}"

OnnxStack.UI/Views/Settings.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@
5757
</Grid.ColumnDefinitions>
5858

5959
<StackPanel>
60-
<UniformGrid Columns="5">
60+
<UniformGrid Columns="5" >
6161
<StackPanel>
6262
<TextBlock Text="Pipeline" />
6363
<ComboBox ItemsSource="{Binding Source={StaticResource DiffuserPipelineType}}" SelectedItem="{Binding SelectedModelSet.PipelineType}" />
6464
</StackPanel>
65-
<StackPanel VerticalAlignment="Center">
65+
<StackPanel VerticalAlignment="Center" Margin="10,0,0,0">
66+
<TextBlock />
6667
<CheckBox IsChecked="{Binding SelectedModelSet.IsEnabled}" Content="IsEnabled" />
6768
</StackPanel>
6869
</UniformGrid>

OnnxStack.UI/Views/TextToImage.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
SupportedDiffusers="{Binding SupportedDiffusers}"
2626
SelectedModel="{Binding SelectedModel, Mode=TwoWay}" Models="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=Models}"/>
2727
<userControls:PromptControl
28+
SelectedModel="{Binding SelectedModel}"
2829
PromptOptions="{Binding PromptOptions}"
2930
IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}"/>
3031
<userControls:SchedulerControl
32+
SelectedModel="{Binding SelectedModel}"
3133
SchedulerOptions="{Binding SchedulerOptions, Mode=TwoWay}"
3234
IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}" DiffuserType="TextToImage" Margin="0, 10, 0 ,0"/>
3335
</StackPanel>

0 commit comments

Comments
 (0)