-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/#112 이미지 ocr
- Loading branch information
Showing
6 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package play.pluv.playlist.infra; | ||
|
||
import java.util.List; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.service.annotation.PostExchange; | ||
import play.pluv.playlist.infra.dto.OcrMusicRequest; | ||
import play.pluv.playlist.infra.dto.OcrMusicResponse; | ||
|
||
public interface OcrApiClient { | ||
|
||
@PostExchange("http://192.168.0.22:8000/ocr") | ||
List<OcrMusicResponse> ocrPlayListImage(@RequestBody final OcrMusicRequest request); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package play.pluv.playlist.infra; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import play.pluv.playlist.domain.PlayListMusic; | ||
import play.pluv.playlist.infra.dto.OcrMusicRequest; | ||
import play.pluv.playlist.infra.dto.OcrMusicResponse; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class OcrReader { | ||
|
||
private final OcrApiClient ocrApiClient; | ||
|
||
public List<PlayListMusic> ocrImages(final List<String> base64EncodedImages) { | ||
final OcrMusicRequest request = OcrMusicRequest.from(base64EncodedImages); | ||
return ocrApiClient.ocrPlayListImage(request).stream() | ||
.map(OcrMusicResponse::toPlayListMusic) | ||
.toList(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/play/pluv/playlist/infra/dto/OcrMusicRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package play.pluv.playlist.infra.dto; | ||
|
||
import java.util.List; | ||
|
||
public record OcrMusicRequest( | ||
List<Base64EncodedImage> images | ||
) { | ||
|
||
public static OcrMusicRequest from(final List<String> base64EncodedImages) { | ||
return new OcrMusicRequest( | ||
base64EncodedImages.stream() | ||
.map(Base64EncodedImage::new) | ||
.toList() | ||
); | ||
} | ||
|
||
private record Base64EncodedImage(String base64EncodedImage) { | ||
|
||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/play/pluv/playlist/infra/dto/OcrMusicResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package play.pluv.playlist.infra.dto; | ||
|
||
import java.util.List; | ||
import play.pluv.playlist.domain.PlayListMusic; | ||
|
||
public record OcrMusicResponse( | ||
String artistNames, String songTitle | ||
) { | ||
|
||
public PlayListMusic toPlayListMusic() { | ||
return new PlayListMusic(songTitle, List.of(artistNames), null, ""); | ||
} | ||
} |