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

Commit 7646a91

Browse files
committed
Initial GUI commit
1 parent 2fcf7f9 commit 7646a91

Some content is hidden

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

45 files changed

+7749
-1
lines changed

OnnxStack.StableDiffusion/Config/SchedulerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class SchedulerOptions
4040
/// The number of steps to run inference for. The more steps the longer it will take to run the inference loop but the image quality should improve.
4141
/// </value>
4242
[Range(5, 200)]
43-
public int InferenceSteps { get; set; } = 15;
43+
public int InferenceSteps { get; set; } = 30;
4444

4545
/// <summary>
4646
/// Gets or sets the guidance scale.

OnnxStack.UI/App.xaml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<Application x:Class="OnnxStack.UI.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:system="clr-namespace:System;assembly=mscorlib"
5+
xmlns:local="clr-namespace:OnnxStack.UI"
6+
xmlns:SD_Enums="clr-namespace:OnnxStack.StableDiffusion.Enums;assembly=OnnxStack.StableDiffusion"
7+
xmlns:userControls="clr-namespace:OnnxStack.UI.UserControls"
8+
xmlns:behaviors="clr-namespace:OnnxStack.UI.Behaviors"
9+
xmlns:models="clr-namespace:OnnxStack.UI.Models"
10+
xmlns:converters="clr-namespace:OnnxStack.UI.Converters">
11+
<Application.Resources>
12+
13+
<BitmapImage x:Key="PlaceholderImage" UriSource="/Images/placeholder.png" />
14+
15+
<FontFamily x:Key="FontAwesomeBrands">pack://application:,,,/Fonts/fa-brands-400.ttf#Font Awesome 5 Brands Regular</FontFamily>
16+
<FontFamily x:Key="FontAwesomeDuotone">pack://application:,,,/Fonts/fa-duotone-900.ttf#Font Awesome 5 Duotone Solid</FontFamily>
17+
<FontFamily x:Key="FontAwesomeLight">pack://application:,,,/Fonts/fa-light-300.ttf#Font Awesome 5 Pro Light</FontFamily>
18+
<FontFamily x:Key="FontAwesomeRegular">pack://application:,,,/Fonts/fa-regular-400.ttf#Font Awesome 5 Pro Regular</FontFamily>
19+
<FontFamily x:Key="FontAwesomeSolid">pack://application:,,,/Fonts/fa-solid-900.ttf#Font Awesome 5 Pro Solid</FontFamily>
20+
21+
22+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
23+
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" />
24+
<converters:InverseBoolConverter x:Key="InverseBoolConverter" />
25+
26+
<ObjectDataProvider x:Key="SchedulerType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
27+
<ObjectDataProvider.MethodParameters>
28+
<x:Type TypeName="SD_Enums:SchedulerType"/>
29+
</ObjectDataProvider.MethodParameters>
30+
</ObjectDataProvider>
31+
32+
<ObjectDataProvider x:Key="AlphaTransformType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
33+
<ObjectDataProvider.MethodParameters>
34+
<x:Type TypeName="SD_Enums:AlphaTransformType"/>
35+
</ObjectDataProvider.MethodParameters>
36+
</ObjectDataProvider>
37+
38+
<ObjectDataProvider x:Key="BetaScheduleType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
39+
<ObjectDataProvider.MethodParameters>
40+
<x:Type TypeName="SD_Enums:BetaScheduleType"/>
41+
</ObjectDataProvider.MethodParameters>
42+
</ObjectDataProvider>
43+
44+
<ObjectDataProvider x:Key="PredictionType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
45+
<ObjectDataProvider.MethodParameters>
46+
<x:Type TypeName="SD_Enums:PredictionType"/>
47+
</ObjectDataProvider.MethodParameters>
48+
</ObjectDataProvider>
49+
50+
<ObjectDataProvider x:Key="TimestepSpacingType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
51+
<ObjectDataProvider.MethodParameters>
52+
<x:Type TypeName="SD_Enums:TimestepSpacingType"/>
53+
</ObjectDataProvider.MethodParameters>
54+
</ObjectDataProvider>
55+
56+
<ObjectDataProvider x:Key="VarianceType" MethodName="GetValues" ObjectType="{x:Type system:Enum}">
57+
<ObjectDataProvider.MethodParameters>
58+
<x:Type TypeName="SD_Enums:VarianceType"/>
59+
</ObjectDataProvider.MethodParameters>
60+
</ObjectDataProvider>
61+
62+
63+
<!--TODO: Style dictionary for themeing-->
64+
<Style TargetType="{x:Type TextBox}">
65+
<Setter Property="Height" Value="24" />
66+
<Setter Property="Padding" Value="2,3,0,0" />
67+
</Style>
68+
69+
<Style TargetType="{x:Type ComboBox}">
70+
<Setter Property="Height" Value="24" />
71+
<Setter Property="Padding" Value="4,3,0,0" />
72+
73+
</Style>
74+
75+
76+
77+
78+
<Style x:Key="ImageResultListBoxItem" TargetType="ListBoxItem">
79+
<Setter Property="Margin" Value="2"/>
80+
<Setter Property="BorderThickness" Value="1" />
81+
<Setter Property="BorderBrush" Value="LightGray" />
82+
<Setter Property="Background" Value="WhiteSmoke"/>
83+
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
84+
<Setter Property="Template">
85+
<Setter.Value>
86+
<ControlTemplate TargetType="{x:Type ListBoxItem}">
87+
<Border Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
88+
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="{TemplateBinding Padding}" />
89+
</Border>
90+
</ControlTemplate>
91+
</Setter.Value>
92+
</Setter>
93+
</Style>
94+
95+
96+
<DataTemplate DataType="{x:Type models:ImageResult}">
97+
<DockPanel Width="200" Height="265" HorizontalAlignment="Center">
98+
<StackPanel DockPanel.Dock="Bottom" >
99+
<UniformGrid Columns="2" Rows="2" HorizontalAlignment="Center">
100+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
101+
<TextBlock Text="{Binding SchedulerType}" Margin="2,0,0,0"/>
102+
</StackPanel>
103+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
104+
<TextBlock Text="Steps:" Margin="2,0,0,0" FontSize="9" Opacity=".6" VerticalAlignment="Center" FontStyle="Italic"/>
105+
<TextBlock Text="{Binding SchedulerOptions.InferenceSteps}" Margin="2,0,0,0"/>
106+
</StackPanel>
107+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
108+
<TextBlock Text="Guidance:" Margin="2,0,0,0" FontSize="9" Opacity=".6" VerticalAlignment="Center" FontStyle="Italic"/>
109+
<TextBlock Text="{Binding SchedulerOptions.GuidanceScale}" Margin="2,0,0,0"/>
110+
</StackPanel>
111+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
112+
<TextBlock Text="Seed:" Margin="2,0,0,0" FontSize="9" Opacity=".6" VerticalAlignment="Center" FontStyle="Italic"/>
113+
<TextBlock Text="{Binding SchedulerOptions.Seed}" Margin="2,0,0,0" />
114+
</StackPanel>
115+
</UniformGrid>
116+
<UniformGrid Columns="6" Margin="0,2,0,2">
117+
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=SaveImageCommand}" CommandParameter="{Binding}">
118+
<userControls:FontAwesome Icon="&#xf0c7;" IconStyle="Light" Size="13" ToolTip="Save Image File"/>
119+
</Button>
120+
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=SaveBlueprintCommand}" CommandParameter="{Binding}" BorderThickness="0, 1">
121+
<userControls:FontAwesome Icon="&#xf121;" IconStyle="Light" Size="13" ToolTip="Save Blueprint File"/>
122+
</Button>
123+
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=NavigateTextToImageCommand}" CommandParameter="{Binding}">
124+
<userControls:FontAwesome Icon="&#xf15c;" IconStyle="Light" Size="13" ToolTip="Send To Text To Image"/>
125+
</Button>
126+
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=NavigateImageToImageCommand}" CommandParameter="{Binding}" BorderThickness="0, 1">
127+
<userControls:FontAwesome Icon="&#xf302;" IconStyle="Light" Size="13" ToolTip="Send To Image To Image"/>
128+
</Button>
129+
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=NavigateImageInpaintCommand}" CommandParameter="{Binding}" >
130+
<userControls:FontAwesome Icon="&#xf1fc;" IconStyle="Light" Size="13" ToolTip="Send To Image Inpaint"/>
131+
</Button>
132+
<Button Command="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Path=NavigateImageUpscaleCommand}" CommandParameter="{Binding}" Padding="2,2" BorderThickness="0,1,1,1">
133+
<userControls:FontAwesome Icon="&#xf065;" IconStyle="Light" Size="13" ToolTip="Send To Upscaler"/>
134+
</Button>
135+
</UniformGrid>
136+
</StackPanel>
137+
<Border Margin="0,2" BorderBrush="#c0c0c0" BorderThickness="1" Background="White" >
138+
<Image Source="{Binding Image}" DockPanel.Dock="Left" Stretch="Uniform" VerticalAlignment="Center" />
139+
</Border>
140+
</DockPanel>
141+
</DataTemplate>
142+
143+
144+
145+
146+
147+
</Application.Resources>
148+
</Application>

