mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:16:30 +00:00
refactor external clients
put model batch size as parameter in config
This commit is contained in:
+36
-23
@@ -33,7 +33,10 @@ public partial class App
|
||||
private IMediator _mediator = null!;
|
||||
private FormState _formState = null!;
|
||||
|
||||
private PythonResourceLoader _resourceLoader = null!;
|
||||
private InferenceExternalClient _inferenceClient = null!;
|
||||
private IResourceLoader _resourceLoader = null!;
|
||||
private IAuthProvider _authProvider = null!;
|
||||
|
||||
private Stream _securedConfig = null!;
|
||||
private static readonly Guid KeyPressTaskId = Guid.NewGuid();
|
||||
|
||||
@@ -55,41 +58,44 @@ public partial class App
|
||||
"Azaion.Dataset"
|
||||
];
|
||||
|
||||
private static PythonConfig ReadPythonConfig()
|
||||
private static SecureAppConfig ReadSecureAppConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(SecurityConstants.CONFIG_PATH))
|
||||
throw new FileNotFoundException(SecurityConstants.CONFIG_PATH);
|
||||
var configStr = File.ReadAllText(SecurityConstants.CONFIG_PATH);
|
||||
return JsonConvert.DeserializeObject<SecureAppConfig>(configStr)!.PythonConfig;
|
||||
var config = JsonConvert.DeserializeObject<SecureAppConfig>(configStr);
|
||||
|
||||
return config ?? SecurityConstants.DefaultSecureAppConfig;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return new PythonConfig
|
||||
{
|
||||
ZeroMqHost = SecurityConstants.DEFAULT_ZMQ_HOST,
|
||||
ZeroMqPort = SecurityConstants.DEFAULT_ZMQ_PORT,
|
||||
OneTryTimeoutSeconds = SecurityConstants.DEFAULT_TIMEOUT_SECONDS,
|
||||
RetryCount = SecurityConstants.DEFAULT_RETRY_COUNT,
|
||||
|
||||
ResourcesFolder = ""
|
||||
};
|
||||
return SecurityConstants.DefaultSecureAppConfig;
|
||||
}
|
||||
}
|
||||
|
||||
private void StartLogin()
|
||||
{
|
||||
new ConfigUpdater().CheckConfig();
|
||||
var secureAppConfig = ReadSecureAppConfig();
|
||||
_inferenceClient = new InferenceExternalClient(new OptionsWrapper<InferenceClientConfig>(secureAppConfig.InferenceClientConfig));
|
||||
_resourceLoader = new ResourceLoader(_inferenceClient);
|
||||
_authProvider = new AuthProvider(_inferenceClient);
|
||||
|
||||
var login = new Login();
|
||||
var pythonConfig = ReadPythonConfig();
|
||||
_resourceLoader = new PythonResourceLoader(pythonConfig);
|
||||
login.Closed += (sender, args) =>
|
||||
{
|
||||
if (!login.MainSuiteOpened)
|
||||
_inferenceClient.Stop();
|
||||
};
|
||||
|
||||
login.CredentialsEntered += (_, credentials) =>
|
||||
{
|
||||
credentials.Folder = pythonConfig.ResourcesFolder;
|
||||
_resourceLoader.Login(credentials);
|
||||
_securedConfig = _resourceLoader.LoadFileFromPython("secured-config.json");
|
||||
credentials.Folder = secureAppConfig.InferenceClientConfig.ResourcesFolder;
|
||||
_authProvider.Login(credentials);
|
||||
_securedConfig = _resourceLoader.LoadFile("secured-config.json");
|
||||
|
||||
AppDomain.CurrentDomain.AssemblyResolve += (_, a) =>
|
||||
{
|
||||
@@ -98,7 +104,7 @@ public partial class App
|
||||
{
|
||||
try
|
||||
{
|
||||
var stream = _resourceLoader.LoadFileFromPython($"{assemblyName}.dll");
|
||||
var stream = _resourceLoader.LoadFile($"{assemblyName}.dll");
|
||||
return Assembly.Load(stream.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -147,18 +153,25 @@ public partial class App
|
||||
services.AddSingleton<MainSuite>();
|
||||
services.AddSingleton<IHardwareService, HardwareService>();
|
||||
|
||||
services.AddSingleton<IResourceLoader>(_resourceLoader);
|
||||
services.AddSingleton<IAuthProvider>(_resourceLoader);
|
||||
services.AddSingleton<IInferenceService, PythonInferenceService>();
|
||||
|
||||
services.Configure<AppConfig>(context.Configuration);
|
||||
services.ConfigureSection<PythonConfig>(context.Configuration);
|
||||
services.ConfigureSection<QueueConfig>(context.Configuration);
|
||||
services.ConfigureSection<DirectoriesConfig>(context.Configuration);
|
||||
services.ConfigureSection<AnnotationConfig>(context.Configuration);
|
||||
services.ConfigureSection<AIRecognitionConfig>(context.Configuration);
|
||||
services.ConfigureSection<ThumbnailConfig>(context.Configuration);
|
||||
|
||||
#region External Services
|
||||
|
||||
services.ConfigureSection<InferenceClientConfig>(context.Configuration);
|
||||
services.ConfigureSection<GpsDeniedClientConfig>(context.Configuration);
|
||||
services.AddKeyedSingleton<IExternalClient>(SecurityConstants.EXTERNAL_INFERENCE_PATH, _inferenceClient);
|
||||
services.AddKeyedSingleton<IExternalClient, GpsDeniedExternalClient>(SecurityConstants.EXTERNAL_GPS_DENIED_PATH);
|
||||
services.AddSingleton<IResourceLoader>(_resourceLoader);
|
||||
services.AddSingleton<IAuthProvider>(_authProvider);
|
||||
services.AddSingleton<IInferenceService, InferenceService>();
|
||||
|
||||
#endregion
|
||||
|
||||
services.AddSingleton<IConfigUpdater, ConfigUpdater>();
|
||||
services.AddSingleton<Annotator.Annotator>();
|
||||
services.AddSingleton<DatasetExplorer>();
|
||||
|
||||
Reference in New Issue
Block a user