-
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.
Merge pull request #89 from Princess-in-silvertown/feat/87
Feat: 이미지 모델 연결 & S3 저장 로직 생성
- Loading branch information
Showing
21 changed files
with
218 additions
and
184 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
33 changes: 33 additions & 0 deletions
33
src/main/java/slvtwn/khu/toyouserver/agent/aws/AwsConfiguration.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,33 @@ | ||
package slvtwn.khu.toyouserver.agent.aws; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import lombok.Getter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Configuration | ||
public class AwsConfiguration { | ||
|
||
@Value("${cloud.aws.credentials.access-key}") | ||
private String accessKey; | ||
@Value("${cloud.aws.credentials.secret-key}") | ||
private String secretKey; | ||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucket; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); | ||
return (AmazonS3Client) AmazonS3ClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/slvtwn/khu/toyouserver/agent/aws/S3Agent.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,37 @@ | ||
package slvtwn.khu.toyouserver.agent.aws; | ||
|
||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import java.io.ByteArrayInputStream; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import slvtwn.khu.toyouserver.common.response.ResponseType; | ||
import slvtwn.khu.toyouserver.exception.ToyouException; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class S3Agent { | ||
|
||
private final AmazonS3Client amazonS3Client; | ||
private final AwsConfiguration configuration; | ||
|
||
public String uploadFile(byte[] fileData, String fileName, String contentType) { | ||
try { | ||
ObjectMetadata metadata = new ObjectMetadata(); | ||
metadata.setContentType(contentType); | ||
metadata.setContentLength(fileData.length); | ||
|
||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(fileData); | ||
amazonS3Client.putObject(new PutObjectRequest(configuration.getBucket(), fileName, byteArrayInputStream, metadata)); | ||
|
||
return fileName; | ||
} catch (Exception e) { | ||
throw new ToyouException(ResponseType.INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
public String getUrl(String key) { | ||
return amazonS3Client.getResourceUrl(configuration.getBucket(), key); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/slvtwn/khu/toyouserver/agent/model/StickerModelAgent.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,27 @@ | ||
package slvtwn.khu.toyouserver.agent.model; | ||
|
||
import java.util.Base64; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import slvtwn.khu.toyouserver.agent.WebClientWrapper; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class StickerModelAgent { | ||
|
||
private final StickerModelConfiguration configuration; | ||
|
||
private final WebClientWrapper webClientWrapper; | ||
|
||
public List<byte[]> generateStickers(StickerModelRequest request) { | ||
StickerModelResponse response = webClientWrapper.send( | ||
configuration.getEndpoint(), (httpHeaders -> { | ||
}), request, StickerModelResponse.class | ||
); | ||
|
||
return response.base64EncodedImages().stream() | ||
.map(each -> Base64.getDecoder().decode(each)) | ||
.toList(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/slvtwn/khu/toyouserver/agent/model/StickerModelConfiguration.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 slvtwn.khu.toyouserver.agent.model; | ||
|
||
import lombok.Getter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Getter | ||
@Component | ||
public class StickerModelConfiguration { | ||
|
||
@Value("${sticker-model.endpoint}") | ||
private String endpoint; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/slvtwn/khu/toyouserver/agent/model/StickerModelRequest.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,5 @@ | ||
package slvtwn.khu.toyouserver.agent.model; | ||
|
||
public record StickerModelRequest(String prompt, String color) { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/slvtwn/khu/toyouserver/agent/model/StickerModelResponse.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,7 @@ | ||
package slvtwn.khu.toyouserver.agent.model; | ||
|
||
import java.util.List; | ||
|
||
public record StickerModelResponse(List<String> base64EncodedImages) { | ||
|
||
} |
26 changes: 0 additions & 26 deletions
26
src/main/java/slvtwn/khu/toyouserver/agent/modellabs/MetaDataResponse.java
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
src/main/java/slvtwn/khu/toyouserver/agent/modellabs/ModelLabsAgent.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/main/java/slvtwn/khu/toyouserver/agent/modellabs/ModelLabsConfiguration.java
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
src/main/java/slvtwn/khu/toyouserver/agent/modellabs/ModelLabsRequest.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/main/java/slvtwn/khu/toyouserver/agent/modellabs/ModelLabsResponse.java
This file was deleted.
Oops, something went wrong.
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
5 changes: 5 additions & 0 deletions
5
src/main/java/slvtwn/khu/toyouserver/dto/GenerateStickerRequest.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,5 @@ | ||
package slvtwn.khu.toyouserver.dto; | ||
|
||
public record GenerateStickerRequest(String prompt, String color) { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/slvtwn/khu/toyouserver/dto/GenerateStickerResponse.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,7 @@ | ||
package slvtwn.khu.toyouserver.dto; | ||
|
||
import java.util.List; | ||
|
||
public record GenerateStickerResponse(List<String> stickers) { | ||
|
||
} |
Oops, something went wrong.