Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/SVTeamJ/DeepBlue into ch…
Browse files Browse the repository at this point in the history
…ore/#63
  • Loading branch information
kckoh committed Jan 21, 2023
2 parents 5901b95 + a5e36b8 commit c0e601f
Show file tree
Hide file tree
Showing 34 changed files with 978 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*__pycache__*
.DS_Store
.env
aws_key.py
10 changes: 3 additions & 7 deletions backend/api/endpoints/ai.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
from .expect import fish_detect
from fastapi import File, UploadFile
from fastapi import APIRouter, Depends

from .aws.bucket import *
import json

router = APIRouter()



@router.post("/")
async def infer(file: UploadFile = File()):
content = await file.read()
filename = f"{file.filename}.jpg"
with open(filename, "wb") as fp:
fp.write(content)
post_bucket(content,filename)

result = fish_detect(filename)
with open("api/endpoints/data.json", 'r') as file:
fish_data = json.load(file)
for data in fish_data:
if data["pk"] == result:
data["url"] = "https://svj-deepblue.s3.ap-northeast-2.amazonaws.com/" + filename
return data





Empty file.
16 changes: 16 additions & 0 deletions backend/api/endpoints/aws/bucket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .connection import Connect
#from .config import S3_BUCKET
from botocore.exceptions import ClientError
S3_BUCKET="svj-deepblue"


def post_bucket(image_file: str, key_name: str):
connect = Connect()
with connect as client:
try:
client = connect.connect()
client.put_object(
Body=image_file, Bucket=S3_BUCKET, Key=key_name, ContentType="image.jpeg"
)
except ClientError as e:
print("Error during image upload. {}".format(e.response["Error"]["Code"]))
22 changes: 22 additions & 0 deletions backend/api/endpoints/aws/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import boto3
from .aws_key import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
# 해당 모듈은 버켓 보안을 위해 .gitignore 에 추가되어 있습니다. 추가 문의는 팀 리더에게 해주세요.
AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY #임시구동용

class Connect:
def __init__(self):
self.client = boto3.client(
"s3",
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)

def __enter__(self):
return self

def connect(self):
return self.client

def __exit__(self, exc_type, exc_val, exc_tb):
...
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ typing_extensions==4.4.0
urllib3==1.26.13
uvicorn==0.20.0
wcwidth==0.2.5
boto3
22 changes: 21 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-router-dom": "6.6.1",
"react-router-dom": "^6.6.1",
"react-wavify": "^1.7.0",
"recoil": "0.7.6",
"tailwindcss": "3.2.4"
},
Expand Down
Binary file added frontend/src/assets/fishimg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/house.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/image 69.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/login_whale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/png_whale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/png_whale2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/weedimg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/whale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/components/DetailFishList/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
.DetailPage_inform-input {
display: flex;
flex-direction: column;
border: 3px solid #0e1733;
border: 1.5px solid #0e1733;
padding: 1rem;
border-radius: 1rem;
min-width: 90%;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/insertImage/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
margin: 0 auto;
margin-top: 12px;
opacity: 0;
cursor: pointer;
animation: showInsertImage 1s 1.7s alternate forwards;
&:hover {
scale: 1.05;
Expand Down
52 changes: 43 additions & 9 deletions frontend/src/components/insertImage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
import Nav from '@/components/nav';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import Loading from '../loading';
import download from '@/assets/download.png';
import smallFish from '@/assets/smallFish.png';
import seaweeds from '@/assets/seaweeds.png';
import './index.scss';
import { useDropzone } from 'react-dropzone';
import { useNavigate } from 'react-router-dom';
import { useMutation } from '@tanstack/react-query';
import { restFetcher } from '@/queryClient';
import Loading2 from '../loading2';
const InsertImage = () => {
const navigate = useNavigate();
const imageRef = useRef<HTMLInputElement>(null);
const [imagefile, setImageFile] = useState<File>();
const [preview, setPreview] = useState<string>('');

const { mutate, isLoading, isSuccess, isError } = useMutation(
(formData: FormData) => {
return restFetcher({
method: 'POST',
path: 'http://localhost:8000/api/ai',
body: formData,
});
},
);

//이미지 클릭시 file선택창이 나오게하는 함수
const openFile = () => {
imageRef.current?.click();
};

const sendImage = () => {
if (!imagefile) {
alert('먼저 사진을 업로드해주세요 !');
return;
}
const formData = new FormData();
formData.append('file', imagefile);
mutate(formData, {
onSuccess: (data) =>
navigate('/result', {
state: {
data,
},
}),
});
//formData를 post요청 => 성공한다면 result페이지로 이동
};

//이미지를 올리고 저장해주는 함수
const raiseImg = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
const file = e.target?.files[0];
console.log(file);
setImageFile(file);
const formData = new FormData();
formData.append('img', file);
}
};

Expand Down Expand Up @@ -51,12 +82,13 @@ const InsertImage = () => {
<>
<div className="insert_box">
<div {...getRootProps()} onClick={openFile} className="insert_picture">
{preview && (
{isLoading ? (
<Loading2 />
) : preview ? (
<div>
<img className="insert_picture-previewImg" src={preview}></img>
</div>
)}
{!preview && (
) : (
<>
<img className="insert_picture-img" src={download} />
<p>이곳을 클릭하거나 사진을 올려주세요 !</p>
Expand All @@ -68,11 +100,13 @@ const InsertImage = () => {
onChange={raiseImg}
ref={imageRef}
type="file"
accept="image/*"
// accept="image/*"
className="hidden"
></input>
</div>
<div className="insert_search">검색</div>
<div onClick={sendImage} className="insert_search">
검색
</div>
</>
);
};
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/components/loading2/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@import '../../media.scss';

.loading {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: white;
z-index: 99;
}

.spinner {
min-width: 60px;
min-height: 60px;
border: 5px solid rgba(255, 255, 255, 0.1);
border-right: 5px solid black;
border-radius: 50%;
animation: spin 1s linear infinite;
}

@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
11 changes: 11 additions & 0 deletions frontend/src/components/loading2/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import './index.scss';
const Loading2 = () => {
return (
<div className="loading">
<div className="spinner"></div>
</div>
);
};

export default Loading2;
6 changes: 3 additions & 3 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { getClient } from './queryClient';
import * as Sentry from '@sentry/react';
import { BrowserTracing } from '@sentry/tracing';
import reset from './reset.scss';
if (import.meta) {
worker.start();
}
// if (import.meta.env.DEV) {
// worker.start();
// }
Sentry.init({
dsn: `${import.meta.env.VITE_Sentry}`,
integrations: [new BrowserTracing()],
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export interface fishInform {
description: string;
}

export interface fishResult {
fish_type: string;
toxicity: string;
open_season: string;
closed_season: string;
description: string;
}

const fishList: fishInform[] = [
{
fish_type: '갈치',
Expand Down
Loading

0 comments on commit c0e601f

Please sign in to comment.