diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 529df99..1571529 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -85,6 +85,7 @@ private void InitializeComponent() this.logBox = new System.Windows.Forms.RichTextBox(); this.logPanel = new System.Windows.Forms.Panel(); this.SpaceBetween = new System.Windows.Forms.Panel(); + this.downloadProgressBar = new System.Windows.Forms.ProgressBar(); this.lscTrainerMenuStrip.SuspendLayout(); this.mainPanel.SuspendLayout(); this.logPanel.SuspendLayout(); @@ -184,6 +185,7 @@ private void InitializeComponent() this.mainPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.mainPanel.BackColor = System.Drawing.SystemColors.Control; this.mainPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.mainPanel.Controls.Add(this.downloadProgressBar); this.mainPanel.Controls.Add(this.txtGpuCount); this.mainPanel.Controls.Add(this.datasetListComboBox); this.mainPanel.Controls.Add(this.btnFetchDatasets); @@ -277,7 +279,7 @@ private void InitializeComponent() this.instanceCountLabel.AutoSize = true; this.instanceCountLabel.Location = new System.Drawing.Point(292, 222); this.instanceCountLabel.Name = "instanceCountLabel"; - this.instanceCountLabel.Size = new System.Drawing.Size(106, 17); + this.instanceCountLabel.Size = new System.Drawing.Size(97, 16); this.instanceCountLabel.TabIndex = 52; this.instanceCountLabel.Text = "Instance Count:"; // @@ -299,7 +301,7 @@ private void InitializeComponent() this.hyperparametersLabel.AutoSize = true; this.hyperparametersLabel.Location = new System.Drawing.Point(292, 72); this.hyperparametersLabel.Name = "hyperparametersLabel"; - this.hyperparametersLabel.Size = new System.Drawing.Size(122, 17); + this.hyperparametersLabel.Size = new System.Drawing.Size(116, 16); this.hyperparametersLabel.TabIndex = 50; this.hyperparametersLabel.Text = "Hyperparameters:"; // @@ -385,7 +387,7 @@ private void InitializeComponent() // btnDownloadModel // this.btnDownloadModel.BackColor = System.Drawing.Color.Honeydew; - this.btnDownloadModel.Location = new System.Drawing.Point(830, 342); + this.btnDownloadModel.Location = new System.Drawing.Point(814, 342); this.btnDownloadModel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.btnDownloadModel.Name = "btnDownloadModel"; this.btnDownloadModel.Size = new System.Drawing.Size(120, 30); @@ -412,7 +414,7 @@ private void InitializeComponent() this.descriptionLabel.BackColor = System.Drawing.SystemColors.Control; this.descriptionLabel.Location = new System.Drawing.Point(688, 156); this.descriptionLabel.Name = "descriptionLabel"; - this.descriptionLabel.Size = new System.Drawing.Size(83, 17); + this.descriptionLabel.Size = new System.Drawing.Size(78, 16); this.descriptionLabel.TabIndex = 28; this.descriptionLabel.Text = "Description:"; // @@ -422,7 +424,7 @@ private void InitializeComponent() this.trainingStatusLabel.BackColor = System.Drawing.SystemColors.Control; this.trainingStatusLabel.Location = new System.Drawing.Point(688, 128); this.trainingStatusLabel.Name = "trainingStatusLabel"; - this.trainingStatusLabel.Size = new System.Drawing.Size(108, 17); + this.trainingStatusLabel.Size = new System.Drawing.Size(99, 16); this.trainingStatusLabel.TabIndex = 27; this.trainingStatusLabel.Text = "Training Status:"; // @@ -440,7 +442,7 @@ private void InitializeComponent() this.instanceTypelbl.AutoSize = true; this.instanceTypelbl.Location = new System.Drawing.Point(792, 73); this.instanceTypelbl.Name = "instanceTypelbl"; - this.instanceTypelbl.Size = new System.Drawing.Size(0, 17); + this.instanceTypelbl.Size = new System.Drawing.Size(0, 16); this.instanceTypelbl.TabIndex = 25; // // txtOptimizer @@ -458,7 +460,7 @@ private void InitializeComponent() this.trainingDurationLabel.BackColor = System.Drawing.SystemColors.Control; this.trainingDurationLabel.Location = new System.Drawing.Point(688, 99); this.trainingDurationLabel.Name = "trainingDurationLabel"; - this.trainingDurationLabel.Size = new System.Drawing.Size(122, 17); + this.trainingDurationLabel.Size = new System.Drawing.Size(112, 16); this.trainingDurationLabel.TabIndex = 24; this.trainingDurationLabel.Text = "Training Duration:"; // @@ -467,7 +469,7 @@ private void InitializeComponent() this.optimizerLabel.AutoSize = true; this.optimizerLabel.Location = new System.Drawing.Point(292, 156); this.optimizerLabel.Name = "optimizerLabel"; - this.optimizerLabel.Size = new System.Drawing.Size(72, 17); + this.optimizerLabel.Size = new System.Drawing.Size(66, 16); this.optimizerLabel.TabIndex = 36; this.optimizerLabel.Text = "Optimizer:"; // @@ -477,7 +479,7 @@ private void InitializeComponent() this.virtualMachineLabel.BackColor = System.Drawing.SystemColors.Control; this.virtualMachineLabel.Location = new System.Drawing.Point(688, 72); this.virtualMachineLabel.Name = "virtualMachineLabel"; - this.virtualMachineLabel.Size = new System.Drawing.Size(109, 17); + this.virtualMachineLabel.Size = new System.Drawing.Size(101, 16); this.virtualMachineLabel.TabIndex = 23; this.virtualMachineLabel.Text = "Virtual Machine:"; // @@ -495,7 +497,7 @@ private void InitializeComponent() this.workersLabel.AutoSize = true; this.workersLabel.Location = new System.Drawing.Point(292, 128); this.workersLabel.Name = "workersLabel"; - this.workersLabel.Size = new System.Drawing.Size(65, 17); + this.workersLabel.Size = new System.Drawing.Size(61, 16); this.workersLabel.TabIndex = 34; this.workersLabel.Text = "Workers:"; // @@ -513,7 +515,7 @@ private void InitializeComponent() this.patienceLabel.AutoSize = true; this.patienceLabel.Location = new System.Drawing.Point(292, 100); this.patienceLabel.Name = "patienceLabel"; - this.patienceLabel.Size = new System.Drawing.Size(67, 17); + this.patienceLabel.Size = new System.Drawing.Size(63, 16); this.patienceLabel.TabIndex = 32; this.patienceLabel.Text = "Patience:"; // @@ -571,7 +573,7 @@ private void InitializeComponent() this.weightsLabel.AutoSize = true; this.weightsLabel.Location = new System.Drawing.Point(30, 153); this.weightsLabel.Name = "weightsLabel"; - this.weightsLabel.Size = new System.Drawing.Size(63, 17); + this.weightsLabel.Size = new System.Drawing.Size(59, 16); this.weightsLabel.TabIndex = 10; this.weightsLabel.Text = "Weights:"; // @@ -580,7 +582,7 @@ private void InitializeComponent() this.epochsLabel.AutoSize = true; this.epochsLabel.Location = new System.Drawing.Point(30, 126); this.epochsLabel.Name = "epochsLabel"; - this.epochsLabel.Size = new System.Drawing.Size(59, 17); + this.epochsLabel.Size = new System.Drawing.Size(56, 16); this.epochsLabel.TabIndex = 9; this.epochsLabel.Text = "Epochs:"; // @@ -589,7 +591,7 @@ private void InitializeComponent() this.batchSizeLabel.AutoSize = true; this.batchSizeLabel.Location = new System.Drawing.Point(30, 99); this.batchSizeLabel.Name = "batchSizeLabel"; - this.batchSizeLabel.Size = new System.Drawing.Size(79, 17); + this.batchSizeLabel.Size = new System.Drawing.Size(73, 16); this.batchSizeLabel.TabIndex = 8; this.batchSizeLabel.Text = "Batch Size:"; // @@ -598,7 +600,7 @@ private void InitializeComponent() this.imageSizeLabel.AutoSize = true; this.imageSizeLabel.Location = new System.Drawing.Point(30, 72); this.imageSizeLabel.Name = "imageSizeLabel"; - this.imageSizeLabel.Size = new System.Drawing.Size(81, 17); + this.imageSizeLabel.Size = new System.Drawing.Size(77, 16); this.imageSizeLabel.TabIndex = 7; this.imageSizeLabel.Text = "Image Size:"; // @@ -607,7 +609,7 @@ private void InitializeComponent() this.selectedFileLabel.AutoSize = true; this.selectedFileLabel.Location = new System.Drawing.Point(30, 222); this.selectedFileLabel.Name = "selectedFileLabel"; - this.selectedFileLabel.Size = new System.Drawing.Size(93, 17); + this.selectedFileLabel.Size = new System.Drawing.Size(89, 16); this.selectedFileLabel.TabIndex = 4; this.selectedFileLabel.Text = "Selected File:"; // @@ -694,6 +696,14 @@ private void InitializeComponent() this.SpaceBetween.Size = new System.Drawing.Size(1140, 10); this.SpaceBetween.TabIndex = 34; // + // downloadProgressBar + // + this.downloadProgressBar.Location = new System.Drawing.Point(940, 346); + this.downloadProgressBar.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.downloadProgressBar.Name = "downloadProgressBar"; + this.downloadProgressBar.Size = new System.Drawing.Size(161, 23); + this.downloadProgressBar.TabIndex = 55; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); @@ -781,6 +791,7 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtGpuCount; private System.Windows.Forms.ComboBox datasetListComboBox; private System.Windows.Forms.Button btnFetchDatasets; + private System.Windows.Forms.ProgressBar downloadProgressBar; } } diff --git a/Form1.cs b/Form1.cs index 8176fa7..cc51674 100644 --- a/Form1.cs +++ b/Form1.cs @@ -595,12 +595,17 @@ private async void btnFetchOutput_Click(object sender, EventArgs e) { outputListComboBox.Items.Clear(); outputKey = $"users/{USERNAME}/training-jobs/{jobName[0]}/output/output.tar.gz"; - + outputListComboBox.SelectedText = jobName[1]; foreach (var obj in jobName) { outputListComboBox.Items.Add(obj); } } + else + { + outputListComboBox.Items.Add("No items"); + btnDownloadModel.Enabled = false; + } } catch (Exception ex) { @@ -622,7 +627,7 @@ private void outputListComboBox_SelectedValueChanged(object sender, EventArgs e) { string trainingJobOuputs = outputListComboBox.GetItemText(outputListComboBox.SelectedItem); outputKey = $"users/{USERNAME}/training-jobs/{trainingJobOuputs}/output/output.tar.gz"; - modelKey = $"users/ {USERNAME} /training-jobs/{trainingJobOuputs}/output/model.tar.gz"; + modelKey = $"users/{USERNAME}/training-jobs/{trainingJobOuputs}/output/model.tar.gz"; btnDownloadModel.Enabled = true; } else @@ -944,6 +949,33 @@ public void UpdateTrainingStatus(string status, string description) MessageBox.Show($"Error: {ex.Message}"); } } + public void UpdateDownloadStatus(int percentage) + { + try + { + if (this.InvokeRequired) + { + if (percentage >= downloadProgressBar.Minimum && percentage <= downloadProgressBar.Maximum) + { + this.Invoke(new Action(() => UpdateDownloadStatus(percentage))); + return; + } + } + + downloadProgressBar.Value = percentage; + + if(percentage >= 100) + downloadProgressBar.Value = 0; + } + catch (ObjectDisposedException) + { + Console.WriteLine("Main form is closed. Cannot update download progress bar."); + } + catch (Exception ex) + { + MessageBox.Show($"Error: {ex.Message}"); + } + } public void DisplayLogMessage(string logMessage) { @@ -1011,7 +1043,7 @@ private async void btnFetchDatasets_Click(object sender, EventArgs e) { List datasets = await AWS_Helper.GetAvailableDatasetsList(s3Client, SAGEMAKER_BUCKET); - if (datasets != null) + if (datasets != null && datasets.Count > 0) { datasetListComboBox.Items.Clear(); @@ -1020,6 +1052,10 @@ private async void btnFetchDatasets_Click(object sender, EventArgs e) datasetListComboBox.Items.Add(obj); } } + else + { + datasetListComboBox.Items.Add("No items"); + } } catch (Exception ex) { diff --git a/Functions/AWS_Helper.cs b/Functions/AWS_Helper.cs index 07b55f6..df10d71 100644 --- a/Functions/AWS_Helper.cs +++ b/Functions/AWS_Helper.cs @@ -45,11 +45,11 @@ public static async Task> GetTrainingJobOutputList(AmazonS3Client s var response = await s3Client.ListObjectsV2Async(new ListObjectsV2Request { BucketName = bucketName, - Prefix = "training-jobs" + Prefix = $"users/{UserConnectionInfo.UserName}/training-jobs", }); return response.S3Objects - .Select(o => new { Key = o.Key.Split('/')[1], Date = ExtractDateFromKey(o.Key) }) + .Select(o => new { Key = o.Key.Split('/')[3], Date = ExtractDateFromKey(o.Key) }) .OrderByDescending(o => o.Date) .Select(o => o.Key) .Distinct() diff --git a/Functions/FileTransferUtility.cs b/Functions/FileTransferUtility.cs index 80704ab..06d3011 100644 --- a/Functions/FileTransferUtility.cs +++ b/Functions/FileTransferUtility.cs @@ -311,10 +311,12 @@ private static void ConfigureProgressTracking(TransferUtilityDownloadRequest dow downloadRequest.WriteObjectProgressEvent += (sender, args) => { - int percentage = (int)(args.TransferredBytes * 100 / args.TotalBytes); + int percentage = args.PercentDone; if (!cancellationToken.IsCancellationRequested) { UIUpdater.UpdateTrainingStatus($"Downloading Files from S3", $"Downloading {args.TransferredBytes}/{args.TotalBytes} - {percentage}%"); + + UIUpdater.UpdateDownloadStatus(percentage); } }; diff --git a/Functions/IUIUpdater.cs b/Functions/IUIUpdater.cs index fe31cbe..ba89989 100644 --- a/Functions/IUIUpdater.cs +++ b/Functions/IUIUpdater.cs @@ -15,5 +15,6 @@ public interface IUIUpdater void UpdateTrainingStatus(string status, string description); void DisplayLogMessage(string logMessage); string ConvertAnsiToRtf(string ansiText); + void UpdateDownloadStatus(int percentage); } }