From f3c5220e1dd252dcbd3796d66c806723890b4b30 Mon Sep 17 00:00:00 2001 From: YulHee Kim Date: Tue, 1 Jun 2021 04:14:40 +0900 Subject: [PATCH 1/2] =?UTF-8?q?S3=20=ED=8C=8C=EC=9D=BC=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SmartCane/smartcane_app/views.py | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/SmartCane/smartcane_app/views.py b/SmartCane/smartcane_app/views.py index f2cd1a9..a78aeac 100644 --- a/SmartCane/smartcane_app/views.py +++ b/SmartCane/smartcane_app/views.py @@ -13,6 +13,7 @@ import tensorflow as tf import os import io +from io import BytesIO import numpy as np from PIL import Image import time @@ -20,6 +21,9 @@ import json from django.http import JsonResponse from collections import ChainMap +from django.conf import settings +import boto3 +import uuid gpus = tf.config.experimental.list_physical_devices('GPU') @@ -38,7 +42,7 @@ file_name = os.path.dirname(__file__) + '/pspunet_weight.h5' model = keras.models.load_model(file_name) - +print(tf.__version__) #result = {} result_list = [] @@ -138,12 +142,38 @@ async def caution_async_process(): @api_view(['GET','POST']) def direction(request): if request.method == "POST": - bytes = request.FILES['file'].file.getvalue() + get_file = request.FILES['file'] + bytes = get_file.file.getvalue() image = Image.open(io.BytesIO(bytes)).convert("RGB") result_list.clear() predict(image) newdict = {} newdict["result"]=result_list + + access_key = settings.AWS_ACCESS_KEY_ID + access_secret_key = settings.AWS_SECRET_ACCESS_KEY + bucket_name = settings.AWS_STORAGE_BUCKET_NAME + + s3_client = boto3.client( + 's3', + aws_access_key_id = access_key, + aws_secret_access_key = access_secret_key + ) + im = Image.open(get_file) + im = im.resize((480, 272)) + buffer = BytesIO() + im.save(buffer, "JPEG") + buffer.seek(0) + + url_generator = str(uuid.uuid4()) + s3_client.upload_fileobj( + buffer, + "jgback", + url_generator, + ExtraArgs = { + "ContentType": 'image/jpeg' + } + ) return JsonResponse(newdict) else: return JsonResponse("GET Method") From a62a88642f04215bab768ec4eb45f690ba37e22f Mon Sep 17 00:00:00 2001 From: YulHee Kim Date: Fri, 4 Jun 2021 23:01:23 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=ED=95=84=EC=9A=94=EC=97=86=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SmartCane/smartcane_app/serializers.py | 24 +----------------------- SmartCane/smartcane_app/views.py | 1 - 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/SmartCane/smartcane_app/serializers.py b/SmartCane/smartcane_app/serializers.py index fb72593..c7dec7f 100644 --- a/SmartCane/smartcane_app/serializers.py +++ b/SmartCane/smartcane_app/serializers.py @@ -1,24 +1,2 @@ -from rest_framework import serializers -#from django.core.serializers import serialize - -class DirectionSerializer(serializers.Serializer): - result = serializers.CharField() - - class Meta: - fields = ('result') - - -class Image(object): - def __init__(self,): - self.image = image - -class ImageSerializer(serializers.Serializer): - image = serializers.FileField() - - class Meta: - fields = ('image') - - # def create(self, validated_data): - # return Image(**validated_data) - + \ No newline at end of file diff --git a/SmartCane/smartcane_app/views.py b/SmartCane/smartcane_app/views.py index a78aeac..9213e9f 100644 --- a/SmartCane/smartcane_app/views.py +++ b/SmartCane/smartcane_app/views.py @@ -1,7 +1,6 @@ from django.shortcuts import render from rest_framework import views from rest_framework.response import Response -from .serializers import DirectionSerializer, ImageSerializer from rest_framework.decorators import api_view from rest_framework.views import APIView from django.http.response import JsonResponse