forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #36 from kookmin-sw/feat/flask_data_extract
Feat/flask data extract
- Loading branch information
Showing
9 changed files
with
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ personal_color_dataset/valid/img*.jpg | |
gan/pretrained_models | ||
gan/output | ||
predict_image/* | ||
|
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
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
45 changes: 45 additions & 0 deletions
45
backend/src/main/java/org/capstone2024/onlyu/controller/FlaskController.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,45 @@ | ||
package org.capstone2024.onlyu.controller; | ||
|
||
import com.google.gson.JsonObject; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.capstone2024.onlyu.service.FlaskService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.*; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@Slf4j | ||
public class FlaskController { | ||
private final FlaskService flaskService; | ||
@Autowired | ||
public FlaskController(FlaskService flaskService){ | ||
this.flaskService = flaskService; | ||
} | ||
|
||
// 퍼스널 컬러 예측과 피부형 검출 | ||
@RequestMapping(value = "/start", method = RequestMethod.POST) | ||
public String start(@RequestParam("email") String email, @RequestParam("gender") String gender, | ||
@RequestParam("image") MultipartFile multipartFile){ | ||
String predict_color_res = flaskService.predict_color_flask(multipartFile); | ||
String predict_shape_res = flaskService.predict_shape_flask(); | ||
|
||
JsonObject obj = new JsonObject(); | ||
obj.addProperty("predictColorRes", predict_color_res); | ||
obj.addProperty("predictShapeRes", predict_shape_res); | ||
return obj.toString(); | ||
} | ||
|
||
// @RequestMapping(value = "/gan_image", method = RequestMethod.GET) | ||
// public String gan_image(){ | ||
// Boolean res = flaskService.gan_image_flask(); | ||
// JsonObject obj = new JsonObject(); | ||
// obj.addProperty("success", res); | ||
// return obj.toString(); | ||
// } | ||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/org/capstone2024/onlyu/service/FlaskService.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,41 @@ | ||
package org.capstone2024.onlyu.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class FlaskService { | ||
|
||
@Transactional | ||
public String predict_color_flask(MultipartFile image){ | ||
RestTemplate restTemplate = new RestTemplate(); | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.MULTIPART_FORM_DATA); | ||
String url = "http://127.0.0.1:5050/predict_color"; | ||
|
||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>(); | ||
body.add("image", image.getResource()); | ||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers); | ||
return restTemplate.postForObject(url, requestEntity, String.class); | ||
} | ||
|
||
@Transactional | ||
public String predict_shape_flask(){ | ||
RestTemplate restTemplate = new RestTemplate(); | ||
String url = "http://127.0.0.1:5050/predict_shape"; | ||
|
||
return restTemplate.getForObject(url, String.class); | ||
} | ||
} |
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