Ionite
1 year ago
27 changed files with 570 additions and 11 deletions
@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks; |
||||
using Refit; |
||||
using StabilityMatrix.Models.Api; |
||||
|
||||
namespace StabilityMatrix.Api; |
||||
|
||||
public interface ICivitApi |
||||
{ |
||||
[Get("/api/v1/models")] |
||||
Task<CivitModelsResponse> GetModels([Body] CivitModelsRequest request); |
||||
} |
@ -0,0 +1,34 @@
|
||||
<Page |
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}" |
||||
d:DataContext="{d:DesignInstance viewModels:CheckpointBrowserViewModel, |
||||
IsDesignTimeCreatable=True}" |
||||
d:DesignHeight="500" |
||||
d:DesignWidth="650" |
||||
mc:Ignorable="d" |
||||
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}" |
||||
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" |
||||
x:Class="StabilityMatrix.CheckpointBrowserPage" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:designData="clr-namespace:StabilityMatrix.DesignData" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:models="clr-namespace:StabilityMatrix.Models" |
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" |
||||
xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
|
||||
<Grid> |
||||
<TextBlock |
||||
FontSize="24" |
||||
HorizontalAlignment="Center" |
||||
Text="Imagine very nice UI here." |
||||
VerticalAlignment="Center" /> |
||||
<StackPanel Margin="16" Orientation="Vertical"> |
||||
<ui:TextBox PlaceholderText="Query" Text="{Binding SearchQuery, Mode=TwoWay}" /> |
||||
<ui:Button |
||||
Command="{Binding SearchModelsCommand}" |
||||
Content="Search" |
||||
Margin="0,16,0,0" /> |
||||
</StackPanel> |
||||
</Grid> |
||||
</Page> |
@ -0,0 +1,20 @@
|
||||
using System.Diagnostics; |
||||
using System.Threading; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows.Media.Effects; |
||||
using StabilityMatrix.ViewModels; |
||||
using Wpf.Ui.Controls; |
||||
|
||||
namespace StabilityMatrix; |
||||
|
||||
public partial class CheckpointBrowserPage : Page |
||||
{ |
||||
public CheckpointBrowserPage(CheckpointBrowserViewModel viewModel) |
||||
{ |
||||
InitializeComponent(); |
||||
DataContext = viewModel; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
|
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
[SuppressMessage("ReSharper", "InconsistentNaming")] |
||||
public enum CivitCommercialUse |
||||
{ |
||||
None, |
||||
Image, |
||||
Rent, |
||||
Sell |
||||
} |
@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitCreator |
||||
{ |
||||
[JsonPropertyName("username")] |
||||
public string Username { get; set; } |
||||
|
||||
[JsonPropertyName("image")] |
||||
public string? Image { get; set; } |
||||
} |
@ -0,0 +1,22 @@
|
||||
using System; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitFile |
||||
{ |
||||
[JsonPropertyName("sizeKb")] |
||||
public double SizeKb { get; set; } |
||||
|
||||
[JsonPropertyName("pickleScanResult")] |
||||
public string PickleScanResult { get; set; } |
||||
|
||||
[JsonPropertyName("virusScanResult")] |
||||
public string VirusScanResult { get; set; } |
||||
|
||||
[JsonPropertyName("scannedAt")] |
||||
public DateTime? ScannedAt { get; set; } |
||||
|
||||
[JsonPropertyName("metadata")] |
||||
public CivitFileMetadata Metadata { get; set; } |
||||
} |
@ -0,0 +1,15 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitFileMetadata |
||||
{ |
||||
[JsonPropertyName("fp")] |
||||
public CivitModelFpType? Fp { get; set; } |
||||
|
||||
[JsonPropertyName("size")] |
||||
public CivitModelSize? Size { get; set; } |
||||
|
||||
[JsonPropertyName("format")] |
||||
public CivitModelFormat? Format { get; set; } |
||||
} |
@ -0,0 +1,23 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitImage |
||||
{ |
||||
[JsonPropertyName("url")] |
||||
public string Url { get; set; } |
||||
|
||||
[JsonPropertyName("nsfw")] |
||||
public string Nsfw { get; set; } |
||||
|
||||
[JsonPropertyName("width")] |
||||
public int Width { get; set; } |
||||
|
||||
[JsonPropertyName("height")] |
||||
public int Height { get; set; } |
||||
|
||||
[JsonPropertyName("hash")] |
||||
public string Hash { get; set; } |
||||
|
||||
// TODO: "meta" ( object? ) |
||||
} |
@ -0,0 +1,25 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
|
||||
public class CivitMetadata |
||||
{ |
||||
[JsonPropertyName("totalItems")] |
||||
public int TotalItems { get; set; } |
||||
|
||||
[JsonPropertyName("currentPage")] |
||||
public int CurrentPage { get; set; } |
||||
|
||||
[JsonPropertyName("pageSize")] |
||||
public int PageSize { get; set; } |
||||
|
||||
[JsonPropertyName("totalPages")] |
||||
public int TotalPages { get; set; } |
||||
|
||||
[JsonPropertyName("nextPage")] |
||||
public string? NextPage { get; set; } |
||||
|
||||
[JsonPropertyName("prevPage")] |
||||
public string? PrevPage { get; set; } |
||||
} |
@ -0,0 +1,10 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
public enum CivitMode |
||||
{ |
||||
Archived, |
||||
TakenDown |
||||
} |
@ -0,0 +1,36 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitModel |
||||
{ |
||||
[JsonPropertyName("id")] |
||||
public int Id { get; set; } |
||||
|
||||
[JsonPropertyName("name")] |
||||
public string Name { get; set; } |
||||
|
||||
[JsonPropertyName("description")] |
||||
public string Description { get; set; } |
||||
|
||||
[JsonPropertyName("type")] |
||||
public CivitModelType Type { get; set; } |
||||
|
||||
[JsonPropertyName("nsfw")] |
||||
public bool Nsfw { get; set; } |
||||
|
||||
[JsonPropertyName("tags")] |
||||
public string[] Tags { get; set; } |
||||
|
||||
[JsonPropertyName("mode")] |
||||
public CivitMode? Mode { get; set; } |
||||
|
||||
[JsonPropertyName("creator")] |
||||
public CivitCreator Creator { get; set; } |
||||
|
||||
[JsonPropertyName("stats")] |
||||
public CivitModelStats Stats { get; set; } |
||||
|
||||
[JsonPropertyName("modelVersions")] |
||||
public CivitModelVersion[] ModelVersions { get; set; } |
||||
} |
@ -0,0 +1,14 @@
|
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
[SuppressMessage("ReSharper", "InconsistentNaming")] |
||||
public enum CivitModelFormat |
||||
{ |
||||
SafeTensor, |
||||
PickleTensor, |
||||
Other |
||||
} |
@ -0,0 +1,13 @@
|
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
[SuppressMessage("ReSharper", "InconsistentNaming")] |
||||
public enum CivitModelFpType |
||||
{ |
||||
fp16, |
||||
fp32 |
||||
} |
@ -0,0 +1,12 @@
|
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
[SuppressMessage("ReSharper", "InconsistentNaming")] |
||||
public enum CivitModelSize |
||||
{ |
||||
full, |
||||
pruned, |
||||
} |
@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitModelStats : CivitStats |
||||
{ |
||||
[JsonPropertyName("favoriteCount")] |
||||
public int FavoriteCount { get; set; } |
||||
|
||||
[JsonPropertyName("commentCount")] |
||||
public int CommentCount { get; set; } |
||||
} |
@ -0,0 +1,17 @@
|
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
[SuppressMessage("ReSharper", "InconsistentNaming")] |
||||
public enum CivitModelType |
||||
{ |
||||
Checkpoint, |
||||
TextualInversion, |
||||
Hypernetwork, |
||||
AestheticGradient, |
||||
LORA, |
||||
Controlnet, |
||||
Poses |
||||
} |
@ -0,0 +1,34 @@
|
||||
using System; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitModelVersion |
||||
{ |
||||
[JsonPropertyName("id")] |
||||
public int Id { get; set; } |
||||
|
||||
[JsonPropertyName("name")] |
||||
public string Name { get; set; } |
||||
|
||||
[JsonPropertyName("description")] |
||||
public string Description { get; set; } |
||||
|
||||
[JsonPropertyName("createdAt")] |
||||
public DateTime CreatedAt { get; set; } |
||||
|
||||
[JsonPropertyName("downloadUrl")] |
||||
public string DownloadUrl { get; set; } |
||||
|
||||
[JsonPropertyName("trainedWords")] |
||||
public string[] TrainedWords { get; set; } |
||||
|
||||
[JsonPropertyName("files")] |
||||
public CivitFile[] Files { get; set; } |
||||
|
||||
[JsonPropertyName("images")] |
||||
public CivitImage[] Images { get; set; } |
||||
|
||||
[JsonPropertyName("stats")] |
||||
public CivitModelStats Stats { get; set; } |
||||
} |
@ -0,0 +1,105 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
|
||||
public class CivitModelsRequest |
||||
{ |
||||
/// <summary> |
||||
/// The number of results to be returned per page. This can be a number between 1 and 200. By default, each page will return 100 results |
||||
/// </summary> |
||||
[JsonPropertyName("limit")] |
||||
public int? Limit { get; set; } |
||||
|
||||
/// <summary> |
||||
/// The page from which to start fetching models |
||||
/// </summary> |
||||
[JsonPropertyName("page")] |
||||
public int? Page { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Search query to filter models by name |
||||
/// </summary> |
||||
[JsonPropertyName("query")] |
||||
public string? Query { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Search query to filter models by tag |
||||
/// </summary> |
||||
[JsonPropertyName("tag")] |
||||
public string? Tag { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Search query to filter models by user |
||||
/// </summary> |
||||
[JsonPropertyName("username")] |
||||
public string? Username { get; set; } |
||||
|
||||
/// <summary> |
||||
/// The type of model you want to filter with. If none is specified, it will return all types |
||||
/// </summary> |
||||
[JsonPropertyName("types")] |
||||
public CivitModelType[]? Types { get; set; } |
||||
|
||||
/// <summary> |
||||
/// The order in which you wish to sort the results |
||||
/// </summary> |
||||
[JsonPropertyName("sort")] |
||||
public CivitSortMode? Sort { get; set; } |
||||
|
||||
/// <summary> |
||||
/// The time frame in which the models will be sorted |
||||
/// </summary> |
||||
[JsonPropertyName("period")] |
||||
public CivitPeriod? Period { get; set; } |
||||
|
||||
/// <summary> |
||||
/// The rating you wish to filter the models with. If none is specified, it will return models with any rating |
||||
/// </summary> |
||||
[JsonPropertyName("rating")] |
||||
public int? Rating { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Filter to models that require or don't require crediting the creator |
||||
/// <remarks>Requires Authentication</remarks> |
||||
/// </summary> |
||||
[JsonPropertyName("favorites")] |
||||
public bool? Favorites { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Filter to hidden models of the authenticated user |
||||
/// <remarks>Requires Authentication</remarks> |
||||
/// </summary> |
||||
[JsonPropertyName("hidden")] |
||||
public bool? Hidden { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Only include the primary file for each model (This will use your preferred format options if you use an API token or session cookie) |
||||
/// </summary> |
||||
[JsonPropertyName("primaryFileOnly")] |
||||
public bool? PrimaryFileOnly { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Filter to models that allow or don't allow creating derivatives |
||||
/// </summary> |
||||
[JsonPropertyName("allowDerivatives")] |
||||
public bool? AllowDerivatives { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Filter to models that allow or don't allow derivatives to have a different license |
||||
/// </summary> |
||||
[JsonPropertyName("allowDifferentLicenses")] |
||||
public bool? AllowDifferentLicenses { get; set; } |
||||
|
||||
/// <summary> |
||||
/// Filter to models based on their commercial permissions |
||||
/// </summary> |
||||
[JsonPropertyName("allowCommercialUse")] |
||||
public CivitCommercialUse? AllowCommercialUse { get; set; } |
||||
|
||||
/// <summary> |
||||
/// If false, will return safer images and hide models that don't have safe images |
||||
/// </summary> |
||||
[JsonPropertyName("nsfw")] |
||||
public bool? Nsfw { get; set; } |
||||
} |
@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitModelsResponse |
||||
{ |
||||
[JsonPropertyName("items")] |
||||
public CivitModel[] Items { get; set; } |
||||
|
||||
[JsonPropertyName("metadata")] |
||||
public CivitMetadata Metadata { get; set; } |
||||
} |
@ -0,0 +1,13 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
public enum CivitPeriod |
||||
{ |
||||
AllTime, |
||||
Year, |
||||
Month, |
||||
Week, |
||||
Day |
||||
} |
@ -0,0 +1,16 @@
|
||||
using System.Diagnostics.CodeAnalysis; |
||||
using System.Runtime.Serialization; |
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))] |
||||
public enum CivitSortMode |
||||
{ |
||||
[EnumMember(Value = "Highest Rated")] |
||||
HighestRated, |
||||
[EnumMember(Value = "Most Downloaded")] |
||||
MostDownloaded, |
||||
[EnumMember(Value = "Newest")] |
||||
Newest |
||||
} |
@ -0,0 +1,15 @@
|
||||
using System.Text.Json.Serialization; |
||||
|
||||
namespace StabilityMatrix.Models.Api; |
||||
|
||||
public class CivitStats |
||||
{ |
||||
[JsonPropertyName("downloadCount")] |
||||
public int DownloadCount { get; set; } |
||||
|
||||
[JsonPropertyName("ratingCount")] |
||||
public int RatingCount { get; set; } |
||||
|
||||
[JsonPropertyName("rating")] |
||||
public double Rating { get; set; } |
||||
} |
@ -0,0 +1,41 @@
|
||||
using System.Threading.Tasks; |
||||
using CommunityToolkit.Mvvm.ComponentModel; |
||||
using CommunityToolkit.Mvvm.Input; |
||||
using NLog; |
||||
using StabilityMatrix.Api; |
||||
using StabilityMatrix.Models.Api; |
||||
|
||||
namespace StabilityMatrix.ViewModels; |
||||
|
||||
public partial class CheckpointBrowserViewModel : ObservableObject |
||||
{ |
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); |
||||
private readonly ICivitApi civitApi; |
||||
|
||||
[ObservableProperty] |
||||
private string? searchQuery; |
||||
|
||||
public CheckpointBrowserViewModel(ICivitApi civitApi) |
||||
{ |
||||
this.civitApi = civitApi; |
||||
} |
||||
|
||||
[RelayCommand] |
||||
private async Task SearchModels() |
||||
{ |
||||
if (string.IsNullOrWhiteSpace(SearchQuery)) |
||||
{ |
||||
return; |
||||
} |
||||
|
||||
var models = await civitApi.GetModels(new CivitModelsRequest |
||||
{ |
||||
Query = SearchQuery, |
||||
Limit = 5, |
||||
Nsfw = true, |
||||
}); |
||||
|
||||
Logger.Debug($"Found {models.Items.Length} models"); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue