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

Commit 78e6960

Browse files
committed
Fix navigation issues when realtime is running
1 parent 80445d9 commit 78e6960

File tree

7 files changed

+52
-18
lines changed

7 files changed

+52
-18
lines changed

OnnxStack.UI/Models/SchedulerOptionsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SchedulerOptionsModel : INotifyPropertyChanged
1313
private int _seed;
1414
private int _inferenceSteps = 30;
1515
private float _guidanceScale = 7.5f;
16-
private float _strength = 0.7f;
16+
private float _strength = 0.75f;
1717
private float _initialNoiseLevel = 0f;
1818
private int _trainTimesteps = 1000;
1919
private float _betaStart = 0.00085f;

OnnxStack.UI/UserControls/PaintInputControl.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ public ImageInput CanvasResult
100100
set { SetValue(CanvasResultProperty, value); }
101101
}
102102
public static readonly DependencyProperty CanvasResultProperty =
103-
DependencyProperty.Register("CanvasResult", typeof(ImageInput), typeof(PaintInputControl));
103+
DependencyProperty.Register("CanvasResult", typeof(ImageInput), typeof(PaintInputControl), new PropertyMetadata(async (s, e) =>
104+
{
105+
if (s is PaintInputControl control && e.NewValue is null)
106+
{
107+
await control.ClearCanvas();
108+
}
109+
}));
104110

105111

106112
public SchedulerOptionsModel SchedulerOptions

OnnxStack.UI/UserControls/SchedulerControl.xaml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878

7979
<StackPanel Orientation="Horizontal" Margin="5,8,0,0">
8080
<Ellipse Fill="{StaticResource ControlDisabledBorderBrush}" Width="15" Height="15" />
81-
81+
8282
<StackPanel.Style>
8383
<Style TargetType="{x:Type StackPanel}">
8484
<Setter Property="Visibility" Value="Visible" />
@@ -97,10 +97,29 @@
9797
</StackPanel.Style>
9898
</StackPanel>
9999

100+
<StackPanel>
101+
<CheckBox IsChecked="{Binding BatchOptions.IsRealtimeEnabled}" Content="Enable Live Update" Margin="4,12,0,0" />
102+
<StackPanel.Style>
103+
<Style TargetType="{x:Type StackPanel}">
104+
<Setter Property="IsEnabled" Value="True" />
105+
<Style.Triggers>
106+
<MultiDataTrigger>
107+
<MultiDataTrigger.Conditions>
108+
<Condition Binding="{Binding IsGenerating}" Value="True" />
109+
<Condition Binding="{Binding BatchOptions.IsRealtimeEnabled}" Value="True" />
110+
</MultiDataTrigger.Conditions>
111+
<MultiDataTrigger.Setters>
112+
<Setter Property="IsEnabled" Value="False" />
113+
</MultiDataTrigger.Setters>
114+
</MultiDataTrigger>
115+
<DataTrigger Binding="{Binding BatchOptions.IsAutomationEnabled}" Value="True">
116+
<Setter Property="IsEnabled" Value="False" />
117+
</DataTrigger>
118+
</Style.Triggers>
119+
</Style>
120+
</StackPanel.Style>
121+
</StackPanel>
100122

101-
102-
103-
<CheckBox IsChecked="{Binding BatchOptions.IsRealtimeEnabled}" IsEnabled="{Binding BatchOptions.IsAutomationEnabled, Converter={StaticResource InverseBoolConverter}}" Content="Enable Live Update" Margin="4,12,0,0" />
104123
</StackPanel>
105124

106125

OnnxStack.UI/Views/ImageInpaintView.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ public bool IsControlsEnabled
181181
/// </summary>
182182
/// <param name="imageResult">The image result.</param>
183183
/// <returns></returns>
184-
public Task NavigateAsync(ImageResult imageResult)
184+
public async Task NavigateAsync(ImageResult imageResult)
185185
{
186+
if (IsGenerating)
187+
await Cancel();
188+
186189
Reset();
187190
HasResult = false;
188191
ResultImage = null;
@@ -206,7 +209,6 @@ public Task NavigateAsync(ImageResult imageResult)
206209
};
207210
SchedulerOptions = imageResult.SchedulerOptions.ToSchedulerOptionsModel();
208211
SelectedTabIndex = 0;
209-
return Task.CompletedTask;
210212
}
211213

212214

@@ -376,7 +378,7 @@ private async IAsyncEnumerable<ImageResult> ExecuteStableDiffusion(IModelOptions
376378

377379
var timestamp = Stopwatch.GetTimestamp();
378380
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, realtimePromptOptions, realtimeSchedulerOptions, RealtimeProgressCallback(), _cancelationTokenSource.Token);
379-
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
381+
yield return await GenerateResultAsync(result, realtimePromptOptions, realtimeSchedulerOptions, timestamp);
380382
}
381383
await Utils.RefreshDelay(refreshTimestamp, UISettings.RealtimeRefreshRate, _cancelationTokenSource.Token);
382384
}

