public async Task UpdateModelStatus()
        {
            _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "Working | loading model...");
            //get the last version of ml model with specific config
            try
            {
                Log.Information("Loading ml model.");
                Status = "Loading ml model...";
                var config = _newConfig.MlModelConfig;
                // get local versions
                var localVersions = await MLModel.GetInstalledVersions(config);

                if (!localVersions.Contains(config.ModelVersion))
                {
                    throw new Exception($"There are no ml local model to init: {config.Image.Name}:{config.Image.Tag}");
                }
                if (config.ApiVersion != API_VERSION)
                {
                    throw new Exception($"Unsupported api {config.ApiVersion}. Only api v {API_VERSION} is supported.");
                }

                Repository = config.Image.Name;
                Version    = $"{config.ModelVersion}";
                Type       = $"{config.Type}";
                Status     = $"Ready";
                Log.Information("Successfully init ml model.");
            }
            catch (Exception e)
            {
                Status = $"Not ready.";
                Log.Error(e, "Unable to init model.");
            }
            _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
        }
Beispiel #2
0
        public async void UpdateModelStatus()
        {
            _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "Working | loading model...");
            //get the last version of ml model with specific config
            try
            {
                Log.Information("Loading ml model.");
                Status = "Loading ml model...";
                var confDir    = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "lacmus");
                var configPath = Path.Join(confDir, "appConfig.json");
                _appConfig = await AppConfig.Create(configPath);

                var config = _appConfig.MlModelConfig;;
                // get local versions
                var localVersions = await MLModel.GetInstalledVersions(config);

                if (localVersions.Contains(config.ModelVersion))
                {
                    Log.Information($"Find local version: {config.Image.Name}:{config.Image.Tag}.");
                }
                else
                {
                    IsShowLoadModelButton = true;
                    throw new Exception($"There are no ml local models to init: {config.Image.Name}:{config.Image.Tag}");
                }
                Repository = config.Image.Name;
                Version    = $"{config.ModelVersion}";
                Type       = $"{config.Type}";
                using (var model = new MLModel(config))
                    await model.Download();
                Status  = $"Ready";
                IsError = false;
                Log.Information("Successfully loads ml model.");
            }
            catch (Exception e)
            {
                Status  = $"Not ready.";
                IsError = true;
                Error   = $"Error: {e.Message}";
                Log.Error(e, "Unable to load model.");
            }
            _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
        }
Beispiel #3
0
        private async void LoadModel()
        {
            _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "Working | loading model...");
            //get the last version of ml model with specific config
            try
            {
                _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "");
                ModelManagerWindow window = new ModelManagerWindow(_window.LocalizationContext, ref _appConfig, _applicationStatusManager, _window.ThemeManager);
                _appConfig = await window.ShowResult();

                var config = _appConfig.MlModelConfig;
                // init local model or download and init it from docker registry
                var localVersions = await MLModel.GetInstalledVersions(config);

                if (localVersions.Contains(config.ModelVersion))
                {
                    Log.Information($"Find local version: {config.Image.Name}:{config.Image.Tag}.");
                }
                else
                {
                    IsShowLoadModelButton = true;
                    throw new Exception($"There are no ml local models to init: {config.Image.Name}:{config.Image.Tag}");
                }
                Repository = config.Image.Name;
                Version    = $"{config.ModelVersion}";
                Type       = $"{config.Type}";
                using (var model = new MLModel(config))
                    await model.Download();
                Status            = $"Ready";
                IsError           = false;
                _window.AppConfig = _appConfig;
            }
            catch (Exception e)
            {
                Status  = $"Not ready.";
                IsError = true;
                Error   = $"Error: {e.Message}";
                Log.Error(e, "Unable to load model.");
            }
            _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
        }
        public async void Init()
        {
            //get model status
            try
            {
                Status = "Loading ml model...";
                var config = _newConfig.MlModelConfig;
                // get local versions
                var localVersions = await MLModel.GetInstalledVersions(config);

                if (!localVersions.Contains(config.ModelVersion))
                {
                    throw new Exception($"There are no ml local model to init: {config.Image.Name}:{config.Image.Tag}");
                }
                if (config.ApiVersion != API_VERSION)
                {
                    throw new Exception($"Unsupported api {config.ApiVersion}. Only api v {API_VERSION} is supported.");
                }

                Dispatcher.UIThread.Post(() =>
                {
                    Repository = config.Image.Name;
                    Version    = $"{config.ModelVersion}";
                    Type       = $"{config.Type}";
                    Status     = $"Ready";
                });
            }
            catch (Exception e)
            {
                Status = $"Not ready.";
                Log.Error(e, "Unable to init model.");
            }
            // get installed models
            try
            {
                var models = await MLModel.GetInstalledModels();

                Dispatcher.UIThread.Post(() =>
                {
                    foreach (var model in models)
                    {
                        _installedModels.Add(new MlModelData(model.Image.Name,
                                                             model.Type,
                                                             model.ModelVersion,
                                                             model.ApiVersion));
                    }
                });
            }
            catch (Exception e)
            {
                Log.Error(e, "Unable to get installed models.");
            }
            //get available models
            try
            {
                foreach (var repository in _newConfig.Repositories)
                {
                    try
                    {
                        var models = await MLModel.GetAvailableModelsFromRegistry(repository);

                        Dispatcher.UIThread.Post(() =>
                        {
                            _repositories.Add(repository);
                            foreach (var model in models)
                            {
                                _avalableModels.Add(new MlModelData(model.Image.Name,
                                                                    model.Type,
                                                                    model.ModelVersion,
                                                                    model.ApiVersion));
                            }
                        });
                    }
                    catch (Exception e)
                    {
                        Log.Warning(e, $"Unable to parse models from {repository}. Skipped.");
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Unable get available models.");
            }

            Dispatcher.UIThread.Post(() =>
            {
                _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
            });
        }