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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -14
app.py CHANGED
@@ -8,29 +8,19 @@ 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
 
 
8
  try:
9
  data = json_input
10
 
11
+ # Base64 → PIL Image
12
  img_bytes = base64.b64decode(data["image_b64"])
13
  img = Image.open(io.BytesIO(img_bytes))
14
 
15
+ return img # <-- 直接顯示圖片
 
 
 
 
 
 
 
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