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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -5,21 +5,33 @@ 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()
 
5
  import json
6
 
7
  def process(json_input):
8
+ try:
9
+ data = json_input
 
10
 
11
+ # Decode base64 → PIL Image
12
+ img_bytes = base64.b64decode(data["image_b64"])
13
+ img = Image.open(io.BytesIO(img_bytes))
14
+
15
+ # Response JSON
16
+ response = {
17
+ "received": True,
18
+ "robot_id": data.get("robot_id", "unknown"),
19
+ "image_size": img.size
20
+ }
21
+
22
+ return response, img # <-- return JSON + image
23
+
24
+ except Exception as e:
25
+ return {"error": str(e)}, None
26
 
27
  demo = gr.Interface(
28
  fn=process,
29
  inputs=gr.JSON(label="Input JSON from Jetson"),
30
+ outputs=[
31
+ gr.JSON(label="Reply Message"),
32
+ gr.Image(type="pil", label="Received Image") # <-- display image
33
+ ],
34
+ api_name="predict"
35
  )
36
 
37
  demo.launch()