Update handler.py
Browse files4 unmodified lines56789101111121314151617181912131415161718192021222339 unmodified lines636465676667686910 unmodified lines808182848384858687888990919286939495964 unmodified linesimport base64from ultralytics import YOLOimport osimport gdown
class EndpointHandler: def __init__(self, path='.'): # pass api key to model current_directory = os.getcwd() print("Current working directory:", current_directory) files_and_directories = os.listdir()
# Print each file and directory for item in files_and_directories: print(item) self.model = YOLO("./best.pt") # 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 photos if(detections.xyxy.size == 0): if(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 run # Model = Image_detect()Model = 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 image# print(Model("test_images/test6.jpg", 0))print(Model(data))
#test url# print(Model("http://10.10.2.100/cam-lo.jpg", 1))handler.py+19-12