Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,10 +74,9 @@ def safe_parse_json_from_text(text: str):
|
|
| 74 |
|
| 75 |
|
| 76 |
# -------------------------------
|
| 77 |
-
#
|
| 78 |
# -------------------------------
|
| 79 |
-
|
| 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
|
| 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
|
| 102 |
system_prompt = """
|
| 103 |
Respond in STRICT JSON ONLY.
|
| 104 |
{
|
|
@@ -151,28 +150,29 @@ Respond in STRICT JSON ONLY.
|
|
| 151 |
|
| 152 |
|
| 153 |
# -------------------------------
|
| 154 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 166 |
outputs=gr.JSON(label="Result JSON"),
|
| 167 |
title="Robot MCP Server",
|
| 168 |
-
description="
|
| 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)
|