Learn.VideoAnalysis/VideoAnalysis/Program.cs

147 lines
5.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using VideoAnalysisCore.Common;
using Learn.VideoAnalysis.Components;
using Microsoft.OpenApi.Models;
using VideoAnalysisCore.AICore.SherpaOnnx;
using Mapster;
using VideoAnalysisCore.AICore.GPT;
using VideoAnalysisCore.AICore.GPT.KIMI;
using VideoAnalysisCore.AICore.GPT.ChatGPT;
using Microsoft.Extensions.FileProviders;
using VideoAnalysisCore.AICore.GPT.DeepSeek;
using Microsoft.Extensions.DependencyInjection;
using VideoAnalysisCore.Common.Expand;
using Learn.VideoAnalysis.Expand;
using Microsoft.AspNetCore.Mvc.Formatters;
using System.Security.Cryptography;
using System.Diagnostics;
using VideoAnalysisCore.AICore.FFMPGE;
namespace Learn.VideoAnalysis
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
//.AddInteractiveWebAssemblyComponents();
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.ClearProviders(); // 清除默认的日志提供程序
loggingBuilder.AddConsole(); // 添加控制台日志提供程序
loggingBuilder.SetMinimumLevel(LogLevel.Warning); // 设置最小日志级别为 Warning
});
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Learn.VideoAnalysis",
Version = "v1",
Description = "教学视频分析平台v1"
});
var file = Path.Combine(AppContext.BaseDirectory, "Learn.VideoAnalysis.xml"); // xml文档绝对路径
var file1 = Path.Combine(AppContext.BaseDirectory, "VideoAnalysisCore.xml"); // xml文档绝对路径
c.IncludeXmlComments(file, true); // true : 显示控制器层注释
c.IncludeXmlComments(file1, true); // true : 显示控制器层注释
c.OrderActionsBy(o => o.RelativePath); // 对action的名称进行排序如果有多个就可以看见效果了。
});
//绑定 appsetting 配置
//初始化 插件
builder.Configuration.AddAppConfig(args);
builder.Services.AddSqlSugarExpand();
builder.Services.AddSimpleTexOcrClient();
builder.Services.AddDownloadFileExpand();
builder.Services.AddAlibabaCloudVod();
builder.Services.AddRedisExpand();
builder.Services.AddSpeakerAI();
builder.Services.AddCoravel();
//SenseVoice.Init();
//异常过滤器
builder.Services.AddControllersWithViews(options =>
{
options.Filters.Add(typeof(ExceptionFilter));
});
builder.Services.AddScoped(sp =>
{
var httpContext = sp.GetRequiredService<IHttpContextAccessor>().HttpContext;
if (httpContext != null)
{
return new HttpClient
{
BaseAddress = new Uri(httpContext.Request.Scheme + "://" + httpContext.Request.Host)
};
}
return new HttpClient();
});
//VideoAnalysisRazor.Program.AddClientServices(builder.Services);
builder.Services.AddAntDesign();
builder.Services.AddMapster();
builder.Services.AddCorsExpand();
builder.Services.AddHttpClient();
builder.Services.AddHttpContextAccessor();
builder.Services.AddSingleton<ChatGPTClient>();
builder.Services.AddSingleton<DeepSeekGPTClient>();
//builder.Services.AddSingleton<IBserGPT, KIMI_GPT>();
//builder.Services.AddSingleton<IBserGPT, Chat_GPT>();
builder.Services.AddSingleton<IBserGPT, DeepSeek_GPT>();
var app = builder.Build();
AppCommon.Services = app.Services;
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseExceptionHandler("/Error");
}
//添加wwwroot 静态目录
app.UseStaticFiles();
//添加 自定义 静态目录
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(AppCommon.TaskCachedFile),
RequestPath = "/video",
});
app.UseAntiforgery();
app.MapRazorComponents<Learn.VideoAnalysis.Components.App>()
.AddInteractiveServerRenderMode();
//.AddInteractiveWebAssemblyRenderMode()
//.AddAdditionalAssemblies(typeof(VideoAnalysisRazor._Imports).Assembly);
app.MapControllers();
//自定义 应用
app.UseCorsExpand();
app.UseSqlSugarExpand();
app.UseCoravelExpand();
app.Run();
}
}
}