Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,29 +6,25 @@ import json
|
|
| 6 |
|
| 7 |
def process(json_input):
|
| 8 |
try:
|
| 9 |
-
data = json.loads
|
| 10 |
|
| 11 |
-
# Decode Base64
|
| 12 |
img_bytes = base64.b64decode(data["image_b64"])
|
| 13 |
img = Image.open(io.BytesIO(img_bytes))
|
| 14 |
|
| 15 |
-
# You can do CV/LLM here later
|
| 16 |
response = {
|
| 17 |
"received": True,
|
| 18 |
"robot_id": data.get("robot_id", "unknown"),
|
| 19 |
"image_size": img.size
|
| 20 |
}
|
| 21 |
-
|
| 22 |
-
return json.dumps(response)
|
| 23 |
|
| 24 |
except Exception as e:
|
| 25 |
-
return
|
| 26 |
|
| 27 |
-
# Gradio interface
|
| 28 |
demo = gr.Interface(
|
| 29 |
fn=process,
|
| 30 |
-
inputs=gr.
|
| 31 |
-
outputs=gr.
|
| 32 |
)
|
| 33 |
|
| 34 |
demo.launch()
|
|
|
|
| 6 |
|
| 7 |
def process(json_input):
|
| 8 |
try:
|
| 9 |
+
data = json_input # no need to json.loads
|
| 10 |
|
|
|
|
| 11 |
img_bytes = base64.b64decode(data["image_b64"])
|
| 12 |
img = Image.open(io.BytesIO(img_bytes))
|
| 13 |
|
|
|
|
| 14 |
response = {
|
| 15 |
"received": True,
|
| 16 |
"robot_id": data.get("robot_id", "unknown"),
|
| 17 |
"image_size": img.size
|
| 18 |
}
|
| 19 |
+
return response
|
|
|
|
| 20 |
|
| 21 |
except Exception as e:
|
| 22 |
+
return {"error": str(e)}
|
| 23 |
|
|
|
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=process,
|
| 26 |
+
inputs=gr.JSON(label="Input JSON from Jetson"),
|
| 27 |
+
outputs=gr.JSON(label="Reply to Jetson"),
|
| 28 |
)
|
| 29 |
|
| 30 |
demo.launch()
|