Spaces:
Paused
Paused
Update tools/detect_elements.py
Browse files- tools/detect_elements.py +11 -1
tools/detect_elements.py
CHANGED
|
@@ -4,6 +4,9 @@ import numpy as np
|
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
from typing import Optional
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
class DetectElementsTool(Tool):
|
| 9 |
name = "detect_elements"
|
|
@@ -14,7 +17,14 @@ class DetectElementsTool(Tool):
|
|
| 14 |
}
|
| 15 |
output_type = "string"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def forward(self, screenshot_path: Optional[str], element_type="table"):
|
|
|
|
|
|
|
| 18 |
try:
|
| 19 |
if not os.path.exists(screenshot_path):
|
| 20 |
return f"Screenshot not found: {screenshot_path}"
|
|
@@ -55,4 +65,4 @@ class DetectElementsTool(Tool):
|
|
| 55 |
"output_image": output_path
|
| 56 |
}) if detections else "No elements detected"
|
| 57 |
except Exception as e:
|
| 58 |
-
return f"Failed to detect elements: {str(e)}"
|
|
|
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
from typing import Optional
|
| 7 |
+
import logging
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
class DetectElementsTool(Tool):
|
| 12 |
name = "detect_elements"
|
|
|
|
| 17 |
}
|
| 18 |
output_type = "string"
|
| 19 |
|
| 20 |
+
def __init__(self):
|
| 21 |
+
super().__init__()
|
| 22 |
+
self.is_initialized = True # No external dependencies like driver, so always True
|
| 23 |
+
logger.debug(f"DetectElementsTool initialized: is_initialized={self.is_initialized}")
|
| 24 |
+
|
| 25 |
def forward(self, screenshot_path: Optional[str], element_type="table"):
|
| 26 |
+
if not self.is_initialized:
|
| 27 |
+
return "Error: DetectElementsTool is not initialized"
|
| 28 |
try:
|
| 29 |
if not os.path.exists(screenshot_path):
|
| 30 |
return f"Screenshot not found: {screenshot_path}"
|
|
|
|
| 65 |
"output_image": output_path
|
| 66 |
}) if detections else "No elements detected"
|
| 67 |
except Exception as e:
|
| 68 |
+
return f"Failed to detect elements: {str(e)}"
|