Update handler.py
Browse files4 unmodified lines5678910111213141516171819202122232439 unmodified lines6465666768697010 unmodified lines8182838485868788894 unmodified linesimport base64from ultralytics import YOLOimport osclass EndpointHandler:def __init__(self, path='.'): # pass api key to modelcurrent_directory = os.getcwd()print("Current working directory:", current_directory)files_and_directories = os.listdir()# Print each file and directoryfor item in files_and_directories:print(item)self.model = YOLO("./best.pt")def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:inputs = data.get("inputs")isurl = inputs.get("isurl")path = inputs.get("path")39 unmodified lines########################### Data proccessing ################################## only pass the first detection# change 1 -> to len(detections.xyxy) to pass all photosif(detections.xyxy.size == 0):return "Not Found"else:x1, y1, x2, y2 = int(detections.xyxy[0][0]), int(detections.xyxy[0][1]), int(detections.xyxy[0][2]), int(detections.xyxy[0][3])10 unmodified lines# test run# Model = Image_detect()# test file image# print(Model("test_images/test6.jpg", 0))#test url# print(Model("http://10.10.2.100/cam-lo.jpg", 1))4 unmodified lines56789101112131415161718192021222339 unmodified lines6364656667686910 unmodified lines80818283848586878889909192939495964 unmodified linesimport base64from ultralytics import YOLOimport osimport gdownclass EndpointHandler:def __init__(self, path='.'): # pass api key to model# current_directory = os.getcwd()# print("Current working directory:", current_directory)url = "https://drive.google.com/uc?id=1jB8sDYYOTfuF7B1PMcDjkm5R7huv97Wm"gdown.download(url, './best.pt', quiet=False)self.model = YOLO("./best.pt")def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:os.getcwd()inputs = data.get("inputs")isurl = inputs.get("isurl")path = inputs.get("path")39 unmodified lines########################### Data proccessing ################################## only pass the first detection# change 1 -> to len(detections.xyxy) to pass all photosif(detections.xyxy.shape[0] == 0):return "Not Found"else:x1, y1, x2, y2 = int(detections.xyxy[0][0]), int(detections.xyxy[0][1]), int(detections.xyxy[0][2]), int(detections.xyxy[0][3])10 unmodified lines# test runModel = EndpointHandler()data = {"inputs": {"isurl": True,# "path": "http://10.10.2.100/cam-lo.jpg","path": "https://www.next.us/nxtcms/resource/blob/5791586/ee0fc6a294be647924fa5f5e7e3df8e9/hoodies-data.jpg",# "key": "iJuYzEzNEFSaQq4e0hfE",}}# test file imageprint(Model(data))#test url# print(Model("http://10.10.2.100/cam-lo.jpg", 1))
handler.py+19-12