Compare commits

...

2 Commits

Author SHA1 Message Date
小肥羊 935c6a9eb1 新增 任务异常后重试机制 2024-11-26 11:47:53 +08:00
小肥羊 3e936e71f6 修复 vad目录异常问题 silero_vad.onnx 2024-11-26 09:56:17 +08:00
10 changed files with 71 additions and 28 deletions

View File

@ -51,7 +51,7 @@ namespace Learn.VideoAnalysis.Components.Pages
NotificationType = NotificationType.Warning NotificationType = NotificationType.Warning
}); });
} }
if (InputAccount == "admin" && InputPassword == "q1w2e3!@#") if (InputAccount ==AppCommon.Config.Admin.Account && InputPassword == AppCommon.Config.Admin.Password)
{ {
await session.SetAsync("Login", true); await session.SetAsync("Login", true);
NavigationManager.NavigateTo("/"); NavigationManager.NavigateTo("/");

View File

@ -21,9 +21,9 @@
<PropertyColumn Property="c=>c.LastEnum" Width="120" /> <PropertyColumn Property="c=>c.LastEnum" Width="120" />
<PropertyColumn Property="c=>c.ApiToken" Width="120" /> <PropertyColumn Property="c=>c.ApiToken" Width="120" />
<PropertyColumn Property="c=>c.ComeFrom" Width="120" /> <PropertyColumn Property="c=>c.ComeFrom" Width="120" />
<PropertyColumn Property="c=>c.MediaUrl" /> <PropertyColumn Property="c=>c.MediaUrl" Width="300" />
<PropertyColumn Property="c=>c.TotalTokens" Width="100" /> <PropertyColumn Property="c=>c.TotalTokens" Width="100" />
<PropertyColumn Property="c=>c.CreateTime" Width="100" /> <PropertyColumn Property="c=>c.CreateTime" />
</ColumnDefinitions> </ColumnDefinitions>
<ExpandTemplate Context="rowData" > <ExpandTemplate Context="rowData" >
<Descriptions Title="任务详情" Bordered> <Descriptions Title="任务详情" Bordered>

View File

@ -43,7 +43,8 @@ namespace Learn.VideoAnalysis.Controllers.Dto
public TextValue(float v) public TextValue(float v)
{ {
var s = TimeSpan.FromSeconds((double)v); var s = TimeSpan.FromSeconds((double)v);
Text = s.ToString(@"mm\:ss"); var td = new[] { s.Hours, s.Minutes, s.Seconds };
Text = string.Join(':', td.Where(s => s > 0));
Value = v; Value = v;
} }
public TextValue(string t,object v) public TextValue(string t,object v)

View File

@ -15,7 +15,7 @@
"DB": { "DB": {
"ConnectionString": "AllowLoadLocalInfile=true;Server=10.255.255.3;Port=3306;Database=learn.videoanalysis;User ID=marking;Password=qwe123!@#;CharSet=utf8mb4;pooling=true;SslMode=None", "ConnectionString": "AllowLoadLocalInfile=true;Server=10.255.255.3;Port=3306;Database=learn.videoanalysis;User ID=marking;Password=qwe123!@#;CharSet=utf8mb4;pooling=true;SslMode=None",
"SqlType": "MySql", "SqlType": "MySql",
"UpdateTable": true "UpdateTable": false
} }
} }
} }

View File

