OppaAI commited on
Commit
eb6d527
·
verified ·
1 Parent(s): d13c8a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -6,21 +6,33 @@ import json
6
 
7
  def process(json_input):
8
  try:
9
- # json_input from gr.JSON() is STRING, so must parse
10
  data = json.loads(json_input)
11
 
 
12
  img_bytes = base64.b64decode(data["image_b64"])
13
  img = Image.open(io.BytesIO(img_bytes))
14
 
15
- return img # show image
 
 
 
 
 
 
 
 
16
 
17
  except Exception as e:
18
- return None
 
19
 
20
  demo = gr.Interface(
21
  fn=process,
22
- inputs=gr.JSON(label="Input JSON from Jetson"),
23
- outputs=gr.Image(type="pil", label="Image From Jetson"),
 
 
 
24
  api_name="predict"
25
  )
26
 
 
6
 
7
  def process(json_input):
8
  try:
 
9
  data = json.loads(json_input)
10
 
11
+ # decode base64 image
12
  img_bytes = base64.b64decode(data["image_b64"])
13
  img = Image.open(io.BytesIO(img_bytes))
14
 
15
+ # This goes to Jetson
16
+ reply = {
17
+ "received": True,
18
+ "robot_id": data.get("robot_id"),
19
+ "size": img.size
20
+ }
21
+
22
+ # return only the msg: (Jetson JSON)
23
+ return reply
24
 
25
  except Exception as e:
26
+ return None, {"error": str(e)}
27
+
28
 
29
  demo = gr.Interface(
30
  fn=process,
31
+ inputs=gr.JSON(label="Jetson JSON"),
32
+ outputs=[
33
+ gr.Image(type="pil", label="Image Preview"),
34
+ gr.JSON(label="Reply to Jetson")
35
+ ],
36
  api_name="predict"
37
  )
38