OnnxStack.UI/App.xaml.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Hosting;
3+
using Microsoft.Extensions.Logging;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Configuration;
7+
using System.Data;
8+
using System.Linq;
9+
using System.Threading.Tasks;
10+
using System.Windows;
11+
using OnnxStack.Core;
12+
using OnnxStack.UI.Services;
13+
using OnnxStack.UI.Dialogs;
14+
using System.Diagnostics;
15+
using System.Windows.Controls;
16+
using System.Windows.Threading;
17+
18+
namespace OnnxStack.UI
19+
{
20+
/// <summary>
21+
/// Interaction logic for App.xaml
22+
/// </summary>
23+
public partial class App : Application
24+
{
25+
private static IHost _applicationHost;
26+
private static ILogger<App> _logger;
27+
28+
public App()
29+
{
30+
var builder = Host.CreateApplicationBuilder();
31+
builder.Logging.ClearProviders();
32+
builder.Services.AddLogging((loggingBuilder) => loggingBuilder.SetMinimumLevel(LogLevel.Trace).AddWindowLogger());
33+
34+
// Add OnnxStackStableDiffusion
35+
builder.Services.AddOnnxStackStableDiffusion();
36+
37+
// Add Windows
38+
builder.Services.AddSingleton<MainWindow>();
39+
builder.Services.AddTransient<CropImageDialog>();
40+
builder.Services.AddSingleton<IDialogService, DialogService>();
41+
42+
// Build App
43+
_applicationHost = builder.Build();
44+
}
45+
46+
47+
public static T GetService<T>() => _applicationHost.Services.GetService<T>();
48+
49+
public static void UIInvoke(Action action, DispatcherPriority priority = DispatcherPriority.Render) => Current.Dispatcher.BeginInvoke(priority, action);
50+
51+
52+
/// <summary>
53+
/// Raises the <see cref="E:Startup" /> event.
54+
/// </summary>
55+
/// <param name="e">The <see cref="StartupEventArgs"/> instance containing the event data.</param>
56+
protected override async void OnStartup(StartupEventArgs e)
57+
{
58+
base.OnStartup(e);
59+
await _applicationHost.StartAsync();
60+
GetService<MainWindow>().Show();
61+
}
62+
63+
64+
/// <summary>
65+
/// Raises the <see cref="E:Exit" /> event.
66+
/// </summary>
67+
/// <param name="e">The <see cref="ExitEventArgs"/> instance containing the event data.</param>
68+
protected override async void OnExit(ExitEventArgs e)
69+
{
70+
await _applicationHost.StopAsync();
71+
base.OnExit(e);
72+
}
73+
}
74+
}

OnnxStack.UI/AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Windows;
3+
using System.Windows.Controls;
4+
using System.Windows.Media.Animation;
5+
6+
namespace OnnxStack.UI.Behaviors
7+
{
8+
public class SmoothProgressBarBehavior
9+
{
10+
public static double GetSmoothValue(DependencyObject obj)
11+
{
12+
return (double)obj.GetValue(SmoothValueProperty);
13+
}
14+
15+
public static void SetSmoothValue(DependencyObject obj, double value)
16+
{
17+
obj.SetValue(SmoothValueProperty, value);
18+
}
19+
20+
public static readonly DependencyProperty SmoothValueProperty =
21+
DependencyProperty.RegisterAttached("SmoothValue", typeof(double), typeof(SmoothProgressBarBehavior), new PropertyMetadata(0.0, changing));
22+
23+
private static void changing(DependencyObject d, DependencyPropertyChangedEventArgs e)
24+
{
25+
var anim = new DoubleAnimation((double)e.OldValue, (double)e.NewValue, new TimeSpan(0, 0, 0, 0, 200));
26+
(d as ProgressBar).BeginAnimation(ProgressBar.ValueProperty, anim, HandoffBehavior.Compose);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)