This commit is contained in:
2025-12-12 03:30:20 +09:00
parent 2025c514f7
commit aa59037e28
7 changed files with 346 additions and 167 deletions

View File

@@ -54,7 +54,67 @@ public class VisionService {
}
/**
* PDF 파일을 Vision 모델로 분석하여 텍스트 추출
* 진행률 업데이트 콜백 인터페이스
*/
@FunctionalInterface
public interface ProgressCallback {
void update(Long docId, int progress, String message, String status, String errorMsg);
}
/**
* PDF 파일을 Vision 모델로 분석 (진행률 콜백 포함)
*/
public String processPdfWithVisionAndProgress(String pdfPath, Long docId, ProgressCallback callback) {
if (!visionEnabled) {
log.info("[Vision] 비활성화 상태");
return null;
}
StringBuilder allDescriptions = new StringBuilder();
try (PDDocument document = PDDocument.load(new File(pdfPath))) {
PDFRenderer renderer = new PDFRenderer(document);
int pageCount = document.getNumberOfPages();
log.info("[Vision] PDF 분석 시작: {} 페이지", pageCount);
for (int i = 0; i < pageCount; i++) {
try {
// 진행률 계산: 10% ~ 40% 구간에서 페이지 수에 따라 분배
int progress = 10 + (int) ((i + 1) * 30.0 / pageCount);
String message = "PDF 분석중... (" + (i + 1) + "/" + pageCount + " 페이지)";
callback.update(docId, progress, message, null, null);
log.info("[Vision] 페이지 {}/{} 분석 중...", i + 1, pageCount);
BufferedImage image = renderer.renderImageWithDPI(i, 150, ImageType.RGB);
String base64Image = encodeImageToBase64(image);
String description = callVisionApi(base64Image, i + 1, pageCount);
if (description != null && !description.isEmpty()) {
allDescriptions.append("\n\n=== 페이지 ").append(i + 1).append(" ===\n");
allDescriptions.append(description);
}
Thread.sleep(1000);
} catch (Exception e) {
log.warn("[Vision] 페이지 {} 분석 실패: {}", i + 1, e.getMessage());
}
}
log.info("[Vision] PDF 분석 완료");
} catch (Exception e) {
log.error("[Vision] PDF 처리 실패: {}", e.getMessage());
return null;
}
return allDescriptions.toString();
}
/**
* PDF 파일을 Vision 모델로 분석하여 텍스트 추출 (기존 메서드 - 호환성 유지)
*/
public String processPdfWithVision(String pdfPath) {
if (!visionEnabled) {