Spaces:
Running
Running
Update app.py
Browse files73 unmodified lines747576777879808182839 unmodified lines9394959697989910010110210310446 unmodified lines15115215315415515615715815916016116216316416516616716816917017117217317417517617717873 unmodified lines# -------------------------------# MCP TOOL# -------------------------------@mcp.tool()def robot_watch(payload: Dict[str, Any]):if isinstance(payload, str):try:payload = json.loads(payload)9 unmodified linesif not image_b64:return {"error": "image_b64 missing"}# Upload image_, hf_url, _, size_bytes = upload_image(image_b64, hf_token)if not hf_url:return {"error": "Image upload failed"}# VLM callsystem_prompt = """Respond in STRICT JSON ONLY.{46 unmodified lines# -------------------------------# GRADIO WRAPPER# -------------------------------def process_json(payload):"""Gradio wrapper: directly calls the MCP tool inside the same process."""return robot_watch(payload)app = gr.Interface(fn=process_json,inputs=gr.JSON(label="Input JSON (hf_token, image_b64, robot_id)"),outputs=gr.JSON(label="Result JSON"),title="Robot MCP Server",description="This is only a JSON wrapper. The real logic lives in the MCP tool.",api_name="predict")# -------------------------------# ENTRY# -------------------------------if __name__ == "__main__":# Launch MCP server + Gradio togetherapp.launch(mcp_server=True)73 unmodified lines7475767778798081829 unmodified lines929394959697989910010110210346 unmodified lines15015115215315415515615715815916016116216316416516616716816917017117217317417517617717873 unmodified lines# -------------------------------# TRUE CORE FUNCTION# -------------------------------def robot_watch_core(payload: Dict[str, Any]):if isinstance(payload, str):try:payload = json.loads(payload)9 unmodified linesif not image_b64:return {"error": "image_b64 missing"}# Upload_, hf_url, _, size_bytes = upload_image(image_b64, hf_token)if not hf_url:return {"error": "Image upload failed"}# VLMsystem_prompt = """Respond in STRICT JSON ONLY.{46 unmodified lines# -------------------------------# REGISTER MCP TOOL (wrapper)# -------------------------------@mcp.tool()def robot_watch(payload: Dict[str, Any]):return robot_watch_core(payload)# -------------------------------# Gradio wrapper# -------------------------------def process_json(payload):return robot_watch_core(payload)app = gr.Interface(fn=process_json,inputs=gr.JSON(label="Input JSON"),outputs=gr.JSON(label="Result JSON"),title="Robot MCP Server",description="JSON endpoint for robot vision pipeline.",api_name="predict")if __name__ == "__main__":app.launch(mcp_server=True)
app.py+16-16