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

Commit adceb2c

Browse files
committed
Add Automation to UI
1 parent 1ecf164 commit adceb2c

File tree

13 files changed

+563
-118
lines changed

13 files changed

+563
-118
lines changed

OnnxStack.StableDiffusion/Config/BatchOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace OnnxStack.StableDiffusion.Config
55
public record BatchOptions
66
{
77
public BatchOptionType BatchType { get; set; }
8-
public int Count { get; set; }
98
public float ValueTo { get; set; }
109
public float ValueFrom { get; set; }
1110
public float Increment { get; set; } = 1f;

OnnxStack.StableDiffusion/Helpers/BatchGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static List<SchedulerOptions> GenerateBatch(IModelOptions modelOptions, B
1919
{
2020
if (batchOptions.BatchType == BatchOptionType.Seed)
2121
{
22-
return Enumerable.Range(0, Math.Max(1, batchOptions.Count))
22+
return Enumerable.Range(0, Math.Max(1, (int)batchOptions.ValueTo))
2323
.Select(x => Random.Shared.Next())
2424
.Select(x => schedulerOptions with { Seed = x })
2525
.ToList();

OnnxStack.UI/App.xaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,17 @@
9191
</ObjectDataProvider.MethodParameters>
9292
</ObjectDataProvider>
9393

94-
9594
<ObjectDataProvider x:Key="ModelCacheMode" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
9695
<ObjectDataProvider.MethodParameters>
9796
<x:Type TypeName="models:ModelCacheMode"/>
9897
</ObjectDataProvider.MethodParameters>
9998
</ObjectDataProvider>
10099

101-
100+
<ObjectDataProvider x:Key="BatchOptionType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
101+
<ObjectDataProvider.MethodParameters>
102+
<x:Type TypeName="SD_Enums:BatchOptionType"/>
103+
</ObjectDataProvider.MethodParameters>
104+
</ObjectDataProvider>
102105

103106

104107

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using OnnxStack.StableDiffusion.Enums;
2+
using System.ComponentModel;
3+
using System.Runtime.CompilerServices;
4+
5+
namespace Models
6+
{
7+
public class BatchOptionsModel : INotifyPropertyChanged
8+
{
9+
private float _valueTo;
10+
private float _valueFrom;
11+
private float _increment = 1;
12+
private BatchOptionType _batchType;
13+
private bool _isAutomationEnabled;
14+
private int _stepValue;
15+
private int _stepsValue = 1;
16+
private int _batchValue;
17+
private int _batchsValue = 1;
18+
19+
public BatchOptionType BatchType
20+
{
21+
get { return _batchType; }
22+
set { _batchType = value; NotifyPropertyChanged(); }
23+
}
24+
25+
public float ValueTo
26+
{
27+
get { return _valueTo; }
28+
set { _valueTo = value; NotifyPropertyChanged(); }
29+
}
30+
31+
public float ValueFrom
32+
{
33+
get { return _valueFrom; }
34+
set { _valueFrom = value; NotifyPropertyChanged(); }
35+
}
36+
37+
public float Increment
38+
{
39+
get { return _increment; }
40+
set { _increment = value; NotifyPropertyChanged(); }
41+
}
42+
43+
public bool IsAutomationEnabled
44+
{
45+
get { return _isAutomationEnabled; }
46+
set { _isAutomationEnabled = value; NotifyPropertyChanged(); }
47+
}
48+
49+
public int StepValue
50+
{
51+
get { return _stepValue; }
52+
set { _stepValue = value; NotifyPropertyChanged(); }
53+
}
54+
55+
public int StepsValue
56+
{
57+
get { return _stepsValue; }
58+
set { _stepsValue = value; NotifyPropertyChanged(); }
59+
}
60+
61+
public int BatchValue
62+
{
63+
get { return _batchValue; }
64+
set { _batchValue = value; NotifyPropertyChanged(); }
65+
}
66+
67+
public int BatchsValue
68+
{
69+
get { return _batchsValue; }
70+
set { _batchsValue = value; NotifyPropertyChanged(); }
71+
}
72+
73+
74+
#region INotifyPropertyChanged
75+
public event PropertyChangedEventHandler PropertyChanged;
76+
public void NotifyPropertyChanged([CallerMemberName] string property = "")
77+
{
78+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
79+
}
80+
#endregion
81+
}
82+
}

OnnxStack.UI/UserControls/SchedulerControl.xaml

Lines changed: 155 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
</UniformGrid>
7777

7878
<UniformGrid Columns="2" Margin="0,10,0,10">
79-
79+
8080

8181
<StackPanel Margin="0,0,5,0">
8282
<DockPanel>
@@ -216,10 +216,9 @@
216216
<TextBox Text="{Binding SchedulerOptions.OriginalInferenceSteps}"/>
217217
</StackPanel>
218218
<StackPanel Margin="1,0,1,0">
219-
220219
</StackPanel>
221220
<StackPanel VerticalAlignment="Bottom">
222-
221+
223222
</StackPanel>
224223
</UniformGrid>
225224

@@ -231,6 +230,159 @@
231230

232231
</StackPanel>
233232
</TabItem>
233+
234+
<!--Automation-->
235+
<TabItem>
236+
<TabItem.Header>
237+
<StackPanel Orientation="Horizontal" Margin="5">
238+
<userControls:FontAwesome Icon="&#xf544;" IconStyle="Light"/>
239+
<TextBlock Text="Automation" Margin="5,0,0,0"/>
240+
</StackPanel>
241+
</TabItem.Header>
242+
<StackPanel Margin="5">
243+
244+
<CheckBox Content="Enable Automation" IsChecked="{Binding BatchOptions.IsAutomationEnabled}" Margin="0,10,0,0"/>
245+
246+
<StackPanel IsEnabled="{Binding BatchOptions.IsAutomationEnabled}">
247+
248+
<StackPanel>
249+
<Label>Automation Type</Label>
250+
<ComboBox ItemsSource="{Binding Source={StaticResource BatchOptionType}}" SelectedItem="{Binding BatchOptions.BatchType}"/>
251+
</StackPanel>
252+
253+
254+
<!--Seed-->
255+
<StackPanel Margin="0,10">
256+
<UniformGrid Columns="3">
257+
<TextBlock Text="Count"/>
258+
<TextBlock />
259+
<TextBlock />
260+
</UniformGrid>
261+
<UniformGrid Columns="3">
262+
<TextBox Text="{Binding BatchOptions.ValueTo}" Margin="2,0"/>
263+
<TextBlock />
264+
<TextBlock />
265+
</UniformGrid>
266+
<StackPanel.Style>
267+
<Style TargetType="{x:Type StackPanel}">
268+
<Setter Property="Visibility" Value="Collapsed" />
269+
<Style.Triggers>
270+
<DataTrigger Binding="{Binding BatchOptions.BatchType, ElementName=UI}" Value="Seed" >
271+
<Setter Property="Visibility" Value="Visible" />
272+
</DataTrigger>
273+
</Style.Triggers>
274+
</Style>
275+
</StackPanel.Style>
276+
</StackPanel>
277+
278+
<!--Step-->
279+
<StackPanel Margin="0,10">
280+
<UniformGrid Columns="3">
281+
<TextBlock Text="Start Step"/>
282+
<TextBlock Text="End Step"/>
283+
<TextBlock Text="Increment"/>
284+
</UniformGrid>
285+
<UniformGrid Columns="3">
286+
<TextBox Text="{Binding BatchOptions.ValueFrom}" Margin="0,0,2,0"/>
287+
<TextBox Text="{Binding BatchOptions.ValueTo}" Margin="2,0"/>
288+
<TextBox Text="{Binding BatchOptions.Increment}" Margin="2,0,0,0"/>
289+
</UniformGrid>
290+
<StackPanel.Style>
291+
<Style TargetType="{x:Type StackPanel}">
292+
<Setter Property="Visibility" Value="Collapsed" />
293+
<Style.Triggers>
294+
<DataTrigger Binding="{Binding BatchOptions.BatchType, ElementName=UI}" Value="Step" >
295+
<Setter Property="Visibility" Value="Visible" />
296+
</DataTrigger>
297+
</Style.Triggers>
298+
</Style>
299+
</StackPanel.Style>
300+
</StackPanel>
301+
302+
303+
<!--Guidance-->
304+
<StackPanel Margin="0,10">
305+
<UniformGrid Columns="3">
306+
<TextBlock Text="Start Value"/>
307+
<TextBlock Text="End Value"/>
308+
<TextBlock Text="Increment"/>
309+
</UniformGrid>
310+
<UniformGrid Columns="3">
311+
<TextBox Text="{Binding BatchOptions.ValueFrom}" Margin="0,0,2,0"/>
312+
<TextBox Text="{Binding BatchOptions.ValueTo}" Margin="2,0"/>
313+
<TextBox Text="{Binding BatchOptions.Increment}" Margin="2,0,0,0"/>
314+
</UniformGrid>
315+
<StackPanel.Style>
316+
<Style TargetType="{x:Type StackPanel}">
317+
<Setter Property="Visibility" Value="Collapsed" />
318+
<Style.Triggers>
319+
<DataTrigger Binding="{Binding BatchOptions.BatchType, ElementName=UI}" Value="Guidance" >
320+
<Setter Property="Visibility" Value="Visible" />
321+
</DataTrigger>
322+
</Style.Triggers>
323+
</Style>
324+
</StackPanel.Style>
325+
</StackPanel>
326+
327+
328+
<!--Strength-->
329+
<StackPanel Margin="0,10">
330+
<UniformGrid Columns="3">
331+
<TextBlock Text="Start Value"/>
332+
<TextBlock Text="End Value"/>
333+
<TextBlock Text="Increment"/>
334+
</UniformGrid>
335+
<UniformGrid Columns="3">
336+
<TextBox Text="{Binding BatchOptions.ValueFrom}" Margin="0,0,2,0"/>
337+
<TextBox Text="{Binding BatchOptions.ValueTo}" Margin="2,0"/>
338+
<TextBox Text="{Binding BatchOptions.Increment}" Margin="2,0,0,0"/>
339+
</UniformGrid>
340+
<StackPanel.Style>
341+
<Style TargetType="{x:Type StackPanel}">
342+
<Setter Property="Visibility" Value="Collapsed" />
343+
<Style.Triggers>
344+
<DataTrigger Binding="{Binding BatchOptions.BatchType, ElementName=UI}" Value="Strength" >
345+
<Setter Property="Visibility" Value="Visible" />
346+
</DataTrigger>
347+
</Style.Triggers>
348+
</Style>
349+
</StackPanel.Style>
350+
</StackPanel>
351+
352+
<!--Progress-->
353+
<StackPanel Margin="0,5">
354+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
355+
<TextBlock Text="Steps " />
356+
<TextBlock Text="{Binding BatchOptions.StepValue}" DockPanel.Dock="Left" />
357+
<TextBlock Text=" / " />
358+
<TextBlock Text="{Binding BatchOptions.StepsValue}" DockPanel.Dock="Right"/>
359+
</StackPanel>
360+
<ProgressBar Value="{Binding BatchOptions.StepValue}" Maximum="{Binding BatchOptions.StepsValue}" Height="22"/>
361+
362+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,5,0,0 ">
363+
<TextBlock Text="Batch " />
364+
<TextBlock Text="{Binding BatchOptions.BatchValue}" DockPanel.Dock="Left" />
365+
<TextBlock Text=" / " />
366+
<TextBlock Text="{Binding BatchOptions.BatchsValue}" DockPanel.Dock="Right"/>
367+
</StackPanel>
368+
<ProgressBar Value="{Binding BatchOptions.BatchValue}" Maximum="{Binding BatchOptions.BatchsValue}" Height="22"/>
369+
</StackPanel>
370+
371+
</StackPanel>
372+
373+
</StackPanel>
374+
</TabItem>
375+
376+
377+
378+
<TabControl.Template>
379+
<ControlTemplate TargetType="TabControl">
380+
<DockPanel>
381+
<UniformGrid IsItemsHost="True" Rows="1" DockPanel.Dock="Top"></UniformGrid>
382+
<ContentPresenter ContentSource="SelectedContent"></ContentPresenter>
383+
</DockPanel>
384+
</ControlTemplate>
385+
</TabControl.Template>
234386
</TabControl>
235387
</DockPanel>
236388
</UserControl>

OnnxStack.UI/UserControls/SchedulerControl.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ public SchedulerOptionsModel SchedulerOptions
8282
DependencyProperty.Register("SchedulerOptions", typeof(SchedulerOptionsModel), typeof(SchedulerControl));
8383

8484

85+
public BatchOptionsModel BatchOptions
86+
{
87+
get { return (BatchOptionsModel)GetValue(BatchOptionsProperty); }
88+
set { SetValue(BatchOptionsProperty, value); }
89+
}
90+
public static readonly DependencyProperty BatchOptionsProperty =
91+
DependencyProperty.Register("BatchOptions", typeof(BatchOptionsModel), typeof(SchedulerControl));
92+
93+
94+
95+
96+
8597
/// <summary>
8698
/// Gets or sets the options configuration.
8799
/// </summary>

OnnxStack.UI/Utils.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using OnnxStack.StableDiffusion.Config;
1+
using Models;
2+
using OnnxStack.StableDiffusion.Config;
23
using OnnxStack.StableDiffusion.Enums;
34
using OnnxStack.UI.Models;
45
using System;
@@ -82,8 +83,8 @@ public static async Task<bool> AutoSave(this ImageResult imageResult, string aut
8283
Directory.CreateDirectory(autosaveDirectory);
8384

8485
var random = RandomString();
85-
var imageFile = Path.Combine(autosaveDirectory, $"image-{imageResult.SchedulerOptions.Seed}-{random}.png");
86-
var blueprintFile = Path.Combine(autosaveDirectory, $"image-{imageResult.SchedulerOptions.Seed}-{random}.json");
86+
var imageFile = Path.Combine(autosaveDirectory, $"image-{imageResult.SchedulerOptions.Seed}-{random}.png");
87+
var blueprintFile = Path.Combine(autosaveDirectory, $"image-{imageResult.SchedulerOptions.Seed}-{random}.json");
8788
if (!await imageResult.SaveImageFile(imageFile))
8889
return false;
8990

@@ -167,6 +168,33 @@ public static PromptOptionsModel ToPromptOptionsModel(this PromptOptions promptO
167168
};
168169
}
169170

171+
172+
173+
public static BatchOptionsModel ToBatchOptionsModel(this BatchOptions batchOptions)
174+
{
175+
return new BatchOptionsModel
176+
{
177+
BatchType = batchOptions.BatchType,
178+
ValueTo = batchOptions.ValueTo,
179+
Increment = batchOptions.Increment,
180+
ValueFrom = batchOptions.ValueFrom
181+
};
182+
}
183+
184+
185+
public static BatchOptions ToBatchOptions(this BatchOptionsModel batchOptionsModel)
186+
{
187+
return new BatchOptions
188+
{
189+
BatchType = batchOptionsModel.BatchType,
190+
ValueTo = batchOptionsModel.ValueTo,
191+
Increment = batchOptionsModel.Increment,
192+
ValueFrom = batchOptionsModel.ValueFrom
193+
};
194+
}
195+
196+
197+
170198
public static void LogToWindow(string message)
171199
{
172200
System.Windows.Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>

OnnxStack.UI/Views/ImageInpaint.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<userControls:SchedulerControl DockPanel.Dock="Bottom"
3535
SelectedModel="{Binding SelectedModel}"
3636
DiffuserType="ImageInpaint"
37+
BatchOptions="{Binding BatchOptions}"
3738
SchedulerOptions="{Binding SchedulerOptions, Mode=TwoWay}"
3839
IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}"
3940
Margin="0, 10, 0 ,0"/>

0 commit comments

Comments
 (0)