public async Task UpdateInstalledModels() { _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "Working | get installed models..."); _installedModels.Clear(); try { Log.Information("Get installed ml models."); var models = await MLModel.GetInstalledModels(); foreach (var model in models) { _installedModels.Add(new MlModelData(model.Image.Name, model.Type, model.ModelVersion, model.ApiVersion)); } Log.Information("Successfully get installed ml models."); } catch (Exception e) { Log.Error(e, "Unable to get installed models."); } _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, ""); }); }