OppaAI commited on
Commit
a966c99
·
verified ·
1 Parent(s): 92066ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -28
app.py CHANGED
@@ -4,39 +4,22 @@ from PIL import Image
4
  import io
5
  import json
6
 
7
- # Add a docstring for your function; this is used to generate the MCP tool description
8
- def process(json_input: dict) -> dict:
9
- """
10
- Processes incoming JSON data containing a base64 encoded image and robot ID.
11
 
12
- Args:
13
- json_input (dict): A dictionary with keys "image_b64" and "robot_id".
14
-
15
- Returns:
16
- dict: A response dictionary indicating success, robot ID, and image size, or an error.
17
- """
18
- try:
19
- data = json_input # Already a dict from Gradio API
20
-
21
- img_bytes = base64.b64decode(data["image_b64"])
22
- img = Image.open(io.BytesIO(img_bytes))
23
-
24
- response = {
25
- "received": True,
26
- "robot_id": data.get("robot_id", "unknown"),
27
- "image_size": img.size
28
- }
29
- return response
30
-
31
- except Exception as e:
32
- return {"error": str(e)}
33
 
34
  demo = gr.Interface(
35
  fn=process,
36
  inputs=gr.JSON(label="Input JSON from Jetson"),
37
  outputs=gr.JSON(label="Reply to Jetson"),
 
38
  )
39
 
40
- # Launch with mcp_server enabled
41
- if __name__ == "__main__":
42
- demo.launch(mcp_server=True)
 
4
  import io
5
  import json
6
 
7
+ def process(json_input):
8
+ data = json_input
9
+ img_bytes = base64.b64decode(data["image_b64"])
10
+ img = Image.open(io.BytesIO(img_bytes))
11
 
12
+ return {
13
+ "received": True,
14
+ "robot_id": data.get("robot_id", "unknown"),
15
+ "image_size": img.size
16
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  demo = gr.Interface(
19
  fn=process,
20
  inputs=gr.JSON(label="Input JSON from Jetson"),
21
  outputs=gr.JSON(label="Reply to Jetson"),
22
+ api_name="predict" # very important
23
  )
24
 
25
+ demo.launch()