Skip to content

Commit

Permalink
feat : 생성형 이미지 생성을 위한 정보 csv 파일로 저장 및 포스터 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
lkl4502 committed May 20, 2024
1 parent de2d603 commit 3b93d68
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public FlaskController(FlaskService flaskService){
@RequestMapping(value = "/start", method = RequestMethod.POST)
public PredictResult start(@RequestPart("data") StartDto startDto,
@RequestPart("file") MultipartFile image){
Map<String, Object> predict_color_res = flaskService.predict_color_flask(image);
Map<String, Object> predict_color_res = flaskService.predict_color_flask(image, startDto);
Map<String, Object> predict_shape_res = flaskService.predict_shape_flask();

PredictResult predict_result = new PredictResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
public class StartDto {
String email;
String gender;
Boolean gan_permission = false;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.capstone2024.onlyu.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.capstone2024.onlyu.dto.StartDto;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
Expand All @@ -22,14 +25,23 @@
public class FlaskService {

@Transactional
public Map<String, Object> predict_color_flask(MultipartFile image){
public Map<String, Object> predict_color_flask(MultipartFile image, StartDto startDto){
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());

ObjectMapper objectMapper = new ObjectMapper();
String startDtoJson;
try {
startDtoJson = objectMapper.writeValueAsString(startDto);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
body.add("data", startDtoJson);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
return restTemplate.postForObject(url, requestEntity, Map.class);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Feature/camera.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function Camera() {
const data = {
email: email,
gender: gender,
gan_permission: createImageChecked,
};

formdata.append(
Expand Down
1 change: 1 addition & 0 deletions info.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
email, gender, gan_permission, image_path
13 changes: 11 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import shutil
import base64

from flask import Flask, request, jsonify
from flask import Flask, request
import json

import shape_detect.controller

app = Flask(__name__)

image_path = os.path.join(os.path.dirname(__file__), "predict_image")
info_path = os.path.join(os.path.dirname(__file__), "info.csv")
filename = ""
pc_model : PersonalColorModel = joblib.load('./model_v2.pkl')
ss = joblib.load("./scaler_v2.pkl")
Expand All @@ -33,11 +35,13 @@ def hello_world():
def predict_color():
global features, pc_model, ss, current_image_path
# 이미지 저장

f = request.files['image']
data = json.loads(request.form.get("data"))

type = f.filename[f.filename.rfind("."):]

folder_path = os.path.join(image_path, f.filename.replace(".", "_"))
folder_path = os.path.join(image_path, data["email"])
f_path = os.path.join(folder_path, "origin_img" + type)

if os.path.exists(folder_path):
Expand All @@ -47,6 +51,11 @@ def predict_color():

f.save(f_path)

# 생성형 이미지를 위한 정보 저장
df = pd.read_csv(info_path)
df.loc[len(df)] = [data["email"], data["gender"], data["gan_permission"], f_path]
df.to_csv(info_path, mode = 'w', index=False)

current_image_path = f_path[:]
print(current_image_path)

Expand Down
Binary file modified only_you_poster.pdf
Binary file not shown.

0 comments on commit 3b93d68

Please sign in to comment.