Skip to content

Commit eb6901d

Browse files
committed
resolve conflict
2 parents f9ba953 + 53dba52 commit eb6901d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+87
-43
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
env
2+
__pycache__

api/__pycache__/conf.cpython-38.pyc

-243 Bytes
Binary file not shown.

api/__pycache__/main.cpython-38.pyc

-573 Bytes
Binary file not shown.

api/__pycache__/utils.cpython-38.pyc

-483 Bytes
Binary file not shown.

api/conf.py conf.py

File renamed without changes.

api/load.py load.py

File renamed without changes.

main.py

+28-41
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,37 @@
1-
from string import ascii_lowercase
2-
from random import choice, randint, random
3-
from datetime import date
4-
import cv2
5-
import numpy as np
1+
from flask import Flask, request
2+
import json
63

7-
import os
8-
import shutil
4+
from utils import get_database
5+
from model_dir.detect import load_image_and_detect
96

10-
from io import BytesIO
11-
from PIL import Image
12-
import base64
137

14-
from detect import *
8+
app = Flask(__name__)
9+
clientDB = get_database()
1510

16-
model_weights_dir= 'model_weights/best.pt'
17-
temp_save_dir= 'temp_save_dir'
11+
# @app.route("/")
12+
# def hello_world():
13+
# return "<p>Hello, World!</p>"
1814

19-
if not os.path.isdir(temp_save_dir):
20-
os.mkdir(temp_save_dir)
15+
@app.route("/animals/<ids>")
16+
def getAnimalById(ids):
17+
id_list = ids.split("-")
18+
id_list = set(id_list)
19+
animalCollection = clientDB["animals"]
20+
response = {}
21+
for id in id_list:
22+
animal = animalCollection.find({"id" : id})
23+
animal = list(animal)[0]
24+
del animal["_id"]
25+
response[id] = animal
2126

22-
save_image_format= 'jpg'
27+
return response
2328

24-
def generate_random_image_dir(base_dir='temp_save_dir', save_image_format= 'jpg'):
25-
unique_image_name = f"{''.join([choice(ascii_lowercase) for _ in range(randint(2, 10))])}_{date.today()}.{save_image_format}"
29+
@app.route("/detect", methods=['POST'])
30+
def detect():
31+
base64Image = json.loads(request.data)
32+
base64Image = base64Image['image']
2633

27-
return os.path.join(base_dir, unique_image_name)
34+
return load_image_and_detect(base64Image)
2835

29-
def load_image_and_detect(base64_image):
30-
read_base64= base64_image.encode()
31-
read_base64= base64.decodebytes(read_base64)
32-
33-
img= Image.open(BytesIO(read_base64))
34-
img= np.array(img)
35-
36-
unique_image_dir= generate_random_image_dir(temp_save_dir, save_image_format)
37-
38-
while os.path.isfile(unique_image_dir):
39-
unique_image_dir= generate_random_image_dir(temp_save_dir, save_image_format)
40-
41-
cv2.imwrite(unique_image_dir,img)
42-
43-
return_json= detect(unique_image_dir)
44-
45-
try:
46-
os.remove(unique_image_dir)
47-
except:
48-
pass
49-
50-
return return_json
36+
if __name__ == "__main__":
37+
app.run(debug=True)

LICENSE.md model_dir/LICENSE.md

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

detect.py model_dir/detect.py

+56-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
from pathlib import Path
33

4-
from models.experimental import attempt_load
4+
from .models.experimental import attempt_load
55
from utils.datasets import LoadImages
66
from utils.general import check_img_size, non_max_suppression, \
77
scale_coords, set_logging
@@ -107,4 +107,58 @@ def detect(source, trace=False, weights='model_weights/best.pt', img_size=512, c
107107
result['object_detected']= json_object_detected
108108

109109

110-
return json.dumps(result)
110+
return json.dumps(result)
111+
112+
113+
114+
from string import ascii_lowercase
115+
from random import choice, randint, random
116+
from datetime import date
117+
import numpy as np
118+
119+
import os
120+
import shutil
121+
122+
from io import BytesIO
123+
from PIL import Image
124+
import base64
125+
126+
127+
model_weights_dir= 'model_weights/best.pt'
128+
temp_save_dir= 'temp_save_dir'
129+
130+
if not os.path.isdir(temp_save_dir):
131+
os.mkdir(temp_save_dir)
132+
133+
save_image_format= 'jpg'
134+
135+
def generate_random_image_dir(base_dir='temp_save_dir', save_image_format= 'jpg'):
136+
unique_image_name = f"{''.join([choice(ascii_lowercase) for _ in range(randint(2, 10))])}_{date.today()}.{save_image_format}"
137+
138+
return os.path.join(base_dir, unique_image_name)
139+
140+
def load_image_and_detect(base64_image):
141+
read_base64= base64_image.encode()
142+
read_base64= base64.decodebytes(read_base64)
143+
144+
img= Image.open(BytesIO(read_base64))
145+
img= np.array(img)
146+
147+
unique_image_dir= generate_random_image_dir(temp_save_dir, save_image_format)
148+
149+
while os.path.isfile(unique_image_dir):
150+
unique_image_dir= generate_random_image_dir(temp_save_dir, save_image_format)
151+
152+
cv2.imwrite(unique_image_dir,img)
153+
154+
return_json= detect(unique_image_dir)
155+
156+
try:
157+
os.remove(unique_image_dir)
158+
except:
159+
pass
160+
161+
return return_json
162+
163+
def hello_name(name):
164+
print("hello " + name)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

model_dir/test.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello():
2+
return "hello world"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

api/utils.py utils.py

File renamed without changes.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)