Skip to content

Commit

Permalink
Feat: #24 ai-backend 커넥션 진행 중 (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
gilyeon00 committed Sep 25, 2022
1 parent 6fdb886 commit 07fd63b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
18 changes: 18 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,23 @@ def post(self):
# return "재발행", 200


from service.image_service import saveOriginImage, saveResultImage, convertImage

@ladder_api.route('/convert-image')
def post(self):
email = get_jwt_identity()
originImage = request.files['file']
resultImage = saveOriginImage(originImage, email)
resp = jsonify(resultImage)
resp.status = 201
return resp








if __name__ == '__main__':
app.run(debug=True, port=5123)
18 changes: 7 additions & 11 deletions service/image_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from api import s3_api
from entity.model import Image
from entity import database
from entity.model import db

import requests
from datetime import datetime as dt
Expand Down Expand Up @@ -42,21 +43,14 @@ def saveOriginImage(file, email) :
database.add_instance(Image, user_id = user_id, origin_url = origin_url, is_deleted = False)

# ai 셀러리 요청, 이제 요 다음부터 비동기처리
convertImage.delay(origin_url)
convertImage.delay(origin_url, user_id)

return "성공적으로 사진이 S3에 저장되었습니다."



# 변환된 사진 저장
def saveResultImage(file, email) :

# 이메일 받아오면 user_id 찾기
sql = f"SELECT user_id \
FROM user \
WHERE email='{email}'"
cursor = database.session_execute(sql)
user_id = cursor.fetchall()[0][0]
def saveResultImage(file, user_id) :

# 파일 이름 지정
filename = file.filename.split('.')[0]
Expand All @@ -79,6 +73,8 @@ def saveResultImage(file, email) :
# celery가 처리할 거
# api요청 (ai 서버)
@app.task()
def convertImage(origin_url):
result_image = requests.post(AI_CONVERT_API, origin_url)
def convertImage(origin_url, user_id):
######## 수정 필요

result_image = requests.post(AI_CONVERT_API, files=upload)
saveResultImage(result_image.content)

0 comments on commit 07fd63b

Please sign in to comment.