-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimage.py
More file actions
77 lines (49 loc) · 2.16 KB
/
image.py
File metadata and controls
77 lines (49 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from flask import Blueprint, request, jsonify
from google.cloud import storage
from dotenv import load_dotenv
import os
load_dotenv() # .env 파일 로드
bucket_name = "pj3-payday"
upload_bp = Blueprint('upload', __name__)
download_bp = Blueprint('download', __name__)
send_predict_request_bp = Blueprint('predict', __name__)
# upload는 그냥 뭐 통채로 .. 해도 .. 일단은 단일 코드
@upload_bp.route('/flaskapi/upload/<int:roomId>', methods=['POST'])
def upload_image(roomId):
if 'image' not in request.files:
return jsonify({'description': 'No image file provided'}), 400
# bucket Connections
KEY_PATH = os.environ.get('GOOGLE_APPLICATION_PATH')
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = KEY_PATH
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
#Type: blob(form_data)
images = request.files.getlist('image')
uploaded_image_urls = []
for image in images:
# try 구현 할수도 있음
content_type = image.content_type
blob = bucket.blob(image.filename)
blob.upload_from_file(image, content_type=content_type)
uploaded_image_urls.append(blob.public_url);
return jsonify({'imageUrl': uploaded_image_urls}), 200
# 버튼 하나 더 만들자.. 최종 보내기 .. 재 업로드 or 나머지만 보내기 ..
# 된다면 로딩 ㄱㄱ
#@download_bp.route('/flaskapi/download' )
'''
original_filename = image.filename_,
file_extension = os.path.splitext(original_filename)
new_filename = f"{uuid.uuid4()}{file_extension}"
'''
'''
# signal 처리, 복잡도 감소
image_uploaded = signal('image-uploaded')
@image_uploaded.connect
def send_predict_request(sender, **kwargs):
receiptId = kwargs['receiptId']
image_url = kwargs['imageUrl']
order = kwargs['order'] # 필요에 따라 order 값 설정
# 다른 Flask 서버로 요청 보내기
response = requests.post(f'http://localhost:5333/gpu/predict/{receiptId}/{order}', json={'imageUrl': image_url})
return response.json(), response.status_code
'''