Spaces:
Sleeping
Sleeping
Update app.py
Browse files17 unmodified lines18192021222331 unmodified lines5556575859606117 unmodified lines"""return "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:"""A tool that fetches the current local time in a specified timezone.31 unmodified linesagent = CodeAgent(model=model,tools=[final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,17 unmodified lines1819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899031 unmodified lines12212312412512612712817 unmodified lines"""return "What magic will you build ?"@tooldef simple_object_detection(image_path: str, confidence_threshold: float) -> str:"""A tool that performs simple object detection on an image using MobileNet SSD with error handling.Args:image_path: Path to the input image.confidence_threshold: Minimum confidence (e.g., 0.2) to filter weak detections.Returns:A string indicating the location of the saved processed image or an error message."""try:# List of class labels MobileNet SSD was trained onclasses = ["background", "aeroplane", "bicycle", "bird", "boat","bottle", "bus", "car", "cat", "chair", "cow","diningtable", "dog", "horse", "motorbike", "person","pottedplant", "sheep", "sofa", "train", "tvmonitor"]# Paths to the pre-trained model files (ensure these files are downloaded)prototxt_path = "MobileNetSSD_deploy.prototxt.txt"model_path = "MobileNetSSD_deploy.caffemodel"# Load the pre-trained model from disknet = cv2.dnn.readNetFromCaffe(prototxt_path, model_path)# Load the image and get its dimensionsimage = cv2.imread(image_path)if image is None:return f"Error: Image at {image_path} could not be loaded."(h, w) = image.shape[:2]# Prepare the image as a blob for the networkblob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)),scalefactor=0.007843, size=(300, 300),mean=127.5)# Pass the blob through the network to obtain detectionsnet.setInput(blob)detections = net.forward()# Loop over the detections and draw bounding boxes for those above the thresholdfor i in range(0, detections.shape[2]):confidence = detections[0, 0, i, 2]if confidence > confidence_threshold:idx = int(detections[0, 0, i, 1])# Compute bounding box coordinatesbox = detections[0, 0, i, 3:7] * np.array([w, h, w, h])(startX, startY, endX, endY) = box.astype("int")# Draw the bounding box and label on the imagelabel = f"{classes[idx]}: {confidence * 100:.2f}%"cv2.rectangle(image, (startX, startY), (endX, endY), (0, 255, 0), 2)y = startY - 10 if startY - 10 > 10 else startY + 20cv2.putText(image, label, (startX, y),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)# Save the output imageoutput_path = "output.jpg"cv2.imwrite(output_path, image)return f"Processed image saved as {output_path}"except Exception as e:return f"An error occurred: {str(e)}"@tooldef get_current_time_in_timezone(timezone: str) -> str:"""A tool that fetches the current local time in a specified timezone.31 unmodified linesagent = CodeAgent(model=model,tools=[DuckDuckGoSearchTool(), final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,
app.py+68-1