OppaAI commited on
Commit
d82a7f0
·
verified ·
1 Parent(s): 7081f59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -12
app.py CHANGED
@@ -1,18 +1,42 @@
1
  import gradio as gr
 
 
 
 
2
 
3
- # The function now accepts a simple string (plain text)
4
- def process_text(input_text):
5
- response = {
6
- "received": True,
7
- "message": f"Received: {input_text}",
8
- "status": "Success"
9
- }
10
- return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  demo = gr.Interface(
13
- fn=process_text,
14
- inputs=gr.Textbox(label="Input Text"), # Changed input type
15
- outputs=gr.JSON(label="Reply"),
16
  )
17
 
18
- demo.launch()
 
 
 
1
  import gradio as gr
2
+ import base64
3
+ 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)