OppaAI commited on
Commit
07ea75f
·
verified ·
1 Parent(s): d1e9476

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -74,10 +74,9 @@ def safe_parse_json_from_text(text: str):
74
 
75
 
76
  # -------------------------------
77
- # MCP TOOL
78
  # -------------------------------
79
- @mcp.tool()
80
- def robot_watch(payload: Dict[str, Any]):
81
  if isinstance(payload, str):
82
  try:
83
  payload = json.loads(payload)
@@ -93,12 +92,12 @@ def robot_watch(payload: Dict[str, Any]):
93
  if not image_b64:
94
  return {"error": "image_b64 missing"}
95
 
96
- # Upload image
97
  _, hf_url, _, size_bytes = upload_image(image_b64, hf_token)
98
  if not hf_url:
99
  return {"error": "Image upload failed"}
100
 
101
- # VLM call
102
  system_prompt = """
103
  Respond in STRICT JSON ONLY.
104
  {
@@ -151,28 +150,29 @@ Respond in STRICT JSON ONLY.
151
 
152
 
153
  # -------------------------------
154
- # GRADIO WRAPPER
 
 
 
 
 
 
 
 
155
  # -------------------------------
156
  def process_json(payload):
157
- """
158
- Gradio wrapper: directly calls the MCP tool inside the same process.
159
- """
160
- return robot_watch(payload)
161
 
162
 
163
  app = gr.Interface(
164
  fn=process_json,
165
- inputs=gr.JSON(label="Input JSON (hf_token, image_b64, robot_id)"),
166
  outputs=gr.JSON(label="Result JSON"),
167
  title="Robot MCP Server",
168
- description="This is only a JSON wrapper. The real logic lives in the MCP tool.",
169
  api_name="predict"
170
  )
171
 
172
 
173
- # -------------------------------
174
- # ENTRY
175
- # -------------------------------
176
  if __name__ == "__main__":
177
- # Launch MCP server + Gradio together
178
  app.launch(mcp_server=True)
 
74
 
75
 
76
  # -------------------------------
77
+ # TRUE CORE FUNCTION
78
  # -------------------------------
79
+ def robot_watch_core(payload: Dict[str, Any]):
 
80
  if isinstance(payload, str):
81
  try:
82
  payload = json.loads(payload)
 
92
  if not image_b64:
93
  return {"error": "image_b64 missing"}
94
 
95
+ # Upload
96
  _, hf_url, _, size_bytes = upload_image(image_b64, hf_token)
97
  if not hf_url:
98
  return {"error": "Image upload failed"}
99
 
100
+ # VLM
101
  system_prompt = """
102
  Respond in STRICT JSON ONLY.
103
  {
 
150
 
151
 
152
  # -------------------------------
153
+ # REGISTER MCP TOOL (wrapper)
154
+ # -------------------------------
155
+ @mcp.tool()
156
+ def robot_watch(payload: Dict[str, Any]):
157
+ return robot_watch_core(payload)
158
+
159
+
160
+ # -------------------------------
161
+ # Gradio wrapper
162
  # -------------------------------
163
  def process_json(payload):
164
+ return robot_watch_core(payload)
 
 
 
165
 
166
 
167
  app = gr.Interface(
168
  fn=process_json,
169
+ inputs=gr.JSON(label="Input JSON"),
170
  outputs=gr.JSON(label="Result JSON"),
171
  title="Robot MCP Server",
172
+ description="JSON endpoint for robot vision pipeline.",
173
  api_name="predict"
174
  )
175
 
176
 
 
 
 
177
  if __name__ == "__main__":
 
178
  app.launch(mcp_server=True)