@ -7,7 +7,11 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"AppConfig": { "AppConfig": {
"ID": "APP0001",// "ID": "APP0001", //
"Admin": {
"Account": "admin",
"Password": "q1w2e3!@#"
},
"Redis": { "Redis": {
"ConnectionString": "127.0.0.1:6379,password=Woshiren123,defaultDatabase=10" "ConnectionString": "127.0.0.1:6379,password=Woshiren123,defaultDatabase=10"
}, },

View File

@ -7,6 +7,7 @@ using System.Net.Http;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Net.Http.Json; using System.Net.Http.Json;
using AntDesign; using AntDesign;
using OneOf.Types;
/// <summary> /// <summary>
/// https://platform.moonshot.cn/docs/api-reference /// https://platform.moonshot.cn/docs/api-reference
@ -185,9 +186,24 @@ namespace VideoAnalysisCore.AICore.ChatGPT.KIMI
var client = _httpClientFactory.CreateClient(); var client = _httpClientFactory.CreateClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiKey); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ApiKey);
var request = ToHttpRequest(path); var request = ToHttpRequest(path);
var maxRestart = 4;
var errorMSG = new Exception[maxRestart];
for (int i = 0; i < maxRestart; i++)
{
try
{
request.Content = new StringContent(json, Encoding.UTF8, "application/json"); request.Content = new StringContent(json, Encoding.UTF8, "application/json");
return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead); return await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
} }
catch (Exception e)
{
errorMSG[i] = e;
}
Thread.Sleep(1000);
}
string error = string.Join('\r', errorMSG.Select(s => "\r\n"+ s.Message + "\r\n" + s.StackTrace + "\r\n >>>>>>>>"));
throw new Exception("重试后仍旧失败!\r\n" + error);
}
private HttpRequestMessage ToHttpRequest(string path) private HttpRequestMessage ToHttpRequest(string path)
{ {

View File

@ -36,8 +36,8 @@ namespace VideoAnalysisCore.AICore.FFMPGE
var outputFile = new OutputFile(Path.Combine(task.LocalPath(), Path.GetFileNameWithoutExtension(filePath) + ".wav")); var outputFile = new OutputFile(Path.Combine(task.LocalPath(), Path.GetFileNameWithoutExtension(filePath) + ".wav"));
var ffmpeg = new Engine(FFmpegPath); var ffmpeg = new Engine(FFmpegPath);
ffmpeg.Progress += OnProgress; //ffmpeg.Progress += OnProgress;
ffmpeg.Data += OnData; //ffmpeg.Data += OnData;
ffmpeg.Complete += OnComplete; ffmpeg.Complete += OnComplete;
ffmpeg.Error += (sender, e) => ffmpeg.Error += (sender, e) =>
{ {

View File

@ -69,7 +69,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
OR = new OfflineRecognizer(config); OR = new OfflineRecognizer(config);
VADModelConfig = new VadModelConfig(); VADModelConfig = new VadModelConfig();
VADModelConfig.SileroVad.Model = Path.Combine(AppCommon.AIModelFile, "sherpa-onnx-sense-voice-24-07-17", "silero_VAD.onnx"); VADModelConfig.SileroVad.Model = Path.Combine(AppCommon.AIModelFile, "sherpa-onnx-sense-voice-24-07-17", "silero_vad.onnx");
VADModelConfig.Debug = 0; VADModelConfig.Debug = 0;
//缓冲区大小 //缓冲区大小
VAD = new VoiceActivityDetector(VADModelConfig, 60); VAD = new VoiceActivityDetector(VADModelConfig, 60);

View File

@ -272,6 +272,20 @@ namespace VideoAnalysisCore.Common
} }
/// <summary> /// <summary>
/// 管理界面Admin账号
/// </summary>
public class AdminConfig
{
/// <summary>
/// 账号
/// </summary>
public string Account { get; set; } = string.Empty;
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; } = string.Empty;
}
/// <summary>
/// redis配置 /// redis配置
/// </summary> /// </summary>
public class RedisConfig public class RedisConfig
@ -308,6 +322,10 @@ namespace VideoAnalysisCore.Common
/// </summary> /// </summary>
public string ID { get; set; } = string.Empty; public string ID { get; set; } = string.Empty;
/// <summary> /// <summary>
/// Admin
/// </summary>
public AdminConfig Admin { get; set; } = new AdminConfig();
/// <summary>
/// redis /// redis
/// </summary> /// </summary>
public RedisConfig Redis { get; set; } = new RedisConfig(); public RedisConfig Redis { get; set; } = new RedisConfig();

View File

@ -100,10 +100,10 @@ namespace VideoAnalysisCore.Common
} }
/// <summary> /// <summary>
/// 获取任务进度 /// 缓存GPT任务缓存
/// </summary> /// </summary>
/// <param name="taskId"></param> /// <param name="taskId"></param>
public static void SetTaskGPTCached(object taskId, object data) public static void SetTaskGPTCached(object taskId, object? data)
{ {
Redis.Set(RedisExpandKey.TaskGPT(taskId), data, 3600); Redis.Set(RedisExpandKey.TaskGPT(taskId), data, 3600);
} }
@ -281,9 +281,11 @@ namespace VideoAnalysisCore.Common
{ {
if (taskId is null) return; if (taskId is null) return;
var tID = long.Parse(taskId); var tID = long.Parse(taskId);
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> " + key + " " + taskId);
if (action is not null) if (action is not null)
{ {
for (int i = 0; i < 3; i++)
{
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 开始执行 " + key + " " + taskId);
try try
{ {
Redis.HMSet(RedisExpandKey.Task(taskId), "LastEnum", key); Redis.HMSet(RedisExpandKey.Task(taskId), "LastEnum", key);
@ -292,13 +294,15 @@ namespace VideoAnalysisCore.Common
.SetColumns(it => it.LastEnum == key) .SetColumns(it => it.LastEnum == key)
.Where(it => it.Id == tID) .Where(it => it.Id == tID)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
await action(taskId); await action(taskId);
return;
} }
catch (Exception ex) catch (Exception ex)
{ {
await SetTaskErrorMessage(tID, ex) Thread.Sleep(1000);
.ConfigureAwait(false);//不切回上下文 Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "-> 稍后后重试." + key + " " + taskId );
await SetTaskErrorMessage(tID, ex);
}
} }
} }
else else