Browse Source

Merge pull request #157 from ionite34/checkpoints-fixes

pull/55/head
Ionite 1 year ago committed by GitHub
parent
commit
9fe76ba249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .github/workflows/release.yml
  2. 9
      StabilityMatrix.Avalonia/DesignData/DesignData.cs
  3. 41
      StabilityMatrix.Avalonia/ViewModels/CheckpointFile.cs
  4. 5
      StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs
  5. 5
      StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml

4
.github/workflows/release.yml

@ -84,7 +84,7 @@ jobs:
with:
environment: production
ignore_missing: true
version: StabilityMatrix@${{ env.GIT_TAG_NAME }}
version: StabilityMatrix.Avalonia@${{ env.GIT_TAG_NAME }}
- name: Create Sentry release
if: ${{ github.event_name == 'workflow_dispatch' }}
@ -97,7 +97,7 @@ jobs:
with:
environment: production
ignore_missing: true
version: StabilityMatrix@${{ github.event.inputs.version }}
version: StabilityMatrix.Avalonia@${{ github.event.inputs.version }}
release-windows:

9
StabilityMatrix.Avalonia/DesignData/DesignData.cs

@ -151,6 +151,8 @@ public static class DesignData
{
FilePath = "~/Models/Lora/electricity-light.safetensors",
Title = "Auroral Background",
PreviewImagePath = "https://image.civitai.com/xG1nkqKTMzGDvpLrqFT7WA/" +
"78fd2a0a-42b6-42b0-9815-81cb11bb3d05/00009-2423234823.jpeg",
ConnectedModel = new ConnectedModelInfo
{
VersionName = "Lightning Auroral",
@ -170,7 +172,7 @@ public static class DesignData
FilePath = "~/Models/Lora/model.safetensors",
Title = "Some model"
},
}
},
},
new(settingsManager, downloadService, modelFinder)
{
@ -187,6 +189,11 @@ public static class DesignData
}
};
foreach (var folder in CheckpointsPageViewModel.CheckpointFolders)
{
folder.DisplayedCheckpointFiles = folder.CheckpointFiles;
}
CheckpointBrowserViewModel.ModelCards = new
ObservableCollection<CheckpointBrowserCardViewModel>
{

41
StabilityMatrix.Avalonia/ViewModels/CheckpointFile.cs

@ -39,10 +39,12 @@ public partial class CheckpointFile : ViewModelBase
/// </summary>
[ObservableProperty]
private string title = string.Empty;
public string? PreviewImagePath { get; set; }
public Bitmap? PreviewImage { get; set; }
public bool IsPreviewImageLoaded => PreviewImage != null;
/// <summary>
/// Path to preview image. Can be local or remote URL.
/// </summary>
[ObservableProperty]
private string? previewImagePath;
[ObservableProperty]
private ConnectedModelInfo? connectedModel;
@ -75,6 +77,18 @@ public partial class CheckpointFile : ViewModelBase
}
}
private string GetConnectedModelInfoFilePath()
{
if (string.IsNullOrEmpty(FilePath))
{
throw new InvalidOperationException(
"Cannot get connected model info file path when FilePath is empty");
}
var modelNameNoExt = Path.GetFileNameWithoutExtension(FilePath);
var modelDir = Path.GetDirectoryName(FilePath) ?? "";
return Path.Combine(modelDir, $"{modelNameNoExt}.cm-info.json");
}
[RelayCommand]
private async Task DeleteAsync()
{
@ -89,6 +103,14 @@ public partial class CheckpointFile : ViewModelBase
{
await Task.Run(() => File.Delete(PreviewImagePath));
}
if (ConnectedModel != null)
{
var cmInfoPath = GetConnectedModelInfoFilePath();
if (File.Exists(cmInfoPath))
{
await Task.Run(() => File.Delete(cmInfoPath));
}
}
}
catch (IOException ex)
{
@ -169,16 +191,6 @@ public partial class CheckpointFile : ViewModelBase
if (ConnectedModel?.ModelId == null) return;
ProcessRunner.OpenUrl($"https://civitai.com/models/{ConnectedModel.ModelId}");
}
// Loads image from path
private async Task LoadPreviewImage()
{
if (PreviewImagePath == null) return;
await Dispatcher.UIThread.InvokeAsync(() =>
{
PreviewImage = new Bitmap(File.OpenRead(PreviewImagePath));
});
}
/// <summary>
/// Indexes directory and yields all checkpoint files.
@ -226,7 +238,6 @@ public partial class CheckpointFile : ViewModelBase
if (previewImage != null)
{
checkpointFile.PreviewImagePath = files[previewImage];
checkpointFile.LoadPreviewImage().SafeFireAndForget();
}
yield return checkpointFile;

5
StabilityMatrix.Avalonia/ViewModels/CheckpointsPageViewModel.cs

@ -67,12 +67,13 @@ public partial class CheckpointsPageViewModel : PageViewModelBase
public override async Task OnLoadedAsync()
{
DisplayedCheckpointFolders = CheckpointFolders;
if (Design.IsDesignMode) return;
// Set UI states
IsImportAsConnected = settingsManager.Settings.IsImportAsConnected;
SearchFilter = string.Empty;
if (Design.IsDesignMode) return;
IsLoading = CheckpointFolders.Count == 0;
IsIndexing = CheckpointFolders.Count > 0;
await IndexFolders();

5
StabilityMatrix.Avalonia/Views/CheckpointsPage.axaml

@ -101,9 +101,10 @@
TextWrapping="WrapWithOverflow"
IsVisible="{Binding IsConnectedModel}" />
<!-- Image -->
<Image
<controls:BetterAdvancedImage
Margin="0,0,0,4"
Source="{Binding PreviewImage}"
CornerRadius="4"
Source="{Binding PreviewImagePath}"
Stretch="Uniform"
IsVisible="{Binding IsConnectedModel}" />
</StackPanel>

Loading…
Cancel
Save