stop inference on stop pressed

small fixes
This commit is contained in:
Alex Bezdieniezhnykh
2025-03-24 10:52:32 +02:00
parent 6429ad62c2
commit 73c2ab5374
11 changed files with 40 additions and 29 deletions
@@ -144,6 +144,9 @@ public class AnnotationService : INotificationHandler<AnnotationsDeletedEvent>
.Where(x => x.Name == fName)
.Set(x => x.Source, source)
.Set(x => x.AnnotationStatus, status)
.Set(x => x.CreatedDate, createdDate)
.Set(x => x.CreatedEmail, createdEmail)
.Set(x => x.CreatedRole, userRole)
.UpdateAsync(token: token);
ann.Detections = detections;
}
+11 -5
View File
@@ -13,30 +13,31 @@ namespace Azaion.Common.Services;
public interface IInferenceService
{
Task RunInference(List<string> mediaPaths, Func<AnnotationImage, Task> processAnnotation, CancellationToken ct = default);
Task RunInference(List<string> mediaPaths, Func<AnnotationImage, Task> processAnnotation, CancellationToken detectToken = default);
void StopInference();
}
public class InferenceService(ILogger<InferenceService> logger, [FromKeyedServices(SecurityConstants.EXTERNAL_INFERENCE_PATH)] IExternalClient externalClient, IOptions<AIRecognitionConfig> aiConfigOptions) : IInferenceService
{
public async Task RunInference(List<string> mediaPaths, Func<AnnotationImage, Task> processAnnotation, CancellationToken ct = default)
public async Task RunInference(List<string> mediaPaths, Func<AnnotationImage, Task> processAnnotation, CancellationToken detectToken = default)
{
var aiConfig = aiConfigOptions.Value;
aiConfig.Paths = mediaPaths;
externalClient.Send(RemoteCommand.Create(CommandType.Inference, aiConfig));
while (!ct.IsCancellationRequested)
while (!detectToken.IsCancellationRequested)
{
try
{
var bytes = externalClient.GetBytes(ct: ct);
var bytes = externalClient.GetBytes(ct: detectToken);
if (bytes == null)
throw new Exception("Can't get bytes from inference client");
if (bytes.Length == 4 && Encoding.UTF8.GetString(bytes) == "DONE")
return;
var annotationImage = MessagePackSerializer.Deserialize<AnnotationImage>(bytes, cancellationToken: ct);
var annotationImage = MessagePackSerializer.Deserialize<AnnotationImage>(bytes, cancellationToken: detectToken);
await processAnnotation(annotationImage);
}
@@ -47,4 +48,9 @@ public class InferenceService(ILogger<InferenceService> logger, [FromKeyedServic
}
}
}
public void StopInference()
{
externalClient.Send(RemoteCommand.Create(CommandType.StopInference));
}
}