OnnxStack.UI/Views/ImageToImageView.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ public bool IsControlsEnabled
167167
/// </summary>
168168
/// <param name="imageResult">The image result.</param>
169169
/// <returns></returns>
170-
public Task NavigateAsync(ImageResult imageResult)
170+
public async Task NavigateAsync(ImageResult imageResult)
171171
{
172+
if (IsGenerating)
173+
await Cancel();
174+
172175
Reset();
173176
HasResult = false;
174177
ResultImage = null;
@@ -189,7 +192,6 @@ public Task NavigateAsync(ImageResult imageResult)
189192
};
190193
SchedulerOptions = imageResult.SchedulerOptions.ToSchedulerOptionsModel();
191194
SelectedTabIndex = 0;
192-
return Task.CompletedTask;
193195
}
194196

195197

@@ -358,7 +360,7 @@ private async IAsyncEnumerable<ImageResult> ExecuteStableDiffusion(IModelOptions
358360

359361
var timestamp = Stopwatch.GetTimestamp();
360362
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, realtimePromptOptions, realtimeSchedulerOptions, RealtimeProgressCallback(), _cancelationTokenSource.Token);
361-
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
363+
yield return await GenerateResultAsync(result, realtimePromptOptions, realtimeSchedulerOptions, timestamp);
362364
}
363365
await Utils.RefreshDelay(refreshTimestamp, UISettings.RealtimeRefreshRate, _cancelationTokenSource.Token);
364366
}

OnnxStack.UI/Views/PaintToImageView.xaml.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,15 @@ public bool IsControlsEnabled
177177
/// </summary>
178178
/// <param name="imageResult">The image result.</param>
179179
/// <returns></returns>
180-
public Task NavigateAsync(ImageResult imageResult)
180+
public async Task NavigateAsync(ImageResult imageResult)
181181
{
182+
if (IsGenerating)
183+
await Cancel();
184+
182185
Reset();
183186
HasResult = false;
184187
ResultImage = null;
188+
CanvasImage = null;
185189
HasCanvasChanged = true;
186190
if (imageResult.Model.ModelOptions.Diffusers.Contains(DiffuserType.ImageToImage))
187191
{
@@ -199,7 +203,6 @@ public Task NavigateAsync(ImageResult imageResult)
199203
};
200204
SchedulerOptions = imageResult.SchedulerOptions.ToSchedulerOptionsModel();
201205
SelectedTabIndex = 0;
202-
return Task.CompletedTask;
203206
}
204207

205208

@@ -369,7 +372,7 @@ private async IAsyncEnumerable<ImageResult> ExecuteStableDiffusion(IModelOptions
369372

370373
var timestamp = Stopwatch.GetTimestamp();
371374
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, realtimePromptOptions, realtimeSchedulerOptions, RealtimeProgressCallback(), _cancelationTokenSource.Token);
372-
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
375+
yield return await GenerateResultAsync(result, realtimePromptOptions, realtimeSchedulerOptions, timestamp);
373376
}
374377
await Utils.RefreshDelay(refreshTimestamp, UISettings.RealtimeRefreshRate, _cancelationTokenSource.Token);
375378
}

OnnxStack.UI/Views/TextToImageView.xaml.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,11 @@ public bool IsControlsEnabled
153153
/// </summary>
154154
/// <param name="imageResult">The image result.</param>
155155
/// <returns></returns>
156-
public Task NavigateAsync(ImageResult imageResult)
156+
public async Task NavigateAsync(ImageResult imageResult)
157157
{
158+
if (IsGenerating)
159+
await Cancel();
160+
158161
Reset();
159162
HasResult = false;
160163
ResultImage = null;
@@ -169,7 +172,6 @@ public Task NavigateAsync(ImageResult imageResult)
169172
};
170173
SchedulerOptions = imageResult.SchedulerOptions.ToSchedulerOptionsModel();
171174
SelectedTabIndex = 0;
172-
return Task.CompletedTask;
173175
}
174176

175177

@@ -337,7 +339,7 @@ private async IAsyncEnumerable<ImageResult> ExecuteStableDiffusion(IModelOptions
337339
realtimePromptOptions.Prompt = string.IsNullOrEmpty(realtimePromptOptions.Prompt) ? " " : realtimePromptOptions.Prompt;
338340
var timestamp = Stopwatch.GetTimestamp();
339341
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, realtimePromptOptions, realtimeSchedulerOptions, RealtimeProgressCallback(), _cancelationTokenSource.Token);
340-
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
342+
yield return await GenerateResultAsync(result, realtimePromptOptions, realtimeSchedulerOptions, timestamp);
341343
}
342344
await Utils.RefreshDelay(refreshTimestamp, UISettings.RealtimeRefreshRate, _cancelationTokenSource.Token);
343345
}

0 commit comments

Comments
 (0)