This commit is contained in:
zeyu xu
2024-04-08 12:38:14 +08:00
parent 7cee8fd87a
commit cb861ef2bb
2 changed files with 6 additions and 5 deletions

View File

@@ -106,14 +106,15 @@ namespace AntSK.Domain.Domain.Service
MaxTokensPerParagraph = kms.MaxTokensPerParagraph,
OverlappingTokens = kms.OverlappingTokens
});
//加载OCR
WithOcr(memoryBuild, kms);
//加载会话模型
WithTextGenerationByAIType(memoryBuild, chatModel, chatHttpClient);
//加载向量模型
WithTextEmbeddingGenerationByAIType(memoryBuild, embedModel, embeddingHttpClient);
//加载向量库
WithMemoryDbByVectorDB(memoryBuild);
//加载OCR
WithOcr(memoryBuild, kms);
_memory = memoryBuild.Build<MemoryServerless>();
return _memory;
}

View File

@@ -12,11 +12,11 @@ namespace AntSK.OCR
public class AntSKOcrEngine : IOcrEngine
{
FullOcrModel model;
public async Task<string> ExtractTextFromImageAsync(Stream imageContent, CancellationToken cancellationToken = default)
public Task<string> ExtractTextFromImageAsync(Stream imageContent, CancellationToken cancellationToken = default)
{
if (model == null)
{
model = await OnlineFullModels.ChineseV4.DownloadAsync();
model = OnlineFullModels.ChineseV4.DownloadAsync().Result;
}
using (PaddleOcrAll all = new(model)
{
@@ -26,7 +26,7 @@ namespace AntSK.OCR
{
Mat src = Cv2.ImDecode(StreamToByte(imageContent), ImreadModes.Color);
PaddleOcrResult result = all.Run(src);
return await Task.FromResult(result.Text);
return Task.FromResult(result.Text);
}
}