Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,39 +4,22 @@ from PIL import Image
|
|
| 4 |
import io
|
| 5 |
import json
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
""
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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 |
-
|
| 41 |
-
if __name__ == "__main__":
|
| 42 |
-
demo.launch(mcp_server=True)
|
|
|
|
| 4 |
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()
|
|
|
|
|
|