OppaAI commited on
Commit
0e3d6b3
·
verified ·
1 Parent(s): 971f1e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -14
app.py CHANGED
@@ -73,36 +73,57 @@ async def process_webcam_stream_async(image):
73
  # Use async context to call MCP server tool
74
  async with MCP_CLIENT:
75
  response = await MCP_CLIENT.call_tool(TOOL_NAME, payload)
76
-
77
  if response.is_error:
78
- # Extract error message
79
- error_text = response.content[0].text if response.content and isinstance(response.content, list) else "Unknown error"
80
  raise Exception(f"MCP Tool Error: {error_text}")
81
-
82
  # Server may return Python-style string (single quotes)
83
- raw_text = response.content[0].text
 
84
  response_dict = ast.literal_eval(raw_text)
85
-
86
  # -------------------------------
87
  # Extract fields from response
88
  # -------------------------------
89
  vlm_result = response_dict.get("result", {})
90
-
91
  description_out = vlm_result.get("description", "")
92
  human_out = vlm_result.get("human", "")
93
- objects_list = vlm_result.get("objects", [])
94
  environment_out = vlm_result.get("environment", "")
95
-
96
- # Convert objects list to a comma-separated string for display
 
 
 
 
 
 
 
 
97
  objects_str = ", ".join(objects_list) if isinstance(objects_list, list) else str(objects_list)
98
-
99
- return description_out, human_out, objects_str, environment_out
100
-
 
 
 
 
 
 
 
 
 
 
 
 
101
  except Exception as e:
102
  print(f"Error calling remote MCP API: {e}")
103
  import traceback
104
  traceback.print_exc()
105
- return f"Error: {e}", "", "", ""
 
106
 
107
 
108
  # -------------------------------
 
73
  # Use async context to call MCP server tool
74
  async with MCP_CLIENT:
75
  response = await MCP_CLIENT.call_tool(TOOL_NAME, payload)
76
+
77
  if response.is_error:
78
+ # Extract error message using the correct attribute access
79
+ error_text = response.content.text if response.content else "Unknown error"
80
  raise Exception(f"MCP Tool Error: {error_text}")
81
+
82
  # Server may return Python-style string (single quotes)
83
+ # Corrected: Access the combined text content directly
84
+ raw_text = response.content.text
85
  response_dict = ast.literal_eval(raw_text)
86
+
87
  # -------------------------------
88
  # Extract fields from response
89
  # -------------------------------
90
  vlm_result = response_dict.get("result", {})
91
+
92
  description_out = vlm_result.get("description", "")
93
  human_out = vlm_result.get("human", "")
 
94
  environment_out = vlm_result.get("environment", "")
95
+
96
+ # New fields (assuming your server update added these)
97
+ indoor_outdoor_out = vlm_result.get("indoor_or_outdoor", "")
98
+ lighting_condition_out = vlm_result.get("lighting_condition", "")
99
+ animals_list = vlm_result.get("animals", []) # Assuming animals are in a list
100
+ hazards_list = vlm_result.get("hazards", []) # Assuming hazards are in a list
101
+
102
+ objects_list = vlm_result.get("objects", [])
103
+
104
+ # Convert lists to a comma-separated string for display
105
  objects_str = ", ".join(objects_list) if isinstance(objects_list, list) else str(objects_list)
106
+ animals_str = ", ".join(animals_list) if isinstance(animals_list, list) else str(animals_list)
107
+ hazards_str = ", ".join(hazards_list) if isinstance(hazards_list, list) else str(hazards_list)
108
+
109
+ # Return all 8 fields in the correct order
110
+ return (
111
+ description_out,
112
+ environment_out,
113
+ indoor_outdoor_out,
114
+ lighting_condition_out,
115
+ human_out,
116
+ animals_str,
117
+ objects_str,
118
+ hazards_str
119
+ )
120
+
121
  except Exception as e:
122
  print(f"Error calling remote MCP API: {e}")
123
  import traceback
124
  traceback.print_exc()
125
+ # Ensure error returns 8 values as well to maintain consistency
126
+ return f"Error: {e}", "", "", "", "", "", "", ""
127
 
128
 
129
  # -------------------------------