diff --git a/src/libse/LibSE.csproj b/src/libse/LibSE.csproj index 8e2e84a8e..06b8c3776 100644 --- a/src/libse/LibSE.csproj +++ b/src/libse/LibSE.csproj @@ -51,7 +51,7 @@ - + diff --git a/src/ui/Forms/AudioToText/WhisperAudioToText.cs b/src/ui/Forms/AudioToText/WhisperAudioToText.cs index f4a37e29f..8ca04bac2 100644 --- a/src/ui/Forms/AudioToText/WhisperAudioToText.cs +++ b/src/ui/Forms/AudioToText/WhisperAudioToText.cs @@ -911,6 +911,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText if (!_useCenterChannelOnly && (comboBoxWhisperEngine.Text == WhisperChoice.PurfviewFasterWhisper || comboBoxWhisperEngine.Text == WhisperChoice.PurfviewFasterWhisperXXL) && + (videoFileName.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase) || + videoFileName.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase)) && _audioTrackNumber <= 0) { inputFile = videoFileName; diff --git a/src/ui/Forms/Translate/AutoTranslate.Designer.cs b/src/ui/Forms/Translate/AutoTranslate.Designer.cs index 87c1fb49b..8056cdf86 100644 --- a/src/ui/Forms/Translate/AutoTranslate.Designer.cs +++ b/src/ui/Forms/Translate/AutoTranslate.Designer.cs @@ -52,6 +52,9 @@ this.translateCurrentLineToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.labelApiKey = new System.Windows.Forms.Label(); this.buttonStrategy = new System.Windows.Forms.Button(); + this.contextMenuStripOlamaModels = new System.Windows.Forms.ContextMenuStrip(this.components); + this.updateLocalModelsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.findModelsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.labelFormality = new Nikse.SubtitleEdit.Controls.NikseLabel(); this.comboBoxFormality = new Nikse.SubtitleEdit.Controls.NikseComboBox(); this.nikseTextBoxApiKey = new Nikse.SubtitleEdit.Controls.NikseTextBox(); @@ -63,6 +66,7 @@ this.subtitleListViewSource = new Nikse.SubtitleEdit.Controls.SubtitleListView(); this.contextMenuStrip2.SuspendLayout(); this.contextMenuStrip1.SuspendLayout(); + this.contextMenuStripOlamaModels.SuspendLayout(); this.SuspendLayout(); // // progressBar1 @@ -262,6 +266,28 @@ this.buttonStrategy.UseVisualStyleBackColor = true; this.buttonStrategy.Click += new System.EventHandler(this.buttonStrategy_Click); // + // contextMenuStripOlamaModels + // + this.contextMenuStripOlamaModels.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.updateLocalModelsToolStripMenuItem, + this.findModelsToolStripMenuItem}); + this.contextMenuStripOlamaModels.Name = "contextMenuStripOlamaModels"; + this.contextMenuStripOlamaModels.Size = new System.Drawing.Size(184, 70); + // + // updateLocalModelsToolStripMenuItem + // + this.updateLocalModelsToolStripMenuItem.Name = "updateLocalModelsToolStripMenuItem"; + this.updateLocalModelsToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.updateLocalModelsToolStripMenuItem.Text = "Refresh local models"; + this.updateLocalModelsToolStripMenuItem.Click += new System.EventHandler(this.UpdateLocalModelsToolStripMenuItem_Click); + // + // findModelsToolStripMenuItem + // + this.findModelsToolStripMenuItem.Name = "findModelsToolStripMenuItem"; + this.findModelsToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.findModelsToolStripMenuItem.Text = "Find models online"; + this.findModelsToolStripMenuItem.Click += new System.EventHandler(this.findModelsToolStripMenuItem_Click); + // // labelFormality // this.labelFormality.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -495,6 +521,7 @@ this.Resize += new System.EventHandler(this.AutoTranslate_Resize); this.contextMenuStrip2.ResumeLayout(false); this.contextMenuStrip1.ResumeLayout(false); + this.contextMenuStripOlamaModels.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -534,5 +561,8 @@ private System.Windows.Forms.Button buttonStrategy; private System.Windows.Forms.ToolStripMenuItem translateCurrentLineToolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem translateCurrentLineToolStripMenuItem; + private System.Windows.Forms.ContextMenuStrip contextMenuStripOlamaModels; + private System.Windows.Forms.ToolStripMenuItem updateLocalModelsToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem findModelsToolStripMenuItem; } } \ No newline at end of file diff --git a/src/ui/Forms/Translate/AutoTranslate.cs b/src/ui/Forms/Translate/AutoTranslate.cs index ff3a288c0..b8d95cdf6 100644 --- a/src/ui/Forms/Translate/AutoTranslate.cs +++ b/src/ui/Forms/Translate/AutoTranslate.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -170,6 +171,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate nikseTextBoxApiKey.Top = nikseComboBoxUrl.Top; labelApiKey.Text = LanguageSettings.Current.Settings.GoogleTranslateApiKey; labelFormality.Visible = false; + comboBoxFormality.ContextMenuStrip = null; comboBoxFormality.Visible = false; var engineType = _autoTranslator.GetType(); @@ -343,36 +345,8 @@ namespace Nikse.SubtitleEdit.Forms.Translate var models = Configuration.Settings.Tools.OllamaModels.Split(',').ToList(); - //TODO: move to refresh models context menu - //using (var httpClient = new HttpClient()) - //{ - // try - // { - // httpClient.Timeout = TimeSpan.FromSeconds(5); - // var url = "http://localhost:11434/api/tags"; - // var resultTask = httpClient.GetAsync(new Uri(url)); - - // var result = resultTask.Result; - // var bytes = result.Content.ReadAsByteArrayAsync().Result; - // if (result.IsSuccessStatusCode) - // { - // var parser = new SeJsonParser(); - // var resultJson = Encoding.UTF8.GetString(bytes); - // var names = parser.GetAllTagsByNameAsStrings(resultJson, "name"); - // foreach (var name in names.OrderByDescending(p => p)) - // { - // models.Remove(name); - // models.Insert(0, name); - // } - // } - // } - // catch (Exception exception) - // { - // SeLogger.Error(exception, "Unable to get ollama models"); - // } - //} - labelFormality.Text = LanguageSettings.Current.AudioToText.Model; + labelFormality.Enabled = true; labelFormality.Visible = true; comboBoxFormality.DropDownStyle = ComboBoxStyle.DropDown; @@ -386,6 +360,8 @@ namespace Nikse.SubtitleEdit.Forms.Translate } comboBoxFormality.Text = Configuration.Settings.Tools.OllamaModel; + comboBoxFormality.ContextMenuStrip = contextMenuStripOlamaModels; + return; } @@ -1466,5 +1442,52 @@ namespace Nikse.SubtitleEdit.Forms.Translate SetupLanguageSettings(); } } + + private void UpdateLocalModelsToolStripMenuItem_Click(object sender, EventArgs e) + { + using (var httpClient = new HttpClient()) + { + try + { + var models = Configuration.Settings.Tools.OllamaModels.Split(',').ToList(); + var url = nikseComboBoxUrl.Text.Replace("generate", "tags"); + var resultTask = httpClient.GetAsync(new Uri(url)); + + var result = resultTask.Result; + var bytes = result.Content.ReadAsByteArrayAsync().Result; + if (result.IsSuccessStatusCode) + { + var parser = new SeJsonParser(); + var resultJson = Encoding.UTF8.GetString(bytes); + var names = parser.GetAllTagsByNameAsStrings(resultJson, "name"); + foreach (var name in names.OrderByDescending(p => p)) + { + models.Remove(name); + models.Insert(0, name); + } + + Configuration.Settings.Tools.OllamaModels = string.Join(",", models); + + var v = comboBoxFormality.Text; + comboBoxFormality.Items.Clear(); + foreach (var model in models) + { + comboBoxFormality.Items.Add(model); + } + comboBoxFormality.Text = v; + } + } + catch (Exception exception) + { + MessageBox.Show("Unable to get ollama models - is ollama running?" + Environment.NewLine + exception.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); + SeLogger.Error(exception, "Unable to get ollama models"); + } + } + } + + private void findModelsToolStripMenuItem_Click(object sender, EventArgs e) + { + UiUtil.OpenUrl("https://ollama.com/library"); + } } } diff --git a/src/ui/Forms/Translate/AutoTranslate.resx b/src/ui/Forms/Translate/AutoTranslate.resx index b5844921f..ef53063fa 100644 --- a/src/ui/Forms/Translate/AutoTranslate.resx +++ b/src/ui/Forms/Translate/AutoTranslate.resx @@ -123,4 +123,7 @@ 17, 17 + + 327, 17 + \ No newline at end of file