Skip to content

Commit be84502

Browse files
committed
Gallery/Preview, Improved pipeline loading
1 parent 9d4c592 commit be84502

Some content is hidden

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

56 files changed

+1558
-863
lines changed

DiffuseApp/DiffuseApp.Common/PipelineServer.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,30 @@ public async Task StartAsync(CancellationToken cancellationToken = default)
8484
}
8585
else if (message.Type == RequestType.Environment && _currentState == RequestType.Start)
8686
{
87-
_currentState = message.Type;
88-
CallbackMessage("Create Envrironment...", "Initialize");
87+
try
88+
{
89+
_currentState = message.Type;
90+
CallbackMessage("Create Environment...", "Initialize");
91+
var environment = message.Environment;
92+
var pythonService = new PythonManager(environment.Config, _logger);
93+
if (pythonService.Exists() && !environment.IsRebuild)
94+
await pythonService.LoadAsync(_progressCallback);
95+
else
96+
await pythonService.CreateAsync(environment.IsRebuild, environment.IsReinstall, _progressCallback);
8997

90-
var environment = message.Environment;
91-
var pythonService = new PythonManager(environment.Config, _logger);
92-
if (pythonService.Exists() && !environment.IsRebuild)
93-
await pythonService.LoadAsync(_progressCallback);
94-
else
95-
await pythonService.CreateAsync(environment.IsRebuild, environment.IsReinstall, _progressCallback);
98+
await _messagePipe.SendResponse(cancellationToken);
99+
CallbackMessage(string.Empty, "Initialize");
96100

97-
await _messagePipe.SendResponse(cancellationToken);
98-
CallbackMessage(string.Empty, "Initialize");
99-
continue;
101+
}
102+
catch (Exception ex)
103+
{
104+
await _messagePipe.SendMessage(new PipelineResponse
105+
{
106+
Error = ex.Message
107+
}, cancellationToken: cancellationToken);
108+
109+
throw;
110+
}
100111
}
101112

102113
// Environment Loaded

DiffuseApp/DiffuseApp.Common/ProcessLifetimeHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void Dispose()
4747
private const uint JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x2000;
4848

4949
[DllImport("kernel32.dll")]
50-
static extern IntPtr CreateJobObject(IntPtr lpJobAttributes, string? name);
50+
static extern IntPtr CreateJobObject(IntPtr lpJobAttributes, string name);
5151

