Ionite
1 year ago
committed by
GitHub
271 changed files with 9458 additions and 2400 deletions
@ -0,0 +1,27 @@
|
||||
name: UI Tests |
||||
|
||||
on: |
||||
workflow_dispatch: |
||||
|
||||
concurrency: |
||||
group: build-${{ github.event.pull_request.number || github.ref }} |
||||
cancel-in-progress: true |
||||
|
||||
jobs: |
||||
build: |
||||
if: github.repository == 'LykosAI/StabilityMatrix' || github.event_name == 'workflow_dispatch' |
||||
runs-on: windows-latest |
||||
|
||||
steps: |
||||
- uses: actions/checkout@v3 |
||||
|
||||
- name: Set up .NET |
||||
uses: actions/setup-dotnet@v3 |
||||
with: |
||||
dotnet-version: '7.0.x' |
||||
|
||||
- name: Install dependencies |
||||
run: dotnet restore |
||||
|
||||
- name: Test |
||||
run: dotnet test StabilityMatrix.UITests |
@ -1,9 +1,7 @@
|
||||
using Avalonia; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.Primitives; |
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
public class BatchSizeCard : TemplatedControl |
||||
{ |
||||
} |
||||
[Transient] |
||||
public class BatchSizeCard : TemplatedControl { } |
||||
|
@ -1,5 +1,7 @@
|
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
[Transient] |
||||
public class FreeUCard : TemplatedControl { } |
||||
|
@ -1,7 +1,7 @@
|
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
public class ImageGalleryCard : TemplatedControl |
||||
{ |
||||
} |
||||
[Transient] |
||||
public class ImageGalleryCard : TemplatedControl { } |
||||
|
@ -1,9 +1,7 @@
|
||||
using Avalonia; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.Primitives; |
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
public class ModelCard : TemplatedControl |
||||
{ |
||||
} |
||||
[Transient] |
||||
public class ModelCard : TemplatedControl { } |
||||
|
@ -1,7 +1,7 @@
|
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
public class SamplerCard : TemplatedControl |
||||
{ |
||||
} |
||||
[Transient] |
||||
public class SamplerCard : TemplatedControl { } |
||||
|
@ -0,0 +1,14 @@
|
||||
using Avalonia.Controls.Presenters; |
||||
using Avalonia.Input; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls.Scroll; |
||||
|
||||
public class BetterScrollContentPresenter : ScrollContentPresenter |
||||
{ |
||||
protected override void OnPointerWheelChanged(PointerWheelEventArgs e) |
||||
{ |
||||
if (e.KeyModifiers == KeyModifiers.Control) |
||||
return; |
||||
base.OnPointerWheelChanged(e); |
||||
} |
||||
} |
@ -0,0 +1,69 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:scroll="clr-namespace:StabilityMatrix.Avalonia.Controls.Scroll"> |
||||
<Design.PreviewWith> |
||||
<scroll:BetterScrollViewer Width="200" Height="200" |
||||
HorizontalScrollBarVisibility="Auto"> |
||||
<StackPanel Spacing="20" Width="210"> |
||||
<TextBlock>Item 1</TextBlock> |
||||
<TextBlock>Item 2</TextBlock> |
||||
<TextBlock>Item 3</TextBlock> |
||||
<TextBlock>Item 4</TextBlock> |
||||
<TextBlock>Item 5</TextBlock> |
||||
<TextBlock>Item 6</TextBlock> |
||||
<TextBlock>Item 7</TextBlock> |
||||
<TextBlock>Item 8</TextBlock> |
||||
<TextBlock>Item 9</TextBlock> |
||||
</StackPanel> |
||||
</scroll:BetterScrollViewer> |
||||
</Design.PreviewWith> |
||||
|
||||
<ControlTheme x:Key="{x:Type scroll:BetterScrollViewer}" TargetType="scroll:BetterScrollViewer"> |
||||
<Setter Property="Background" Value="Transparent" /> |
||||
<Setter Property="Template"> |
||||
<ControlTemplate> |
||||
<Grid ColumnDefinitions="*,Auto" RowDefinitions="*,Auto"> |
||||
<scroll:BetterScrollContentPresenter x:Name="PART_ContentPresenter" |
||||
Grid.Row="0" |
||||
Grid.Column="0" |
||||
Grid.RowSpan="2" |
||||
Grid.ColumnSpan="2" |
||||
Background="{TemplateBinding Background}" |
||||
HorizontalSnapPointsType="{TemplateBinding HorizontalSnapPointsType}" |
||||
VerticalSnapPointsType="{TemplateBinding VerticalSnapPointsType}" |
||||
HorizontalSnapPointsAlignment="{TemplateBinding HorizontalSnapPointsAlignment}" |
||||
VerticalSnapPointsAlignment="{TemplateBinding VerticalSnapPointsAlignment}" |
||||
Padding="{TemplateBinding Padding}" |
||||
ScrollViewer.IsScrollInertiaEnabled="{TemplateBinding IsScrollInertiaEnabled}"> |
||||
<scroll:BetterScrollContentPresenter.GestureRecognizers> |
||||
<ScrollGestureRecognizer |
||||
CanHorizontallyScroll="{Binding CanHorizontallyScroll, ElementName=PART_ContentPresenter}" |
||||
CanVerticallyScroll="{Binding CanVerticallyScroll, ElementName=PART_ContentPresenter}" |
||||
IsScrollInertiaEnabled="{Binding (ScrollViewer.IsScrollInertiaEnabled), ElementName=PART_ContentPresenter}" /> |
||||
</scroll:BetterScrollContentPresenter.GestureRecognizers> |
||||
</scroll:BetterScrollContentPresenter> |
||||
<ScrollBar Name="PART_HorizontalScrollBar" |
||||
Orientation="Horizontal" |
||||
Grid.Row="1" /> |
||||
<ScrollBar Name="PART_VerticalScrollBar" |
||||
Orientation="Vertical" |
||||
Grid.Column="1" /> |
||||
<Panel x:Name="PART_ScrollBarsSeparator" |
||||
Grid.Row="1" |
||||
Grid.Column="1" |
||||
Background="{DynamicResource ScrollViewerScrollBarsSeparatorBackground}" |
||||
Opacity="0"> |
||||
<Panel.Transitions> |
||||
<Transitions> |
||||
<DoubleTransition Property="Opacity" Duration="0:0:0.1" /> |
||||
</Transitions> |
||||
</Panel.Transitions> |
||||
</Panel> |
||||
</Grid> |
||||
</ControlTemplate> |
||||
</Setter> |
||||
<Style Selector="^[IsExpanded=true] /template/ Panel#PART_ScrollBarsSeparator"> |
||||
<Setter Property="Opacity" Value="1" /> |
||||
</Style> |
||||
</ControlTheme> |
||||
</ResourceDictionary> |
@ -0,0 +1,5 @@
|
||||
using Avalonia.Controls; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls.Scroll; |
||||
|
||||
public class BetterScrollViewer : ScrollViewer { } |
@ -1,7 +1,7 @@
|
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
public class SeedCard : TemplatedControl |
||||
{ |
||||
} |
||||
[Transient] |
||||
public class SeedCard : TemplatedControl { } |
||||
|
@ -1,3 +1,6 @@
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
[Transient] |
||||
public class SelectImageCard : DropTargetTemplatedControlBase { } |
||||
|
@ -0,0 +1,51 @@
|
||||
<Styles xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:selectableImageCard="clr-namespace:StabilityMatrix.Avalonia.Controls.SelectableImageCard" |
||||
xmlns:controls="clr-namespace:StabilityMatrix.Avalonia.Controls"> |
||||
<Design.PreviewWith> |
||||
<Border Padding="20"> |
||||
<!-- Add Controls for Previewer Here --> |
||||
<selectableImageCard:SelectableImageButton |
||||
Source="https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/78fd2a0a-42b6-42b0-9815-81cb11bb3d05/00009-2423234823.jpeg" /> |
||||
</Border> |
||||
</Design.PreviewWith> |
||||
|
||||
<!-- Add Styles Here --> |
||||
<Style Selector="selectableImageCard|SelectableImageButton"> |
||||
<Setter Property="Template"> |
||||
<ControlTemplate> |
||||
<Grid |
||||
Width="{Binding ImageWidth, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" |
||||
Height="{Binding ImageHeight, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"> |
||||
<CheckBox VerticalAlignment="Top" |
||||
HorizontalAlignment="Right" |
||||
Margin="14,8" |
||||
Padding="0" |
||||
IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" |
||||
ZIndex="100"> |
||||
<CheckBox.RenderTransform> |
||||
<ScaleTransform ScaleX="1.5" ScaleY="1.5" /> |
||||
</CheckBox.RenderTransform> |
||||
<CheckBox.Styles> |
||||
<Style Selector="CheckBox"> |
||||
<Setter Property="CornerRadius" Value="16" /> |
||||
</Style> |
||||
</CheckBox.Styles> |
||||
</CheckBox> |
||||
<Button |
||||
Margin="0" |
||||
Padding="4" |
||||
CornerRadius="12" |
||||
Command="{TemplateBinding Command}" |
||||
CommandParameter="{TemplateBinding CommandParameter}"> |
||||
<controls:BetterAdvancedImage |
||||
Stretch="UniformToFill" |
||||
CornerRadius="8" |
||||
ContextFlyout="{TemplateBinding ContextFlyout}" |
||||
Source="{TemplateBinding Source}" /> |
||||
</Button> |
||||
</Grid> |
||||
</ControlTemplate> |
||||
</Setter> |
||||
</Style> |
||||
</Styles> |
@ -0,0 +1,56 @@
|
||||
using System; |
||||
using AsyncImageLoader; |
||||
using Avalonia; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.Primitives; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls.SelectableImageCard; |
||||
|
||||
public class SelectableImageButton : Button |
||||
{ |
||||
public static readonly StyledProperty<bool?> IsSelectedProperty = |
||||
ToggleButton.IsCheckedProperty.AddOwner<SelectableImageButton>(); |
||||
|
||||
public static readonly StyledProperty<string?> SourceProperty = |
||||
AdvancedImage.SourceProperty.AddOwner<SelectableImageButton>(); |
||||
|
||||
public static readonly StyledProperty<double> ImageWidthProperty = AvaloniaProperty.Register< |
||||
SelectableImageButton, |
||||
double |
||||
>("ImageWidth", 300); |
||||
|
||||
public static readonly StyledProperty<double> ImageHeightProperty = AvaloniaProperty.Register< |
||||
SelectableImageButton, |
||||
double |
||||
>("ImageHeight", 300); |
||||
|
||||
static SelectableImageButton() |
||||
{ |
||||
AffectsRender<SelectableImageButton>(ImageWidthProperty, ImageHeightProperty); |
||||
AffectsArrange<SelectableImageButton>(ImageWidthProperty, ImageHeightProperty); |
||||
} |
||||
|
||||
public double ImageHeight |
||||
{ |
||||
get => GetValue(ImageHeightProperty); |
||||
set => SetValue(ImageHeightProperty, value); |
||||
} |
||||
|
||||
public double ImageWidth |
||||
{ |
||||
get => GetValue(ImageWidthProperty); |
||||
set => SetValue(ImageWidthProperty, value); |
||||
} |
||||
|
||||
public bool? IsSelected |
||||
{ |
||||
get => GetValue(IsSelectedProperty); |
||||
set => SetValue(IsSelectedProperty, value); |
||||
} |
||||
|
||||
public string? Source |
||||
{ |
||||
get => GetValue(SourceProperty); |
||||
set => SetValue(SourceProperty, value); |
||||
} |
||||
} |
@ -1,7 +1,7 @@
|
||||
using Avalonia; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Controls.Primitives; |
||||
using Avalonia.Controls.Primitives; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
[Transient] |
||||
public class SharpenCard : TemplatedControl { } |
||||
|
@ -1,12 +0,0 @@
|
||||
using System; |
||||
using StabilityMatrix.Core.Api; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockApiFactory : IApiFactory |
||||
{ |
||||
public T CreateRefitClient<T>(Uri baseAddress) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
@ -1,18 +0,0 @@
|
||||
using System; |
||||
using StabilityMatrix.Avalonia.Services; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockDiscordRichPresenceService : IDiscordRichPresenceService |
||||
{ |
||||
/// <inheritdoc /> |
||||
public void Dispose() |
||||
{ |
||||
GC.SuppressFinalize(this); |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
public void UpdateState() |
||||
{ |
||||
} |
||||
} |
@ -1,50 +0,0 @@
|
||||
using System; |
||||
using System.IO; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockDownloadService : IDownloadService |
||||
{ |
||||
public Task DownloadToFileAsync( |
||||
string downloadUrl, |
||||
string downloadPath, |
||||
IProgress<ProgressReport>? progress = null, |
||||
string? httpClientName = null, |
||||
CancellationToken cancellationToken = default |
||||
) |
||||
{ |
||||
return Task.CompletedTask; |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
public Task ResumeDownloadToFileAsync( |
||||
string downloadUrl, |
||||
string downloadPath, |
||||
long existingFileSize, |
||||
IProgress<ProgressReport>? progress = null, |
||||
string? httpClientName = null, |
||||
CancellationToken cancellationToken = default |
||||
) |
||||
{ |
||||
return Task.CompletedTask; |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
public Task<long> GetFileSizeAsync( |
||||
string downloadUrl, |
||||
string? httpClientName = null, |
||||
CancellationToken cancellationToken = default |
||||
) |
||||
{ |
||||
return Task.FromResult(0L); |
||||
} |
||||
|
||||
public Task<Stream?> GetImageStreamFromUrl(string url) |
||||
{ |
||||
return Task.FromResult(new MemoryStream(new byte[24]) as Stream)!; |
||||
} |
||||
} |
@ -1,12 +0,0 @@
|
||||
using System; |
||||
using System.Net.Http; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockHttpClientFactory : IHttpClientFactory |
||||
{ |
||||
public HttpClient CreateClient(string name) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
@ -1,62 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
||||
using LiteDB.Async; |
||||
using StabilityMatrix.Core.Database; |
||||
using StabilityMatrix.Core.Models.Api; |
||||
using StabilityMatrix.Core.Models.Database; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockLiteDbContext : ILiteDbContext |
||||
{ |
||||
public LiteDatabaseAsync Database => throw new NotImplementedException(); |
||||
public ILiteCollectionAsync<CivitModel> CivitModels => throw new NotImplementedException(); |
||||
public ILiteCollectionAsync<CivitModelVersion> CivitModelVersions => |
||||
throw new NotImplementedException(); |
||||
public ILiteCollectionAsync<CivitModelQueryCacheEntry> CivitModelQueryCache => |
||||
throw new NotImplementedException(); |
||||
public ILiteCollectionAsync<LocalModelFile> LocalModelFiles => |
||||
throw new NotImplementedException(); |
||||
public ILiteCollectionAsync<InferenceProjectEntry> InferenceProjects => |
||||
throw new NotImplementedException(); |
||||
public ILiteCollectionAsync<LocalImageFile> LocalImageFiles => |
||||
throw new NotImplementedException(); |
||||
|
||||
public Task<(CivitModel?, CivitModelVersion?)> FindCivitModelFromFileHashAsync( |
||||
string hashBlake3 |
||||
) |
||||
{ |
||||
return Task.FromResult<(CivitModel?, CivitModelVersion?)>((null, null)); |
||||
} |
||||
|
||||
public Task<bool> UpsertCivitModelAsync(CivitModel civitModel) |
||||
{ |
||||
return Task.FromResult(true); |
||||
} |
||||
|
||||
public Task<bool> UpsertCivitModelAsync(IEnumerable<CivitModel> civitModels) |
||||
{ |
||||
return Task.FromResult(true); |
||||
} |
||||
|
||||
public Task<bool> UpsertCivitModelQueryCacheEntryAsync(CivitModelQueryCacheEntry entry) |
||||
{ |
||||
return Task.FromResult(true); |
||||
} |
||||
|
||||
public Task<GithubCacheEntry?> GetGithubCacheEntry(string cacheKey) |
||||
{ |
||||
return Task.FromResult<GithubCacheEntry?>(null); |
||||
} |
||||
|
||||
public Task<bool> UpsertGithubCacheEntry(GithubCacheEntry cacheEntry) |
||||
{ |
||||
return Task.FromResult(true); |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
GC.SuppressFinalize(this); |
||||
} |
||||
} |
@ -1,47 +0,0 @@
|
||||
using System; |
||||
using System.Threading.Tasks; |
||||
using Avalonia; |
||||
using Avalonia.Controls.Notifications; |
||||
using StabilityMatrix.Avalonia.Services; |
||||
using StabilityMatrix.Core.Models; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockNotificationService : INotificationService |
||||
{ |
||||
public void Initialize(Visual? visual, |
||||
NotificationPosition position = NotificationPosition.BottomRight, int maxItems = 3) |
||||
{ |
||||
} |
||||
|
||||
public void Show(INotification notification) |
||||
{ |
||||
} |
||||
|
||||
public Task<TaskResult<T>> TryAsync<T>(Task<T> task, string title = "Error", string? message = null, |
||||
NotificationType appearance = NotificationType.Error) |
||||
{ |
||||
return Task.FromResult(new TaskResult<T>(default!)); |
||||
} |
||||
|
||||
public Task<TaskResult<bool>> TryAsync(Task task, string title = "Error", string? message = null, |
||||
NotificationType appearance = NotificationType.Error) |
||||
{ |
||||
return Task.FromResult(new TaskResult<bool>(true)); |
||||
} |
||||
|
||||
public void Show( |
||||
string title, |
||||
string message, |
||||
NotificationType appearance = NotificationType.Information, |
||||
TimeSpan? expiration = null) |
||||
{ |
||||
} |
||||
|
||||
public void ShowPersistent( |
||||
string title, |
||||
string message, |
||||
NotificationType appearance = NotificationType.Information) |
||||
{ |
||||
} |
||||
} |
@ -1,26 +0,0 @@
|
||||
using System.Threading.Tasks; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
using StabilityMatrix.Core.Models.Packages; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockSharedFolders : ISharedFolders |
||||
{ |
||||
public void SetupLinksForPackage(BasePackage basePackage, DirectoryPath installDirectory) |
||||
{ |
||||
} |
||||
|
||||
public Task UpdateLinksForPackage(BasePackage basePackage, DirectoryPath installDirectory) |
||||
{ |
||||
return Task.CompletedTask; |
||||
} |
||||
|
||||
public void RemoveLinksForAllPackages() |
||||
{ |
||||
} |
||||
|
||||
public void SetupSharedModelFolders() |
||||
{ |
||||
} |
||||
} |
@ -1,22 +0,0 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using StabilityMatrix.Core.Models; |
||||
using StabilityMatrix.Core.Models.FileInterfaces; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Avalonia.DesignData; |
||||
|
||||
public class MockTrackedDownloadService : ITrackedDownloadService |
||||
{ |
||||
/// <inheritdoc /> |
||||
public IEnumerable<TrackedDownload> Downloads => Array.Empty<TrackedDownload>(); |
||||
|
||||
/// <inheritdoc /> |
||||
public event EventHandler<TrackedDownload>? DownloadAdded; |
||||
|
||||
/// <inheritdoc /> |
||||
public TrackedDownload NewDownload(Uri downloadUrl, FilePath downloadPath) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
using System; |
||||
using FuzzySharp; |
||||
using FuzzySharp.PreProcess; |
||||
using StabilityMatrix.Core.Models.Database; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Helpers; |
||||
|
||||
public class ImageSearcher |
||||
{ |
||||
public int MinimumFuzzScore { get; init; } = 80; |
||||
|
||||
public ImageSearchOptions SearchOptions { get; init; } = ImageSearchOptions.All; |
||||
|
||||
public Func<LocalImageFile, bool> GetPredicate(string? searchQuery) |
||||
{ |
||||
if (string.IsNullOrEmpty(searchQuery)) |
||||
{ |
||||
return _ => true; |
||||
} |
||||
|
||||
return file => |
||||
{ |
||||
if (file.FileName.Contains(searchQuery, StringComparison.OrdinalIgnoreCase)) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
if ( |
||||
SearchOptions.HasFlag(ImageSearchOptions.FileName) |
||||
&& Fuzz.WeightedRatio(searchQuery, file.FileName, PreprocessMode.Full) |
||||
> MinimumFuzzScore |
||||
) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
// Generation params |
||||
if (file.GenerationParameters is { } parameters) |
||||
{ |
||||
if ( |
||||
SearchOptions.HasFlag(ImageSearchOptions.PositivePrompt) |
||||
&& ( |
||||
parameters.PositivePrompt?.Contains( |
||||
searchQuery, |
||||
StringComparison.OrdinalIgnoreCase |
||||
) ?? false |
||||
) |
||||
|| SearchOptions.HasFlag(ImageSearchOptions.NegativePrompt) |
||||
&& ( |
||||
parameters.NegativePrompt?.Contains( |
||||
searchQuery, |
||||
StringComparison.OrdinalIgnoreCase |
||||
) ?? false |
||||
) |
||||
|| SearchOptions.HasFlag(ImageSearchOptions.Seed) |
||||
&& parameters.Seed |
||||
.ToString() |
||||
.StartsWith(searchQuery, StringComparison.OrdinalIgnoreCase) |
||||
|| SearchOptions.HasFlag(ImageSearchOptions.Sampler) |
||||
&& ( |
||||
parameters.Sampler?.StartsWith( |
||||
searchQuery, |
||||
StringComparison.OrdinalIgnoreCase |
||||
) ?? false |
||||
) |
||||
|| SearchOptions.HasFlag(ImageSearchOptions.ModelName) |
||||
&& ( |
||||
parameters.ModelName?.StartsWith( |
||||
searchQuery, |
||||
StringComparison.OrdinalIgnoreCase |
||||
) ?? false |
||||
) |
||||
) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
}; |
||||
} |
||||
|
||||
[Flags] |
||||
public enum ImageSearchOptions |
||||
{ |
||||
None = 0, |
||||
FileName = 1 << 0, |
||||
PositivePrompt = 1 << 1, |
||||
NegativePrompt = 1 << 2, |
||||
Seed = 1 << 3, |
||||
Sampler = 1 << 4, |
||||
ModelName = 1 << 5, |
||||
All = int.MaxValue |
||||
} |
||||
} |
@ -0,0 +1,72 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.Immutable; |
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Linq; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models.Inference; |
||||
|
||||
public record FileNameFormat |
||||
{ |
||||
public string Template { get; } |
||||
|
||||
public string Prefix { get; set; } = ""; |
||||
|
||||
public string Postfix { get; set; } = ""; |
||||
|
||||
public IReadOnlyList<FileNameFormatPart> Parts { get; } |
||||
|
||||
private FileNameFormat(string template, IReadOnlyList<FileNameFormatPart> parts) |
||||
{ |
||||
Template = template; |
||||
Parts = parts; |
||||
} |
||||
|
||||
public FileNameFormat WithBatchPostFix(int current, int total) |
||||
{ |
||||
return this with { Postfix = Postfix + $" ({current}-{total})" }; |
||||
} |
||||
|
||||
public FileNameFormat WithGridPrefix() |
||||
{ |
||||
return this with { Prefix = Prefix + "Grid_" }; |
||||
} |
||||
|
||||
public string GetFileName() |
||||
{ |
||||
return Prefix |
||||
+ string.Join( |
||||
"", |
||||
Parts.Select( |
||||
part => part.Match(constant => constant, substitution => substitution.Invoke()) |
||||
) |
||||
) |
||||
+ Postfix; |
||||
} |
||||
|
||||
public static FileNameFormat Parse(string template, FileNameFormatProvider provider) |
||||
{ |
||||
var parts = provider.GetParts(template).ToImmutableArray(); |
||||
return new FileNameFormat(template, parts); |
||||
} |
||||
|
||||
public static bool TryParse( |
||||
string template, |
||||
FileNameFormatProvider provider, |
||||
[NotNullWhen(true)] out FileNameFormat? format |
||||
) |
||||
{ |
||||
try |
||||
{ |
||||
format = Parse(template, provider); |
||||
return true; |
||||
} |
||||
catch (ArgumentException) |
||||
{ |
||||
format = null; |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public const string DefaultTemplate = "{date}_{time}-{model_name}-{seed}"; |
||||
} |
@ -0,0 +1,7 @@
|
||||
using System; |
||||
using OneOf; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models.Inference; |
||||
|
||||
[GenerateOneOf] |
||||
public partial class FileNameFormatPart : OneOfBase<string, Func<string?>> { } |
@ -0,0 +1,197 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel.DataAnnotations; |
||||
using System.Diagnostics.Contracts; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text.RegularExpressions; |
||||
using Avalonia.Data; |
||||
using StabilityMatrix.Core.Extensions; |
||||
using StabilityMatrix.Core.Models; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models.Inference; |
||||
|
||||
public partial class FileNameFormatProvider |
||||
{ |
||||
public GenerationParameters? GenerationParameters { get; init; } |
||||
|
||||
public InferenceProjectType? ProjectType { get; init; } |
||||
|
||||
public string? ProjectName { get; init; } |
||||
|
||||
private Dictionary<string, Func<string?>>? _substitutions; |
||||
|
||||
public Dictionary<string, Func<string?>> Substitutions => |
||||
_substitutions ??= new Dictionary<string, Func<string?>> |
||||
{ |
||||
{ "seed", () => GenerationParameters?.Seed.ToString() }, |
||||
{ "prompt", () => GenerationParameters?.PositivePrompt }, |
||||
{ "negative_prompt", () => GenerationParameters?.NegativePrompt }, |
||||
{ |
||||
"model_name", |
||||
() => Path.GetFileNameWithoutExtension(GenerationParameters?.ModelName) |
||||
}, |
||||
{ "model_hash", () => GenerationParameters?.ModelHash }, |
||||
{ "width", () => GenerationParameters?.Width.ToString() }, |
||||
{ "height", () => GenerationParameters?.Height.ToString() }, |
||||
{ "project_type", () => ProjectType?.GetStringValue() }, |
||||
{ "project_name", () => ProjectName }, |
||||
{ "date", () => DateTime.Now.ToString("yyyy-MM-dd") }, |
||||
{ "time", () => DateTime.Now.ToString("HH-mm-ss") } |
||||
}; |
||||
|
||||
/// <summary> |
||||
/// Validate a format string |
||||
/// </summary> |
||||
/// <param name="format">Format string</param> |
||||
/// <exception cref="DataValidationException">Thrown if the format string contains an unknown variable</exception> |
||||
[Pure] |
||||
public ValidationResult Validate(string format) |
||||
{ |
||||
var regex = BracketRegex(); |
||||
var matches = regex.Matches(format); |
||||
var variables = matches.Select(m => m.Groups[1].Value); |
||||
|
||||
foreach (var variableText in variables) |
||||
{ |
||||
try |
||||
{ |
||||
var (variable, _) = ExtractVariableAndSlice(variableText); |
||||
|
||||
if (!Substitutions.ContainsKey(variable)) |
||||
{ |
||||
return new ValidationResult($"Unknown variable '{variable}'"); |
||||
} |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
return new ValidationResult($"Invalid variable '{variableText}': {e.Message}"); |
||||
} |
||||
} |
||||
|
||||
return ValidationResult.Success!; |
||||
} |
||||
|
||||
public IEnumerable<FileNameFormatPart> GetParts(string template) |
||||
{ |
||||
var regex = BracketRegex(); |
||||
var matches = regex.Matches(template); |
||||
|
||||
var parts = new List<FileNameFormatPart>(); |
||||
|
||||
// Loop through all parts of the string, including matches and non-matches |
||||
var currentIndex = 0; |
||||
|
||||
foreach (var result in matches.Cast<Match>()) |
||||
{ |
||||
// If the match is not at the start of the string, add a constant part |
||||
if (result.Index != currentIndex) |
||||
{ |
||||
var constant = template[currentIndex..result.Index]; |
||||
parts.Add(constant); |
||||
|
||||
currentIndex += constant.Length; |
||||
} |
||||
|
||||
// Now we're at start of the current match, add the variable part |
||||
var (variable, slice) = ExtractVariableAndSlice(result.Groups[1].Value); |
||||
var substitution = Substitutions[variable]; |
||||
|
||||
// Slice string if necessary |
||||
if (slice is not null) |
||||
{ |
||||
parts.Add( |
||||
(FileNameFormatPart)( |
||||
() => |
||||
{ |
||||
var value = substitution(); |
||||
if (value is null) |
||||
return null; |
||||
|
||||
if (slice.End is null) |
||||
{ |
||||
value = value[(slice.Start ?? 0)..]; |
||||
} |
||||
else |
||||
{ |
||||
var length = |
||||
Math.Min(value.Length, slice.End.Value) - (slice.Start ?? 0); |
||||
value = value.Substring(slice.Start ?? 0, length); |
||||
} |
||||
|
||||
return value; |
||||
} |
||||
) |
||||
); |
||||
} |
||||
else |
||||
{ |
||||
parts.Add(substitution); |
||||
} |
||||
|
||||
currentIndex += result.Length; |
||||
} |
||||
|
||||
// Add remaining as constant |
||||
if (currentIndex != template.Length) |
||||
{ |
||||
var constant = template[currentIndex..]; |
||||
parts.Add(constant); |
||||
} |
||||
|
||||
return parts; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Return a sample provider for UI preview |
||||
/// </summary> |
||||
public static FileNameFormatProvider GetSample() |
||||
{ |
||||
return new FileNameFormatProvider |
||||
{ |
||||
GenerationParameters = GenerationParameters.GetSample(), |
||||
ProjectType = InferenceProjectType.TextToImage, |
||||
ProjectName = "Sample Project" |
||||
}; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Extract variable and index from a combined string |
||||
/// </summary> |
||||
private static (string Variable, Slice? Slice) ExtractVariableAndSlice(string combined) |
||||
{ |
||||
if (IndexRegex().Matches(combined).FirstOrDefault() is not { Success: true } match) |
||||
{ |
||||
return (combined, null); |
||||
} |
||||
|
||||
// Variable is everything before the match |
||||
var variable = combined[..match.Groups[0].Index]; |
||||
|
||||
var start = match.Groups["start"].Value; |
||||
var end = match.Groups["end"].Value; |
||||
var step = match.Groups["step"].Value; |
||||
|
||||
var slice = new Slice( |
||||
string.IsNullOrEmpty(start) ? null : int.Parse(start), |
||||
string.IsNullOrEmpty(end) ? null : int.Parse(end), |
||||
string.IsNullOrEmpty(step) ? null : int.Parse(step) |
||||
); |
||||
|
||||
return (variable, slice); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Regex for matching contents within a curly brace. |
||||
/// </summary> |
||||
[GeneratedRegex(@"\{([a-z_:\d\[\]]+)\}")]
|
||||
private static partial Regex BracketRegex(); |
||||
|
||||
/// <summary> |
||||
/// Regex for matching a Python-like array index. |
||||
/// </summary> |
||||
[GeneratedRegex(@"\[(?:(?<start>-?\d+)?)\:(?:(?<end>-?\d+)?)?(?:\:(?<step>-?\d+))?\]")]
|
||||
private static partial Regex IndexRegex(); |
||||
|
||||
private record Slice(int? Start, int? End, int? Step); |
||||
} |
@ -0,0 +1,8 @@
|
||||
namespace StabilityMatrix.Avalonia.Models.Inference; |
||||
|
||||
public record FileNameFormatVar |
||||
{ |
||||
public required string Variable { get; init; } |
||||
|
||||
public string? Example { get; init; } |
||||
} |
@ -0,0 +1,7 @@
|
||||
namespace StabilityMatrix.Avalonia.Models; |
||||
|
||||
public class PackageOutputCategory |
||||
{ |
||||
public required string Name { get; set; } |
||||
public required string Path { get; set; } |
||||
} |
@ -1,14 +1,17 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
using StabilityMatrix.Core.Attributes; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models; |
||||
|
||||
/// <summary> |
||||
/// Singleton DI service for observable shared UI state. |
||||
/// </summary> |
||||
[Singleton] |
||||
public partial class SharedState : ObservableObject |
||||
{ |
||||
/// <summary> |
||||
/// Whether debug mode enabled from settings page version tap. |
||||
/// </summary> |
||||
[ObservableProperty] private bool isDebugMode; |
||||
[ObservableProperty] |
||||
private bool isDebugMode; |
||||
} |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue