Skip to content

Commit

Permalink
Merge pull request LykosAI#490 from ionite34/moar-fix
Browse files Browse the repository at this point in the history
fixed a few bugs from sentry
  • Loading branch information
mohnjiles authored Feb 2, 2024
2 parents 145a8da + e736708 commit dd87c66
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
## v2.8.0-pre.5
### Fixed
- Fixed error when ControlNet module image paths are not found, even if the module is disabled
- Fixed error when finding metadata for archived models
- Fixed error when extensions folder is missing
- Fixed error when webp files have incorrect metadata
- Fixed crash when model was not selected in Inference

## v2.8.0-pre.4
### Added
Expand Down
2 changes: 1 addition & 1 deletion StabilityMatrix.Avalonia/DialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ public static BetterContentDialog CreatePromptErrorDialog(
models.Select(m => m.FileNameWithoutExtension)
);

if (result.Score > 40)
if (result is { Score: > 40 })
{
mainGrid.Children.Add(
new InfoBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ CancellationToken cancellationToken
return;
}

if (!await ModelCardViewModel.ValidateModel())
return;

// If enabled, randomize the seed
var seedCard = StackCardViewModel.GetCard<SeedCardViewModel>();
if (overrides is not { UseCurrentSeed: true } && seedCard.IsRandomizeEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,13 @@ CancellationToken cancellationToken
{
// Validate the prompts
if (!await PromptCardViewModel.ValidatePrompts())
{
return;
}

if (!await ModelCardViewModel.ValidateModel())
return;

if (!await CheckClientConnectedWithPrompt() || !ClientManager.IsConnected)
{
return;
}

// If enabled, randomize the seed
var seedCard = StackCardViewModel.GetCard<SeedCardViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Avalonia.Languages;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.Models.Inference;
using StabilityMatrix.Avalonia.Services;
Expand Down Expand Up @@ -51,6 +53,19 @@ public partial class ModelCardViewModel(IInferenceClientManager clientManager)

public IInferenceClientManager ClientManager { get; } = clientManager;

public async Task<bool> ValidateModel()
{
if (SelectedModel != null)
return true;

var dialog = DialogHelper.CreateMarkdownDialog(
"Please select a model to continue.",
"No Model Selected"
);
await dialog.ShowAsync();
return false;
}

/// <inheritdoc />
public virtual void ApplyStep(ModuleApplyStepEventArgs e)
{
Expand Down
6 changes: 5 additions & 1 deletion StabilityMatrix.Core/Helper/ModelFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ public ModelFinder(ILiteDbContext liteDbContext, ICivitApi civitApi)
// VersionResponse is not actually the full data of ModelVersion, so find it again
var version = model.ModelVersions!.First(version => version.Id == versionResponse.Id);

var file = versionResponse.Files.First(
var file = versionResponse.Files.FirstOrDefault(
file => hashBlake3.Equals(file.Hashes.BLAKE3, StringComparison.OrdinalIgnoreCase)
);

// Archived models do not have files
if (file == null)
return null;

return new ModelSearchResult(model, version, file);
}
catch (TaskCanceledException e)
Expand Down
18 changes: 14 additions & 4 deletions StabilityMatrix.Core/Models/Database/LocalImageFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DynamicData.Tests;
using System.Text.Json;
using DynamicData.Tests;
using MetadataExtractor.Formats.Exif;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models.FileInterfaces;
Expand Down Expand Up @@ -89,9 +90,18 @@ public static LocalImageFile FromPath(FilePath filePath)
filePath,
ExifDirectoryBase.TagImageDescription
);
var parameters = string.IsNullOrWhiteSpace(paramsJson)
? null
: JsonSerializer.Deserialize<GenerationParameters>(paramsJson);

GenerationParameters? parameters = null;
try
{
parameters = string.IsNullOrWhiteSpace(paramsJson)
? null
: JsonSerializer.Deserialize<GenerationParameters>(paramsJson);
}
catch (JsonException)
{
// just don't load params I guess, no logger here <_<
}

filePath.Info.Refresh();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ var indexDirectory in IndexRelativeDirectories.Select(
{
cancellationToken.ThrowIfCancellationRequested();

// Skip directory if not exists
if (!indexDirectory.Exists)
{
continue;
}

// Check subdirectories of the index directory
foreach (var subDirectory in indexDirectory.EnumerateDirectories())
{
Expand Down

0 comments on commit dd87c66

Please sign in to comment.