Minor updates

This commit is contained in:
Nikolaj Olsson 2024-06-15 12:15:54 +02:00
parent e879fb6ef3
commit 37d821130c
5 changed files with 88 additions and 30 deletions

View File

@ -51,7 +51,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.4" />
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="UTF.Unknown" Version="2.5.1" />
<PackageReference Include="zlib.net-mutliplatform" Version="1.0.6" />

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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");
}
}
}

View File

@ -123,4 +123,7 @@
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="contextMenuStripOlamaModels.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>327, 17</value>
</metadata>
</root>