guohanghui commited on
Commit
841013a
·
verified ·
1 Parent(s): ea1ecc3

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: dict, image_data: dict) -> dict:
51
  """
52
  Detect pests in an image using the loaded model.
53
 
54
  Parameters:
55
- model (dict): The loaded pest detection model.
56
- image_data (dict): Preprocessed image data.
57
 
58
  Returns:
59
  dict: A dictionary containing success status and detection results.
60
  """
61
  try:
62
- detection_results = detect_pest(model, image_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
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)}