Skip to content

Commit

Permalink
Merge pull request #18 from Fairy-Taless/feature/#4-face
Browse files Browse the repository at this point in the history
Feature/#4 face
  • Loading branch information
junhaa authored May 3, 2024
2 parents e8c82c8 + ae75f31 commit eb53801
Show file tree
Hide file tree
Showing 19 changed files with 498 additions and 27 deletions.
70 changes: 43 additions & 27 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,52 +1,68 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
id 'java'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
}

group = 'fairytale'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
sourceCompatibility = '17'
}

// build 이름 변경
jar {
archiveBaseName = 'fairytale'
version = '0.0.1-SNAPSHOT'
enabled = false
jar{
archiveBaseName = 'fairytale'
version = '0.0.1-SNAPSHOT'
enabled = false
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'

//logging
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
modules {
module("org.springframework.boot:spring-boot-starter-logging") {
replacedBy("org.springframework.boot:spring-boot-starter-log4j2")
}
}
//logging
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
modules {
module("org.springframework.boot:spring-boot-starter-logging") {
replacedBy("org.springframework.boot:spring-boot-starter-log4j2")
}
}

// ElevenLabs API
implementation('net.andrewcpu:elevenlabs-api:2.7.8')
// ElevenLabs API
implementation ('net.andrewcpu:elevenlabs-api:2.7.8')

// AWS
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
// AWS
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// Face Swap API
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'org.json:json:20200518'

// Face Swap API
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'org.json:json:20200518'

// Face Swap API
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'org.json:json:20200518'

// Spring Security OAUTH 2.1
implementation 'org.springframework.boot:spring-boot-starter-security'
Expand All @@ -62,5 +78,5 @@ dependencies {
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fairytale.tbd.domain.faceSwap.converter;

import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto;

public class FaceDetectConverter {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fairytale.tbd.domain.faceSwap.entity;

import fairytale.tbd.domain.fairytale.entity.Fairytale;
import fairytale.tbd.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CustomCharacter {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long customId;

private String customURL;

@OneToOne
@JoinColumn(name = "userId")
private User userId;


@ManyToOne
@JoinColumn(name = "fairytale_id")
private Fairytale fairytaleId;

public void setUserId(User userId) {
this.userId = userId;
}

public void setFairytaleId(Fairytale fairytaleId) {
this.fairytaleId = fairytaleId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package fairytale.tbd.domain.faceSwap.entity;

import fairytale.tbd.domain.fairytale.entity.Fairytale;
import fairytale.tbd.domain.user.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OriginalCharacter {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long originId;

private String originalURL;

@ManyToOne
@JoinColumn(name = "fairytale_id")
private Fairytale fairytaleId;

@ManyToOne
@JoinColumn(name = "userId")
private User user;

public void setUser(User user){
this.user = user;
}

public void setFairytaleId(Fairytale fairytaleId) {
this.fairytaleId = fairytaleId;
}

}
18 changes: 18 additions & 0 deletions src/main/java/fairytale/tbd/domain/faceSwap/entity/Uuid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fairytale.tbd.domain.faceSwap.entity;

import jakarta.persistence.*;
import lombok.*;
@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)

public class Uuid {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long uuidId;

@Column(unique = true)
private String uuid;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fairytale.tbd.domain.faceSwap.repository;

import fairytale.tbd.domain.faceSwap.entity.CustomCharacter;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CustomCharacterRepository extends JpaRepository<CustomCharacter, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fairytale.tbd.domain.faceSwap.repository;

import fairytale.tbd.domain.faceSwap.entity.OriginalCharacter;
import org.springframework.data.jpa.repository.JpaRepository;

public interface OriginalCharacterRepository extends JpaRepository<OriginalCharacter, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fairytale.tbd.domain.faceSwap.repository;

import fairytale.tbd.domain.faceSwap.entity.Uuid;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UuidRepository extends JpaRepository<Uuid, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fairytale.tbd.domain.faceSwap.service;

import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto;
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto;

import java.io.IOException;

public interface FaceDetectApiService {
FaceDetectResponseDto getOptFromFaceDetectApi(FaceDetectRequestDto faceDetectRequestDto) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package fairytale.tbd.domain.faceSwap.service;

import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto;
import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto;
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapRequestDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.logging.LogManager;
import java.util.logging.Logger;


@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class FaceDetectApiServiceImpl implements FaceDetectApiService{

@Value("${face.akool.apikey}")
private static String apiKey;


@Override
public FaceDetectResponseDto getOptFromFaceDetectApi(FaceDetectRequestDto faceDetectRequestDto) throws IOException {


String landmarkStr = "";

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");

String requestBodyJson = "{\n" +
" \"single_face\": true, \n" +
" \"image_url\": \"" + faceDetectRequestDto.getImgURL() + "\"\n" +
"}";

RequestBody body = RequestBody.create(mediaType, requestBodyJson);

Request request = new Request.Builder()
.url("https://sg3.akool.com/detect")
.method("POST", body)
.addHeader("Authorization", "Bearer " + apiKey)
.addHeader("Content-Type", "application/json")
.build();

try (Response response = client.newCall(request).execute()){

if(!response.isSuccessful()){
throw new IOException("Unexpected code " + response);
}

String responseData = response.body().string();

JSONObject jsonObject = new JSONObject(responseData);

int errCode = jsonObject.getInt("error_code");
String errorMsg = jsonObject.getString("error_msg");

if(errCode!=0 || !errorMsg.equals("SUCCESS")){
throw new IOException("Error! \n" +
"error code : " +
errCode + "\n" +
"error massage : " +
errorMsg + "\n");
}

landmarkStr = jsonObject.getString("landmarks_str");
} catch (IOException e) {

e.printStackTrace();

}

return FaceDetectResponseDto.builder()
.photoUrl(faceDetectRequestDto.getImgURL())
.opt(landmarkStr)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package fairytale.tbd.domain.faceSwap.service;

import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto;
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapResponseDto;

public interface FaceSwapApiService {
/*FaceSwapResponseDto*/void getFaceSwapImg(FaceDetectResponseDto faceDetectResponseDto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fairytale.tbd.domain.faceSwap.service;

import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectResponseDto;
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapRequestDto;
import fairytale.tbd.domain.faceSwap.web.dto.FaceSwapResponseDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class FaceSwapApiServiceImpl implements FaceSwapApiService{

// 여기에서 originalCharacter, customCharacter 둘 다에 사용할 수 있게끔 한다.
@Override
@Transactional
public void getFaceSwapImg(FaceDetectResponseDto faceDetectResponseDto){
FaceSwapRequestDto.FaceSwapRequest faceSwapRequest = new FaceSwapRequestDto.FaceSwapRequest();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fairytale.tbd.domain.faceSwap.service;

import fairytale.tbd.domain.faceSwap.web.dto.FaceDetectRequestDto;
import fairytale.tbd.domain.user.entity.User;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

public interface PhotoUploadService {
FaceDetectRequestDto savePhotos(User userId, MultipartFile photoUploadRequestDto) throws IOException;
}
Loading

0 comments on commit eb53801

Please sign in to comment.