feat: Update package references and enhance AI extraction service with CSV output functionality
This commit is contained in:
parent
55e8f0face
commit
af74c90ce7
12 changed files with 400 additions and 153 deletions
|
|
@ -77,6 +77,8 @@ namespace ImageCatalog_2
|
|||
private Task? _faceMatcherLogWatcherTask;
|
||||
private bool _hasStartedFaceEncoderInSession;
|
||||
private bool _hasStartedFaceMatcherInSession;
|
||||
private int _numberAiGpuRefreshVersion;
|
||||
private volatile bool _numberAiGpuValidationPending;
|
||||
|
||||
private sealed record ParsedFaceMatcherRow(string PhotoId, double? Score, string RawRow, string DebugSummary);
|
||||
|
||||
|
|
@ -137,7 +139,7 @@ namespace ImageCatalog_2
|
|||
|
||||
// Load available fonts
|
||||
AvailableFonts = LoadAvailableFonts();
|
||||
RefreshNumberAiGpuCapabilities();
|
||||
QueueRefreshNumberAiGpuCapabilities();
|
||||
RefreshFaceExecutableCapabilities();
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +159,7 @@ namespace ImageCatalog_2
|
|||
_logger.LogError(ex, "AI extraction failed");
|
||||
if (UseNumberAiGpu)
|
||||
{
|
||||
RefreshNumberAiGpuCapabilities();
|
||||
QueueRefreshNumberAiGpuCapabilities();
|
||||
}
|
||||
|
||||
await InvokeOnUiThreadAsync(() => NumberAiStatsSummary = $"Errore OCR: {ex.GetBaseException().Message}").ConfigureAwait(false);
|
||||
|
|
@ -255,7 +257,7 @@ namespace ImageCatalog_2
|
|||
set
|
||||
{
|
||||
_ai.ModelsFolderPath = value;
|
||||
RefreshNumberAiGpuCapabilities();
|
||||
QueueRefreshNumberAiGpuCapabilities();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2281,31 +2283,86 @@ namespace ImageCatalog_2
|
|||
}
|
||||
}
|
||||
|
||||
private void RefreshNumberAiGpuCapabilities()
|
||||
private void QueueRefreshNumberAiGpuCapabilities()
|
||||
{
|
||||
if (!TryBuildNumberAiModelConfiguration(out var configuration))
|
||||
{
|
||||
_numberAiGpuValidationPending = false;
|
||||
NumberAiGpuOptionEnabled = false;
|
||||
_ai.UseNumberAiGpu = false;
|
||||
return;
|
||||
}
|
||||
|
||||
NumberAiGpuOptionEnabled = NumberRecognitionEngine.TryValidateGpuRuntime(configuration, _logger, out _);
|
||||
if (!NumberAiGpuOptionEnabled)
|
||||
_numberAiGpuValidationPending = true;
|
||||
var requestVersion = Interlocked.Increment(ref _numberAiGpuRefreshVersion);
|
||||
_ = RefreshNumberAiGpuCapabilitiesAsync(configuration, requestVersion);
|
||||
}
|
||||
|
||||
private async Task RefreshNumberAiGpuCapabilitiesAsync(ModelConfiguration configuration, int requestVersion)
|
||||
{
|
||||
try
|
||||
{
|
||||
_ai.UseNumberAiGpu = false;
|
||||
var gpuAvailable = await Task.Run(() =>
|
||||
NumberRecognitionEngine.TryValidateGpuRuntime(configuration, _logger, out _)).ConfigureAwait(false);
|
||||
|
||||
if (requestVersion != Volatile.Read(ref _numberAiGpuRefreshVersion))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await InvokeOnUiThreadAsync(() =>
|
||||
{
|
||||
if (requestVersion != Volatile.Read(ref _numberAiGpuRefreshVersion))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_numberAiGpuValidationPending = false;
|
||||
NumberAiGpuOptionEnabled = gpuAvailable;
|
||||
if (!gpuAvailable)
|
||||
{
|
||||
_ai.UseNumberAiGpu = false;
|
||||
}
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (requestVersion != Volatile.Read(ref _numberAiGpuRefreshVersion))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogWarning(ex, "Failed to refresh OCR GPU capabilities.");
|
||||
|
||||
await InvokeOnUiThreadAsync(() =>
|
||||
{
|
||||
if (requestVersion != Volatile.Read(ref _numberAiGpuRefreshVersion))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_numberAiGpuValidationPending = false;
|
||||
NumberAiGpuOptionEnabled = false;
|
||||
_ai.UseNumberAiGpu = false;
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUseNumberAiGpu(bool value)
|
||||
{
|
||||
if (!NumberAiGpuOptionEnabled)
|
||||
if (!value)
|
||||
{
|
||||
_ai.UseNumberAiGpu = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_ai.UseNumberAiGpu = value;
|
||||
if (NumberAiGpuOptionEnabled || _numberAiGpuValidationPending)
|
||||
{
|
||||
_ai.UseNumberAiGpu = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_ai.UseNumberAiGpu = false;
|
||||
}
|
||||
|
||||
private bool TryBuildNumberAiModelConfiguration(out ModelConfiguration configuration)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue