From c12c8ebfcdbf77dd328c3a31577786f466d45ded Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com>
Date: Tue, 25 Feb 2025 18:26:47 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E9=83=A8=E7=BD=B2?=
=?UTF-8?q?=E7=BA=BF=E4=B8=8A=E6=B5=81=E7=A8=8B=20=E4=BC=98=E5=8C=96=20ds?=
=?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
VideoAnalysis/AntDeploy.json | 10 ++++----
VideoAnalysis/Dockerfile | 12 +++++-----
.../AICore/FFMPGE/FFMPGEHandle.cs | 11 ++++++---
.../AICore/GPT/DeepSeek/DeepSeekClient.cs | 6 ++---
.../AICore/GPT/DeepSeek/DeepSeek_GPT.cs | 23 ++++++++++---------
.../AICore/SherpaOnnx/SenseVoice.cs | 3 ++-
VideoAnalysisCore/Common/RedisExpand.cs | 2 +-
7 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/VideoAnalysis/AntDeploy.json b/VideoAnalysis/AntDeploy.json
index e40e57a..886002b 100644
--- a/VideoAnalysis/AntDeploy.json
+++ b/VideoAnalysis/AntDeploy.json
@@ -6,11 +6,11 @@
"LinuxServerList": [
{
"UserName": "hy",
- "Pwd": "E9D1AC136FDD59740A9595ABD0EB953A",
+ "Pwd": "9718CB3C9A0760CA326767D677ADEC1C",
"Host": "192.168.2.21:10107",
"NickName": "",
"IIsFireUrl": null,
- "DockerFireUrl": "https://videoanalysis.w.23544.com:8843/",
+ "DockerFireUrl": "",
"WindowsServiceFireUrl": null,
"LinuxServiceFireUrl": null
}
@@ -74,8 +74,8 @@
"AspNetCoreEnv": "",
"LastEnvName": "10楼刀片机",
"RemoveDaysFromPublished": "10",
- "WorkDir": "",
- "Volume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy//VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
+ "WorkDir": "/home/hy/",
+ "Volume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
"Other": "",
"EnvPairList": [
{
@@ -84,7 +84,7 @@
"LinuxEnvParam": null,
"DockerPort": "9040",
"DockerEnvName": "",
- "DockerVolume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy//VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
+ "DockerVolume": "/home/hy/VideoAnalysis/AICore:/app/AICore/_Static;/home/hy/VideoAnalysis/TaskCachedFile:/app/TaskCachedFile",
"DockerOther": ""
}
]
diff --git a/VideoAnalysis/Dockerfile b/VideoAnalysis/Dockerfile
index 3303b7f..83bf394 100644
--- a/VideoAnalysis/Dockerfile
+++ b/VideoAnalysis/Dockerfile
@@ -3,17 +3,17 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
+WORKDIR /app
+EXPOSE 9040
+COPY . .
+#设置时间为中国上海 环境为开发环境
+ENV TZ=Asia/Shanghai
+
# 更新 apt 源
COPY sources.list /etc/apt/sources.list
RUN apt-get update
RUN apt-get install -y ffmpeg
-WORKDIR /app
-EXPOSE 9040
-
-COPY . .
-#设置时间为中国上海 环境为开发环境
-ENV TZ=Asia/Shanghai
ENV ASPNETCORE_URLS=http://+:9040
diff --git a/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs b/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs
index 987d5e9..89f3b7e 100644
--- a/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs
+++ b/VideoAnalysisCore/AICore/FFMPGE/FFMPGEHandle.cs
@@ -20,6 +20,8 @@ namespace VideoAnalysisCore.AICore.FFMPGE
public static string FFmpegPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
? $"/usr/bin/ffmpeg"
: Path.Combine(AppCommon.AIModelFile, "ffmpeg.exe");
+
+ public static string Task = string.Empty;
///
/// 音频转码为 wav_16k
///
@@ -27,6 +29,7 @@ namespace VideoAnalysisCore.AICore.FFMPGE
///
public static async Task Audio2WAV16KAsync(string task)
{
+ Task = task;
var filePath = RedisExpand.Redis.HGet(RedisExpandKey.Task(task), "LocalMediaPath");
if (string.IsNullOrEmpty(filePath))
throw new Exception($"任务id[{task}] 无效");
@@ -41,7 +44,9 @@ namespace VideoAnalysisCore.AICore.FFMPGE
ffmpeg.Complete += OnComplete;
ffmpeg.Error += (sender, e) =>
{
- throw new Exception($"[{e.Input.Name} => {e.Output.Name}]: 错误: {e.Exception.Message}");
+ var ee = new Exception($"音频转码出现异常 \r\n[{e.Input.Name} => {e.Output.Name}]: 错误: {e.Exception.Message}");
+ RedisExpand.SetTaskErrorMessage(long.Parse(task), ee);
+ throw ee;
};
var conversionOptions = new ConversionOptions
@@ -53,8 +58,6 @@ namespace VideoAnalysisCore.AICore.FFMPGE
};
var res = await ffmpeg.ConvertAsync(inputFile, outputFile, conversionOptions);
- //加入下一队列
- RedisExpand.InsertChannel(Enum.RedisChannelEnum.ParsingCaptions, task);
}
private static void OnProgress(object sender, ConversionProgressEventArgs e)
@@ -76,6 +79,8 @@ namespace VideoAnalysisCore.AICore.FFMPGE
private static void OnComplete(object sender, ConversionCompleteEventArgs e)
{
Console.WriteLine("转换完成=>" + e.Output.Name);
+ //加入下一队列
+ RedisExpand.InsertChannel(Enum.RedisChannelEnum.ParsingCaptions, Task);
}
}
}
diff --git a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs
index db4a1bb..72b40cb 100644
--- a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs
+++ b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeekClient.cs
@@ -61,9 +61,9 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
goto postStar;
}
- //throw new Exception($" GPT模型返回异常 返回参数: " +
- // $" {System.Text.Json.JsonSerializer.Serialize(res1)}");
-
+ //throw new Exception($" GPT模型返回异常 返回参数: " +
+ // $" {System.Text.Json.JsonSerializer.Serialize(res1)}");
+ Console.WriteLine(DateTime.Now + $"=>GPT请求头获取成功 Code = {chatResp.StatusCode} Res={res1}");
var res = await chatResp.Content.ReadFromJsonAsync();
if (res is null || res.error != null)
throw new Exception($" GPT模型返回异常 返回参数: " +
diff --git a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs
index 1d975d6..6aacd65 100644
--- a/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs
+++ b/VideoAnalysisCore/AICore/GPT/DeepSeek/DeepSeek_GPT.cs
@@ -82,13 +82,13 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
var postMessages =
$"你的任务是分析视频字幕内容并提取出中国高考考试试题方法点,然后分析出<知识块>,来帮助学生快速了解视频字幕的内容" +
$"通过阅读并理解字幕内容.然后识别出{subject}学科中属于{fileNameInfoRes.授课章节}章节相关的方法点以及对应的时间段。" +
- $"关联合并知识内容相似的知识点来合并为<知识块>。(请注意如果<知识块>时长超过600秒则考虑拆封为两个更加贴切的<知识块>.或者<知识块>时长小于30秒则考虑合并<知识块>到相邻的<知识块>)" +
+ $"关联合并知识内容相似的知识点来合并为<知识块>。" +
$"分配空余未使用的时间段到内容相近的<知识块>时间区间来获取更加详细的上下文,但是请避免<知识块>之间时间重合。" +
$"从提取出的<知识块>内容称来匹配我提供的知识点,来作为片段的知识点(请确保匹配的知识点是用户提供的,否则片段知识点值为空字符串)。" +
$"提供的方法点名称({knows})。 格式 (方法点Id|方法点名称) 如果一个<知识块>出现多个知识点那么知识点Id与知识点名称都用逗号','分割。" +
$"这是输入的视频字幕并且是包含时间戳的视频字幕的固定格式文本。" +
$"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).以下是包含时间的视频字幕文本。字幕列表 {captions.Captions}。" +
- $"最后请检查某些<知识块>之间的过渡是否自然。建议按时间顺序优化分段密度,增强知识点衔接。" +
+ $"最后请检查某些<知识块>之间的过渡是否自然,如果<知识块>时长超过500秒则考虑拆封为两个更加贴切的<知识块>.或者<知识块>时长小于30秒则考虑合并<知识块>到相邻的<知识块>)。" +
$"输出格式({resFormat})";
Console.WriteLine(DateTime.Now + "=>开始分析视频内容");
@@ -109,7 +109,7 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
var thems = string.Join(',', questionRes.Select(s => s.StartTime + "->" + s.Theme));
var checkResFormat = """{"Score":打分(number),"Evaluation":评价(string)}""";
- var checkMessage = "我为视频的讲解内容做了一些分段,你能帮我检查下这些分段的分配合理吗?请给出你的打分(0-100,60分及格)以及评价" +
+ var checkMessage = "我为视频的讲解内容做了一些分段,你能帮我检查下这些分段的时间分配合理吗?请给出你的打分(0-100,70分及格)以及评价" +
$"这是我的分段 {thems}." +
$"后续的内容是包含时间戳的视频字幕的固定格式文本。" +
$"字幕格式(说话人:开始秒:结束秒:内容|下一段字幕).以下是包含时间的视频字幕文本。字幕列表 {captions.Captions}。" +
@@ -121,20 +121,20 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
break;
else
{
- Console.WriteLine(DateTime.Now + "=>得分过低 " + checkRes?.Score );
+ Console.WriteLine(DateTime.Now + $"=>{task} 得分过低 " + checkRes?.Score );
Console.WriteLine( checkRes.Evaluation);
Console.WriteLine( );
}
}
- await videoKonwPointDB.DeleteAsync(s => s.VideoTaskId == taskId);
- var data = questionRes
- .Where(s=>!string.IsNullOrEmpty(s.KnowPoint))
+
+ var insertData = questionRes
+ .Where(s => !string.IsNullOrEmpty(s.KnowPoint))
.SelectMany(
- s =>
+ s =>
{
- var ks = s.KnowPoint.Split(",");
- return ks.Where(x=>knowDic.ContainsKey(x))
+ var ks = s.KnowPoint.Split(",").Distinct();
+ return ks.Where(x => knowDic.ContainsKey(x))
.Select(x => new VideoKonwPoint()
{
Content = s.Content,
@@ -147,7 +147,8 @@ namespace VideoAnalysisCore.AICore.GPT.DeepSeek
VideoTaskId = taskInfo.Id,
});
}).ToList();
- await videoKonwPointDB.InsertRangeAsync(data);
+ await videoKonwPointDB.DeleteAsync(s => s.VideoTaskId == taskId);
+ await videoKonwPointDB.InsertRangeAsync(insertData);
diff --git a/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs b/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs
index ae6a944..ae2b5cd 100644
--- a/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs
+++ b/VideoAnalysisCore/AICore/SherpaOnnx/SenseVoice.cs
@@ -42,6 +42,7 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
//模型类型
config.ModelConfig.ModelType = string.Empty;
config.ModelConfig.NumThreads = numThreads;
+ config.ModelConfig.Provider = "cpu";
//需要使用GPU
if (!useGPU)
config.ModelConfig.Provider = "cuda";
@@ -251,10 +252,10 @@ namespace VideoAnalysisCore.AICore.SherpaOnnx
End = (float)Math.Round(startTime + duration, 2, MidpointRounding.AwayFromZero),
});
}
-
VAD.Pop();
}
+ Console.WriteLine(DateTime.Now + "=> SenseVoice 字幕数量"+ res.Count);
await RedisExpand.Redis.HMSetAsync(RedisExpandKey.Task(task), "Captions", res);
//RedisExpand.InsertChannel(Enum.RedisChannelEnum.ParsingSpeaker, task);
RedisExpand.InsertChannel(Enum.RedisChannelEnum.ChatModelAnalysis, task);
diff --git a/VideoAnalysisCore/Common/RedisExpand.cs b/VideoAnalysisCore/Common/RedisExpand.cs
index 0eed3e6..d5acafd 100644
--- a/VideoAnalysisCore/Common/RedisExpand.cs
+++ b/VideoAnalysisCore/Common/RedisExpand.cs
@@ -97,7 +97,7 @@ namespace VideoAnalysisCore.Common
Redis.Deserialize = (json, type) => System.Text.Json.JsonSerializer.Deserialize(json, type);
Task.Run(() =>
{
- Task.Delay(1000 * 10);
+ Thread.Sleep(1000 * 10);
InitChannel();
});
}