add publish script, check its work

This commit is contained in:
Alex Bezdieniezhnykh
2025-02-14 23:08:50 +02:00
parent 961d2499de
commit 0d6ea4264f
11 changed files with 97 additions and 43 deletions
+27 -9
View File
@@ -14,7 +14,6 @@ using Azaion.Common.DTO.Config;
using Azaion.Common.Events;
using Azaion.Common.Extensions;
using Azaion.Common.Services;
using Azaion.CommonSecurity.Services;
using LibVLCSharp.Shared;
using MediatR;
using Microsoft.WindowsAPICodePack.Dialogs;
@@ -520,7 +519,7 @@ public partial class Annotator
var files = new List<string>();
await Dispatcher.Invoke(async () =>
{
//Take not annotated medias
//Take not annotataed medias
files = (LvFiles.ItemsSource as IEnumerable<MediaFileInfo>)?.Skip(LvFiles.SelectedIndex)
.Take(Constants.DETECTION_BATCH_SIZE)
.Where(x => !x.HasAnnotations)
@@ -532,16 +531,16 @@ public partial class Annotator
await ReloadAnnotations();
}
});
if (files.Count == 0)
break;
await _inferenceService.RunInference(files, async annotationImage => await ProcessDetection(annotationImage), ct);
await _inferenceService.RunInference(files, async annotationImage => await ProcessDetection(annotationImage, ct), ct);
Dispatcher.Invoke(() =>
{
if (LvFiles.SelectedIndex + files.Count >= LvFiles.Items.Count)
DetectionCancellationSource.Cancel();
LvFiles.SelectedIndex += files.Count;
LvFiles.Items.Refresh();
});
}
Dispatcher.Invoke(() =>
@@ -553,15 +552,28 @@ public partial class Annotator
});
}
private async Task ProcessDetection(AnnotationImage annotationImage)
private async Task ProcessDetection(AnnotationImage annotationImage, CancellationToken ct = default)
{
await Dispatcher.Invoke(async () =>
{
try
{
var annotation = await _annotationService.SaveAnnotation(annotationImage);
var annotation = await _annotationService.SaveAnnotation(annotationImage, ct);
if (annotation.OriginalMediaName != _formState.CurrentMedia?.FName)
return;
{
var nextFile = (LvFiles.ItemsSource as IEnumerable<MediaFileInfo>)?
.Select((info, i) => new
{
MediaInfo = info,
Index = i
})
.FirstOrDefault(x => x.MediaInfo.FName == annotation.OriginalMediaName);
if (nextFile != null)
{
LvFiles.SelectedIndex = nextFile.Index;
await _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Play), ct);
}
}
AddAnnotation(annotation);
if (FollowAI)
@@ -573,7 +585,13 @@ public partial class Annotator
$"size=({det.Width:F2}, {det.Height:F2}), " +
$"prob: {det.Probability*100:F0}%"));
Dispatcher.Invoke(() => StatusHelp.Text = log);
Dispatcher.Invoke(() =>
{
if (_formState.CurrentMedia != null)
_formState.CurrentMedia.HasAnnotations = true;
LvFiles.Items.Refresh();
StatusHelp.Text = log;
});
}
catch (Exception e)
{