OppaAI commited on
Commit
b98a5e1
·
verified ·
1 Parent(s): 70b499c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -15,8 +15,6 @@ ROBOT_ID = "Robot_MCP_Client"
15
  HF_TOKEN = os.environ.get("HF_TOKEN")
16
  if not HF_TOKEN:
17
  print("Warning: HF_TOKEN not found. API calls may fail.")
18
- # Set a placeholder string to avoid the 'None is not of type string' error
19
- # The API call will fail later due to auth, but validation will pass.
20
  HF_TOKEN = "missing_token_placeholder"
21
 
22
  # The MCP URL of your remote server
@@ -35,16 +33,13 @@ async def process_webcam_stream_async(image):
35
  if image is None:
36
  return "", "", "", ""
37
 
38
- # Check if a valid token is available before proceeding
39
  if HF_TOKEN == "missing_token_placeholder":
40
  return "Error: HF_TOKEN not set locally.", "", "", ""
41
 
42
- # Convert Image to base64
43
  buffered = io.BytesIO()
44
  image.save(buffered, format="JPEG")
45
  b64_img = base64.b64encode(buffered.getvalue()).decode("utf-8")
46
 
47
- # Prepare payload
48
  payload = {
49
  "hf_token_input": HF_TOKEN,
50
  "robot_id_input": ROBOT_ID,
@@ -56,11 +51,14 @@ async def process_webcam_stream_async(image):
56
  response = await MCP_CLIENT.call_tool(TOOL_NAME, payload)
57
 
58
  if response.is_error:
59
- error_text = response.content.text if response.content else "Unknown error"
 
60
  raise Exception(f"MCP Tool Error: {error_text}")
61
 
62
  import json
63
- response_dict = json.loads(response.content.text)
 
 
64
 
65
  vlm_result = response_dict.get("result", {})
66
 
 
15
  HF_TOKEN = os.environ.get("HF_TOKEN")
16
  if not HF_TOKEN:
17
  print("Warning: HF_TOKEN not found. API calls may fail.")
 
 
18
  HF_TOKEN = "missing_token_placeholder"
19
 
20
  # The MCP URL of your remote server
 
33
  if image is None:
34
  return "", "", "", ""
35
 
 
36
  if HF_TOKEN == "missing_token_placeholder":
37
  return "Error: HF_TOKEN not set locally.", "", "", ""
38
 
 
39
  buffered = io.BytesIO()
40
  image.save(buffered, format="JPEG")
41
  b64_img = base64.b64encode(buffered.getvalue()).decode("utf-8")
42
 
 
43
  payload = {
44
  "hf_token_input": HF_TOKEN,
45
  "robot_id_input": ROBOT_ID,
 
51
  response = await MCP_CLIENT.call_tool(TOOL_NAME, payload)
52
 
53
  if response.is_error:
54
+ # Access the first item in the content list for the error text
55
+ error_text = response.content[0].text if response.content and isinstance(response.content, list) else "Unknown error"
56
  raise Exception(f"MCP Tool Error: {error_text}")
57
 
58
  import json
59
+ # Access the first item in the content list for the raw JSON string
60
+ raw_text = response.content[0].text
61
+ response_dict = json.loads(raw_text)
62
 
63
  vlm_result = response_dict.get("result", {})
64