5252
[DllImport("kernel32.dll")]
5353
static extern bool SetInformationJobObject(

DiffuseApp/DiffuseApp/App.xaml

Lines changed: 474 additions & 0 deletions
Large diffs are not rendered by default.

DiffuseApp/DiffuseApp/App.xaml.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Windows.Threading;
1515
using TensorStack.WPF;
1616
using TensorStack.WPF.Services;
17+
using Logger = Microsoft.Extensions.Logging.ILogger;
1718

1819
namespace Diffuse
1920
{
@@ -214,9 +215,9 @@ private void DeregisterExceptionHandlers()
214215
/// </summary>
215216
/// <param name="sender">The sender.</param>
216217
/// <param name="e">The <see cref="DispatcherUnhandledExceptionEventArgs"/> instance containing the event data.</param>
217-
private void OnDispatcherException(object sender, DispatcherUnhandledExceptionEventArgs e)
218+
private async void OnDispatcherException(object sender, DispatcherUnhandledExceptionEventArgs e)
218219
{
219-
ShowExceptionMessage(e.Exception);
220+
await ShowExceptionMessage(e.Exception);
220221

221222
// Prevent application from crashing
222223
e.Handled = true;
@@ -228,11 +229,11 @@ private void OnDispatcherException(object sender, DispatcherUnhandledExceptionEv
228229
/// </summary>
229230
/// <param name="sender">The sender.</param>
230231
/// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
231-
private void OnAppDomainException(object sender, UnhandledExceptionEventArgs e)
232+
private async void OnAppDomainException(object sender, UnhandledExceptionEventArgs e)
232233
{
233234
if (e.ExceptionObject is Exception ex)
234235
{
235-
ShowExceptionMessage(ex);
236+
await ShowExceptionMessage(ex);
236237
}
237238
}
238239

@@ -242,9 +243,9 @@ private void OnAppDomainException(object sender, UnhandledExceptionEventArgs e)
242243
/// </summary>
243244
/// <param name="sender">The sender.</param>
244245
/// <param name="e">The <see cref="UnobservedTaskExceptionEventArgs"/> instance containing the event data.</param>
245-
private void OnTaskSchedulerException(object sender, UnobservedTaskExceptionEventArgs e)
246+
private async void OnTaskSchedulerException(object sender, UnobservedTaskExceptionEventArgs e)
246247
{
247-
ShowExceptionMessage(e.Exception);
248+
await ShowExceptionMessage(e.Exception);
248249

249250
// Prevent application from crashing
250251
e.SetObserved();
@@ -278,7 +279,7 @@ private static string GetAppVersion()
278279
/// <returns>System.String.</returns>
279280
private static string GetAppVersionDisplay()
280281
{
281-
return $"v{AppVersion}-alpha";
282+
return $"v{AppVersion}-beta";
282283
}
283284

284285

DiffuseApp/DiffuseApp/Common/DiffusionHistory.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Diffuse.Views;
22
using System;
3+
using System.Runtime.CompilerServices;
34
using System.Text.Json.Serialization;
45

56
namespace Diffuse.Common
@@ -25,12 +26,19 @@ public record DiffusionHistory : IHistoryItem
2526
public int Width { get; init; }
2627
public int Height { get; init; }
2728

28-
public DiffusionInputOptions Options { get; init; }
29+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30+
public float FrameRate { get; init; }
2931

32+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
33+
public int FrameCount { get; init; }
34+
public DiffusionInputOptions Options { get; init; }
3035

3136
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
3237
public string ExtractModel { get; init; }
3338

39+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
40+
public ExtractorType? ExtractorType { get; init; }
41+
3442
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
3543
public ExtractInputOptions ExtractOptions { get; init; }
3644

@@ -49,6 +57,9 @@ public record DiffusionHistory : IHistoryItem
4957

5058
[JsonIgnore]
5159
public string ThumbPath { get; set; }
52-
60+
61+
62+
public virtual bool Equals(DiffusionHistory other) => ReferenceEquals(this, other);
63+
public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
5364
}
5465
}

DiffuseApp/DiffuseApp/Common/ExtractHistory.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Diffuse.Views;
22
using System;
3+
using System.Runtime.CompilerServices;
34
using System.Text.Json.Serialization;
45

56
namespace Diffuse.Common
@@ -12,12 +13,17 @@ public record ExtractHistory : IHistoryItem
1213
public MediaType MediaType { get; init; }
1314
public DateTime Timestamp { get; init; }
1415
public string Extension { get; init; }
15-
16+
public string Model { get; init; }
1617
public int Width { get; init; }
1718
public int Height { get; init; }
18-
public string Model { get; init; }
19-
public ExtractInputOptions Options { get; init; }
2019

20+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
21+
public float FrameRate { get; init; }
22+
23+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
24+
public int FrameCount { get; init; }
25+
public ExtractorType ExtractorType { get; init; }
26+
public ExtractInputOptions Options { get; init; }
2127

2228
[JsonIgnore]
2329
public string FilePath { get; set; }
@@ -27,5 +33,8 @@ public record ExtractHistory : IHistoryItem
2733

2834
[JsonIgnore]
2935
public string ThumbPath { get; set; }
36+
37+
public virtual bool Equals(ExtractHistory other) => ReferenceEquals(this, other);
38+
public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
3039
}
3140
}

DiffuseApp/DiffuseApp/Common/HistoryItem.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Diffuse.Views;
22
using System;
3+
using System.Runtime.CompilerServices;
34
using System.Text.Json.Serialization;
45

56
namespace Diffuse.Common
@@ -12,8 +13,11 @@ public interface IHistoryItem
1213
MediaType MediaType { get; init; }
1314
DateTime Timestamp { get; init; }
1415
string Extension { get; init; }
16+
string Model { get; init; }
1517
int Width { get; init; }
1618
int Height { get; init; }
19+
float FrameRate { get; init; }
20+
int FrameCount { get; init; }
1721

1822
string FilePath { get; set; }
1923
string MediaPath { get; set; }
@@ -30,9 +34,17 @@ public record RecentHistory : IHistoryItem
3034
public MediaType MediaType { get; init; }
3135
public DateTime Timestamp { get; init; }
3236
public string Extension { get; init; }
37+
public string Model { get; init; }
3338
public int Width { get; init; }
3439
public int Height { get; init; }
3540

41+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
42+
public float FrameRate { get; init; }
43+
44+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
45+
public int FrameCount { get; init; }
46+
47+
3648
[JsonIgnore]
3749
public string FilePath { get; set; }
3850

@@ -41,5 +53,8 @@ public record RecentHistory : IHistoryItem
4153

4254
[JsonIgnore]
4355
public string ThumbPath { get; set; }
56+
57+
public virtual bool Equals(RecentHistory other) => ReferenceEquals(this, other);
58+
public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
4459
}
4560
}

DiffuseApp/DiffuseApp/Common/InterpolateHistory.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Diffuse.Views;
22
using System;
3+
using System.Runtime.CompilerServices;
34
using System.Text.Json.Serialization;
45

56
namespace Diffuse.Common
@@ -13,11 +14,17 @@ public record InterpolateHistory : IHistoryItem
1314
public DateTime Timestamp { get; init; }
1415
public string Extension { get; init; }
1516

17+
public string Model { get; init; } = "Interpolation";
1618
public int Width { get; init; }
1719
public int Height { get; init; }
18-
public float FrameRate { get; set; }
19-
public float OriginalFrameRate { get; set; }
20+
21+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22+
public float FrameRate { get; init; }
23+
24+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
25+
public int FrameCount { get; init; }
2026
public int Multiplier { get; init; }
27+
public float OriginalFrameRate { get; set; }
2128

