Browse Source

Merge pull request #588 from ionite34/fix-model-images

Only download images from civitai with Type == "image"
pull/629/head
JT 7 months ago committed by GitHub
parent
commit
3d1090573b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 5
      StabilityMatrix.Avalonia/Services/ModelDownloadLinkHandler.cs
  3. 9
      StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CheckpointBrowserCardViewModel.cs
  4. 2
      StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFolder.cs
  5. 4
      StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelItemViewModel.cs
  6. 5
      StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelsViewModel.cs
  7. 2
      StabilityMatrix.Avalonia/ViewModels/Dialogs/SelectModelVersionViewModel.cs
  8. 3
      StabilityMatrix.Core/Models/Api/CivitImage.cs
  9. 12
      StabilityMatrix.Core/Services/MetadataImportService.cs

4
CHANGELOG.md

@ -5,6 +5,10 @@ All notable changes to Stability Matrix will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2.0.0.html).
## v2.10.0
### Fixed
- Fixed [#559](https://github.com/LykosAI/StabilityMatrix/issues/559) - "Unable to load bitmap from provided data" error in Checkpoints page
## v2.10.0-pre.2
### Added
- Added more metadata to the image dialog info flyout

5
StabilityMatrix.Avalonia/Services/ModelDownloadLinkHandler.cs

@ -229,7 +229,10 @@ public class ModelDownloadLinkHandler(
return null;
}
var image = modelVersion.Images[0];
var image = modelVersion.Images.FirstOrDefault(x => x.Type == "image");
if (image is null)
return null;
var imageExtension = Path.GetExtension(image.Url).TrimStart('.');
if (imageExtension is "jpg" or "jpeg" or "png")
{

9
StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CheckpointBrowserCardViewModel.cs

@ -159,7 +159,9 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
// Try to find a valid image
var image = images
?.Where(img => LocalModelFile.SupportedImageExtensions.Any(img.Url.Contains))
?.Where(
img => LocalModelFile.SupportedImageExtensions.Any(img.Url.Contains) && img.Type == "image"
)
.FirstOrDefault(image => nsfwEnabled || image.NsfwLevel <= 1);
if (image != null)
{
@ -295,7 +297,10 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
return null;
}
var image = modelVersion.Images[0];
var image = modelVersion.Images.FirstOrDefault(x => x.Type == "image");
if (image is null)
return null;
var imageExtension = Path.GetExtension(image.Url).TrimStart('.');
if (imageExtension is "jpg" or "jpeg" or "png")
{

2
StabilityMatrix.Avalonia/ViewModels/CheckpointManager/CheckpointFolder.cs

@ -500,7 +500,7 @@ public partial class CheckpointFolder : ViewModelBase
await modelInfo.SaveJsonToDirectory(DirectoryPath, modelFileName);
// If available, save thumbnail
var image = version.Images?.FirstOrDefault();
var image = version.Images?.FirstOrDefault(x => x.Type == "image");
if (image != null)
{
var imageExt = Path.GetExtension(image.Url).TrimStart('.');

4
StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelItemViewModel.cs

@ -22,9 +22,9 @@ public partial class RecommendedModelItemViewModel : ViewModelBase
private CivitModel civitModel;
public Uri ThumbnailUrl =>
ModelVersion.Images?.FirstOrDefault()?.Url == null
ModelVersion.Images?.FirstOrDefault(x => x.Type == "image")?.Url == null
? Assets.NoImage
: new Uri(ModelVersion.Images.First().Url);
: new Uri(ModelVersion.Images.First(x => x.Type == "image").Url);
[RelayCommand]
public void ToggleSelection() => IsSelected = !IsSelected;

5
StabilityMatrix.Avalonia/ViewModels/Dialogs/RecommendedModelsViewModel.cs

@ -206,7 +206,10 @@ public partial class RecommendedModelsViewModel : ContentDialogViewModelBase
return null;
}
var image = modelVersion.Images[0];
var image = modelVersion.Images.FirstOrDefault(x => x.Type == "image");
if (image is null)
return null;
var imageExtension = Path.GetExtension(image.Url).TrimStart('.');
if (imageExtension is "jpg" or "jpeg" or "png")
{

2
StabilityMatrix.Avalonia/ViewModels/Dialogs/SelectModelVersionViewModel.cs

@ -99,7 +99,7 @@ public partial class SelectModelVersionViewModel(
var allImages = value
?.ModelVersion
?.Images
?.Where(img => nsfwEnabled || img.NsfwLevel <= 1)
?.Where(img => img.Type == "image" && (nsfwEnabled || img.NsfwLevel <= 1))
?.Select(x => new ImageSource(x.Url))
.ToList();

3
StabilityMatrix.Core/Models/Api/CivitImage.cs

@ -19,5 +19,8 @@ public class CivitImage
[JsonPropertyName("hash")]
public string Hash { get; set; }
[JsonPropertyName("type")]
public string Type { get; set; }
// TODO: "meta" ( object? )
}

12
StabilityMatrix.Core/Services/MetadataImportService.cs

@ -107,7 +107,9 @@ public class MetadataImportService(
.ConfigureAwait(false);
var image = modelVersion.Images?.FirstOrDefault(
img => LocalModelFile.SupportedImageExtensions.Contains(Path.GetExtension(img.Url))
img =>
LocalModelFile.SupportedImageExtensions.Contains(Path.GetExtension(img.Url))
&& img.Type == "image"
);
if (image == null)
{
@ -201,7 +203,9 @@ public class MetadataImportService(
.ConfigureAwait(false);
var image = modelVersion.Images?.FirstOrDefault(
img => LocalModelFile.SupportedImageExtensions.Contains(Path.GetExtension(img.Url))
img =>
LocalModelFile.SupportedImageExtensions.Contains(Path.GetExtension(img.Url))
&& img.Type == "image"
);
if (image == null)
continue;
@ -264,7 +268,9 @@ public class MetadataImportService(
.ConfigureAwait(false);
var image = modelVersion.Images?.FirstOrDefault(
img => LocalModelFile.SupportedImageExtensions.Contains(Path.GetExtension(img.Url))
img =>
LocalModelFile.SupportedImageExtensions.Contains(Path.GetExtension(img.Url))
&& img.Type == "image"
);
if (image == null)

Loading…
Cancel
Save