mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:16:30 +00:00
stop inference on stop pressed
small fixes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user