2229
[JsonIgnore]
2330
public string FilePath { get; set; }
@@ -27,5 +34,8 @@ public record InterpolateHistory : IHistoryItem
2734

2835
[JsonIgnore]
2936
public string ThumbPath { get; set; }
37+
38+
public virtual bool Equals(InterpolateHistory other) => ReferenceEquals(this, other);
39+
public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
3040
}
3141
}

DiffuseApp/DiffuseApp/Common/UpscaleHistory.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Diffuse.Views;
22
using System;
3+
using System.Runtime.CompilerServices;
34
using System.Text.Json.Serialization;
45

56
namespace Diffuse.Common
@@ -13,15 +14,24 @@ public record UpscaleHistory : IHistoryItem
1314
public DateTime Timestamp { get; init; }
1415
public string Extension { get; init; }
1516

17+
public string Model { get; init; }
18+
1619
public int Width { get; init; }
1720
public int Height { get; init; }
21+
22+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
23+
public float FrameRate { get; init; }
24+
25+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
26+
public int FrameCount { get; init; }
27+
1828
public int ScaleFactor { get; init; }
1929
public int OriginalWidth { get; init; }
2030
public int OriginalHeight { get; init; }
21-
public string Model { get; init; }
31+
2232
public UpscaleInputOptions Options { get; init; }
2333

24-
34+
2535
[JsonIgnore]
2636
public string FilePath { get; set; }
2737

@@ -30,5 +40,8 @@ public record UpscaleHistory : IHistoryItem
3040

3141
[JsonIgnore]
3242
public string ThumbPath { get; set; }
43+
44+
public virtual bool Equals(UpscaleHistory other) => ReferenceEquals(this, other);
45+
public override int GetHashCode() => RuntimeHelpers.GetHashCode(this);
3346
}
3447
}

DiffuseApp/DiffuseApp/Controls/DiffusionInputControl.xaml.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@ public DiffusionInputControl()
2525
{
2626
SeedCommand = new RelayCommand<bool>(GenerateSeed);
2727
AddTriggerWordCommand = new AsyncRelayCommand<string>(AddTriggerWordAsync);
28-
// DefaultResolutions = [.. Enumerable.Range(4, 24).Select(x => 64 * x)];
2928
InitializeComponent();
3029
}
3130

32-
33-
3431
public static readonly DependencyProperty PipelineProperty = DependencyProperty.Register(nameof(Pipeline), typeof(PipelineModel), typeof(DiffusionInputControl), new PropertyMetadata<DiffusionInputControl, PipelineModel>((c, o, n) => c.OnPipelineChanged(o, n)));
3532
public static readonly DependencyProperty OptionsProperty = DependencyProperty.Register(nameof(Options), typeof(DiffusionInputOptions), typeof(DiffusionInputControl), new PropertyMetadata<DiffusionInputControl, DiffusionInputOptions>((c, o, n) => c.OnOptionsChanged(o, n)));
3633
public static readonly DependencyProperty UpscaleOptionsProperty = DependencyProperty.Register(nameof(UpscaleOptions), typeof(UpscaleInputOptions), typeof(DiffusionInputControl));
3734
public static readonly DependencyProperty ExtractOptionsProperty = DependencyProperty.Register(nameof(ExtractOptions), typeof(ExtractInputOptions), typeof(DiffusionInputControl));
38-
private HashSet<int> _defaultResolutions;
39-
4035

4136
public ProcessType ProcessType { get; set; }
4237
public RelayCommand<bool> SeedCommand { get; }
@@ -56,27 +51,16 @@ public DiffusionInputOptions Options
5651

5752
public UpscaleInputOptions UpscaleOptions
5853
{
59-
6054
get { return (UpscaleInputOptions)GetValue(UpscaleOptionsProperty); }
6155
set { SetValue(UpscaleOptionsProperty, value); }
6256
}
6357

6458
public ExtractInputOptions ExtractOptions
6559
{
66-
6760
get { return (ExtractInputOptions)GetValue(ExtractOptionsProperty); }
6861
set { SetValue(ExtractOptionsProperty, value); }
6962
}
7063

71-
72-
73-
74-
//public HashSet<int> DefaultResolutions
75-
//{
76-
// get { return _defaultResolutions; }
77-
// set { SetProperty(ref _defaultResolutions, value); }
78-
//}
79-
8064
public SchedulerType[] Schedulers
8165
{
8266
get { return _schedulers; }
@@ -125,9 +109,6 @@ public SizeOption SelectedResolution
125109
}
126110

127111

128-
129-
130-
131112
private Task OnPipelineChanged(PipelineModel oldPipeline, PipelineModel newPipeline)
132113
{
133114
if (newPipeline is null || newPipeline.DiffusionModel is null)

0 commit comments

Comments
 (0)