Spaces:
Sleeping
Sleeping
Update pest/mcp_output/mcp_plugin/mcp_service.py
Browse files
pest/mcp_output/mcp_plugin/mcp_service.py
CHANGED
|
@@ -47,19 +47,32 @@ def preprocess_image_tool(image_path: str) -> dict:
|
|
| 47 |
return {"success": False, "result": None, "error": str(e)}
|
| 48 |
|
| 49 |
@mcp.tool(name="detect_pest", description="Detect pests in an image using the loaded model")
|
| 50 |
-
def detect_pest_tool(model:
|
| 51 |
"""
|
| 52 |
Detect pests in an image using the loaded model.
|
| 53 |
|
| 54 |
Parameters:
|
| 55 |
-
model (
|
| 56 |
-
image_data (
|
| 57 |
|
| 58 |
Returns:
|
| 59 |
dict: A dictionary containing success status and detection results.
|
| 60 |
"""
|
| 61 |
try:
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
return {"success": True, "result": detection_results, "error": None}
|
| 64 |
except Exception as e:
|
| 65 |
return {"success": False, "result": None, "error": str(e)}
|
|
|
|
| 47 |
return {"success": False, "result": None, "error": str(e)}
|
| 48 |
|
| 49 |
@mcp.tool(name="detect_pest", description="Detect pests in an image using the loaded model")
|
| 50 |
+
def detect_pest_tool(model: object, image_data: object) -> dict:
|
| 51 |
"""
|
| 52 |
Detect pests in an image using the loaded model.
|
| 53 |
|
| 54 |
Parameters:
|
| 55 |
+
model (object): The loaded pest detection model (dict or JSON string).
|
| 56 |
+
image_data (object): Preprocessed image data (dict or JSON string).
|
| 57 |
|
| 58 |
Returns:
|
| 59 |
dict: A dictionary containing success status and detection results.
|
| 60 |
"""
|
| 61 |
try:
|
| 62 |
+
import json
|
| 63 |
+
|
| 64 |
+
# Handle both dict and string inputs
|
| 65 |
+
if isinstance(model, str):
|
| 66 |
+
model_dict = json.loads(model)
|
| 67 |
+
else:
|
| 68 |
+
model_dict = model
|
| 69 |
+
|
| 70 |
+
if isinstance(image_data, str):
|
| 71 |
+
image_data_dict = json.loads(image_data)
|
| 72 |
+
else:
|
| 73 |
+
image_data_dict = image_data
|
| 74 |
+
|
| 75 |
+
detection_results = detect_pest(model_dict, image_data_dict)
|
| 76 |
return {"success": True, "result": detection_results, "error": None}
|
| 77 |
except Exception as e:
|
| 78 |
return {"success": False, "result": None, "error": str(e)}
|