Update handler.py
Browse files- handler.py +19 -12
handler.py
CHANGED
|
@@ -5,20 +5,19 @@ import cv2
|
|
| 5 |
import base64
|
| 6 |
from ultralytics import YOLO
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
class EndpointHandler:
|
| 10 |
def __init__(self, path='.'): # pass api key to model
|
| 11 |
-
current_directory = os.getcwd()
|
| 12 |
-
print("Current working directory:", current_directory)
|
| 13 |
-
files_and_directories = os.listdir()
|
| 14 |
-
|
| 15 |
-
# Print each file and directory
|
| 16 |
-
for item in files_and_directories:
|
| 17 |
-
print(item)
|
| 18 |
-
|
| 19 |
-
self.model = YOLO("./best.pt")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|
|
|
| 22 |
inputs = data.get("inputs")
|
| 23 |
isurl = inputs.get("isurl")
|
| 24 |
path = inputs.get("path")
|
|
@@ -64,7 +63,7 @@ class EndpointHandler:
|
|
| 64 |
########################### Data proccessing #################################
|
| 65 |
# only pass the first detection
|
| 66 |
# change 1 -> to len(detections.xyxy) to pass all photos
|
| 67 |
-
if(detections.xyxy.
|
| 68 |
return "Not Found"
|
| 69 |
else:
|
| 70 |
x1, y1, x2, y2 = int(detections.xyxy[0][0]), int(detections.xyxy[0][1]), int(detections.xyxy[0][2]), int(detections.xyxy[0][3])
|
|
@@ -81,9 +80,17 @@ class EndpointHandler:
|
|
| 81 |
|
| 82 |
|
| 83 |
# test run
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
# test file image
|
| 86 |
-
|
| 87 |
|
| 88 |
#test url
|
| 89 |
# print(Model("http://10.10.2.100/cam-lo.jpg", 1))
|
|
|
|
| 5 |
import base64
|
| 6 |
from ultralytics import YOLO
|
| 7 |
import os
|
| 8 |
+
import gdown
|
| 9 |
|
| 10 |
class EndpointHandler:
|
| 11 |
def __init__(self, path='.'): # pass api key to model
|
| 12 |
+
# current_directory = os.getcwd()
|
| 13 |
+
# print("Current working directory:", current_directory)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
url = "https://drive.google.com/uc?id=1jB8sDYYOTfuF7B1PMcDjkm5R7huv97Wm"
|
| 16 |
+
gdown.download(url, './best.pt', quiet=False)
|
| 17 |
+
|
| 18 |
+
self.model = YOLO("./best.pt")
|
| 19 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 20 |
+
os.getcwd()
|
| 21 |
inputs = data.get("inputs")
|
| 22 |
isurl = inputs.get("isurl")
|
| 23 |
path = inputs.get("path")
|
|
|
|
| 63 |
########################### Data proccessing #################################
|
| 64 |
# only pass the first detection
|
| 65 |
# change 1 -> to len(detections.xyxy) to pass all photos
|
| 66 |
+
if(detections.xyxy.shape[0] == 0):
|
| 67 |
return "Not Found"
|
| 68 |
else:
|
| 69 |
x1, y1, x2, y2 = int(detections.xyxy[0][0]), int(detections.xyxy[0][1]), int(detections.xyxy[0][2]), int(detections.xyxy[0][3])
|
|
|
|
| 80 |
|
| 81 |
|
| 82 |
# test run
|
| 83 |
+
Model = EndpointHandler()
|
| 84 |
+
data = {
|
| 85 |
+
"inputs": {
|
| 86 |
+
"isurl": True,
|
| 87 |
+
# "path": "http://10.10.2.100/cam-lo.jpg",
|
| 88 |
+
"path": "https://www.next.us/nxtcms/resource/blob/5791586/ee0fc6a294be647924fa5f5e7e3df8e9/hoodies-data.jpg",
|
| 89 |
+
# "key": "iJuYzEzNEFSaQq4e0hfE",
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
# test file image
|
| 93 |
+
print(Model(data))
|
| 94 |
|
| 95 |
#test url
|
| 96 |
# print(Model("http://10.10.2.100/cam-lo.jpg", 1))
|