diff --git a/src/main/java/com/easylead/easylead/domain/text/business/TextBusiness.java b/src/main/java/com/easylead/easylead/domain/text/business/TextBusiness.java index ff674ed..193ae87 100644 --- a/src/main/java/com/easylead/easylead/domain/text/business/TextBusiness.java +++ b/src/main/java/com/easylead/easylead/domain/text/business/TextBusiness.java @@ -40,12 +40,13 @@ public TextFileResDTO easyToRead(MultipartFile file) throws Exception { log.info("=========== reqText : "+reqText+"============"); - StringBuilder result = new StringBuilder(); - for(String text : reqText){ - HttpRequest request = gptService.requestGPTCustom(text); - result.append(gptService.responseGPT(request)); - } - return textConverter.toTextFileResDTO(result.toString()); +// StringBuilder result = new StringBuilder(); +// for(String text : reqText){ +// HttpRequest request = gptService.requestGPTCustom(text); +// result.append(gptService.responseGPT(request)); +// } +// return textConverter.toTextFileResDTO(result.toString()); + return null; } public Flux easyToReadImage(MultipartFile file) throws JsonProcessingException { diff --git a/src/main/java/com/easylead/easylead/domain/text/service/GoogleVisionService.java b/src/main/java/com/easylead/easylead/domain/text/service/GoogleVisionService.java index 21197a3..30d76a7 100644 --- a/src/main/java/com/easylead/easylead/domain/text/service/GoogleVisionService.java +++ b/src/main/java/com/easylead/easylead/domain/text/service/GoogleVisionService.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; @@ -122,15 +123,19 @@ public List detectDocumentsGcs(String gcsSourcePath, String gcsDestinati String bucketName = matcher.group(1); String prefix = matcher.group(2); - // Get the list of objects with the given prefix from the GCS bucket + // GCS 버킷에서 주어진 접두어로 객체 목록 가져오기 Bucket bucket = storage.get(bucketName); com.google.api.gax.paging.Page pageList = bucket.list(Storage.BlobListOption.prefix(prefix)); - Blob firstOutputFile = null; + List blobList = new ArrayList<>(); + pageList.iterateAll().forEach(blobList::add); - // List objects with the given prefix. - System.out.println("Output files:"); - for (Blob blob : pageList.iterateAll()) { + // 파일 이름에서 숫자를 추출하여 정렬하기 + blobList.sort(Comparator.comparingInt(blob -> extractPageNumber(blob.getName()))); + + // 정렬된 파일 목록을 출력 + System.out.println("출력 파일들:"); + for (Blob blob : blobList) { System.out.println(blob.getName()); String jsonContents = new String(blob.getContent()); @@ -141,32 +146,9 @@ public List detectDocumentsGcs(String gcsSourcePath, String gcsDestinati for (AnnotateImageResponse a : annotateFileResponse.getResponsesList()) { reqList.add(a.getFullTextAnnotation().getText()); } - // Process the first System.output file from GCS. - // Since we specified batch size = 2, the first response contains - // the first two pages of the input file. -// if (firstOutputFile == null) { -// firstOutputFile = blob; -// } + } - // Get the contents of the file and convert the JSON contents to an AnnotateFileResponse - // object. If the Blob is small read all its content in one request - // (Note: the file is a .json file) - // Storage guide: https://cloud.google.com/storage/docs/downloading-objects -// String jsonContents = new String(firstOutputFile.getContent()); -// AnnotateFileResponse.Builder builder = AnnotateFileResponse.newBuilder(); -// JsonFormat.parser().merge(jsonContents, builder); -// -// // Build the AnnotateFileResponse object -// AnnotateFileResponse annotateFileResponse = builder.build(); - - // Parse through the object to get the actual response for the first page of the input file. -// annotateImageResponse = annotateFileResponse.getResponses(0); - - // Here we print the full text from the first page. - // The response contains more information: - // annotation/pages/blocks/paragraphs/words/symbols - // including confidence score and bounding boxes } else { System.out.println("No MATCH"); @@ -174,5 +156,13 @@ public List detectDocumentsGcs(String gcsSourcePath, String gcsDestinati } return reqList; } + private int extractPageNumber(String fileName) { + Pattern pattern = Pattern.compile("output-(\\d+)-to-\\d+\\.json"); + Matcher matcher = pattern.matcher(fileName); + if (matcher.find()) { + return Integer.parseInt(matcher.group(1)); + } + return Integer.MAX_VALUE; // 패턴이 일치하지 않을 경우 높은 값 반환 + } }