Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import base64 | |
| from PIL import Image | |
| import io | |
| import json | |
| # Add a docstring for your function; this is used to generate the MCP tool description | |
| def process(json_input: dict) -> dict: | |
| """ | |
| Processes incoming JSON data containing a base64 encoded image and robot ID. | |
| Args: | |
| json_input (dict): A dictionary with keys "image_b64" and "robot_id". | |
| Returns: | |
| dict: A response dictionary indicating success, robot ID, and image size, or an error. | |
| """ | |
| try: | |
| data = json_input # Already a dict from Gradio API | |
| img_bytes = base64.b64decode(data["image_b64"]) | |
| img = Image.open(io.BytesIO(img_bytes)) | |
| response = { | |
| "received": True, | |
| "robot_id": data.get("robot_id", "unknown"), | |
| "image_size": img.size | |
| } | |
| return response | |
| except Exception as e: | |
| return {"error": str(e)} | |
| demo = gr.Interface( | |
| fn=process, | |
| inputs=gr.JSON(label="Input JSON from Jetson"), | |
| outputs=gr.JSON(label="Reply to Jetson"), | |
| ) | |
| # Launch with mcp_server enabled | |
| if __name__ == "__main__": | |
| demo.launch(mcp_server=True) | |