Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,21 +5,33 @@ import io
|
|
| 5 |
import json
|
| 6 |
|
| 7 |
def process(json_input):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
img = Image.open(io.BytesIO(img_bytes))
|
| 11 |
|
| 12 |
-
|
| 13 |
-
"
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
demo = gr.Interface(
|
| 19 |
fn=process,
|
| 20 |
inputs=gr.JSON(label="Input JSON from Jetson"),
|
| 21 |
-
outputs=
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 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()
|