65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.ML;
|
|
using Microsoft.OpenApi.Models;
|
|
using TesteImagemCaminhao;
|
|
using VehicleDetectionAPI;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Adicionar serviços ao container
|
|
builder.Services.AddControllers();
|
|
|
|
// Configurar Swagger/OpenAPI
|
|
builder.Services.AddSwaggerGen(c =>
|
|
{
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Circle Detection API", Version = "v1" });
|
|
});
|
|
|
|
// Configurar limite de tamanho de upload
|
|
builder.Services.Configure<IISServerOptions>(options =>
|
|
{
|
|
options.MaxRequestBodySize = 30 * 1024 * 1024; // 30MB
|
|
});
|
|
|
|
builder.Services.Configure<KestrelServerOptions>(options =>
|
|
{
|
|
options.Limits.MaxRequestBodySize = 30 * 1024 * 1024; // 30MB
|
|
});
|
|
|
|
// Garantir que as pastas necessárias existam
|
|
var modelsDir = Path.Combine(builder.Environment.ContentRootPath, "Models");
|
|
Directory.CreateDirectory(modelsDir);
|
|
|
|
var imagesDir = Path.Combine(builder.Environment.ContentRootPath, "Images");
|
|
Directory.CreateDirectory(imagesDir);
|
|
|
|
var wwwrootImagesDir = Path.Combine(builder.Environment.ContentRootPath, "wwwroot", "images");
|
|
Directory.CreateDirectory(wwwrootImagesDir);
|
|
|
|
// Registrar o serviço de detecção de rodas
|
|
builder.Services.AddSingleton<IWheelsDetectionService, WheelsDetectionService>();
|
|
|
|
// Configurar o ML.NET PredictionEnginePool
|
|
builder.Services.AddPredictionEnginePool<ModelInput, ModelOutput>()
|
|
.FromFile(modelName: "VehicleTypeModel", filePath: "C:\\Users\\USER\\Pictures\\model.zip", watchForChanges: true);
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configurar o pipeline de requisições HTTP
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Circle Detection API v1"));
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseStaticFiles(); // Para servir arquivos estáticos da pasta wwwroot
|
|
app.UseRouting();
|
|
app.UseAuthorization();
|
|
app.MapControllers();
|
|
|
|
app.Run(); |