Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,11 @@ from PIL import Image
|
|
| 4 |
import io
|
| 5 |
import json
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
try:
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
img_bytes = base64.b64decode(data["image_b64"])
|
| 12 |
img = Image.open(io.BytesIO(img_bytes))
|
|
@@ -19,11 +21,13 @@ def process(json_input):
|
|
| 19 |
return response
|
| 20 |
|
| 21 |
except Exception as e:
|
|
|
|
| 22 |
return {"error": str(e)}
|
| 23 |
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=process,
|
| 26 |
-
|
|
|
|
| 27 |
outputs=gr.JSON(label="Reply to Jetson"),
|
| 28 |
)
|
| 29 |
|
|
|
|
| 4 |
import io
|
| 5 |
import json
|
| 6 |
|
| 7 |
+
# The input will now be a raw text string representing the JSON data
|
| 8 |
+
def process(json_text_input):
|
| 9 |
try:
|
| 10 |
+
# Manually parse the incoming text string into a Python dictionary
|
| 11 |
+
data = json.loads(json_text_input)
|
| 12 |
|
| 13 |
img_bytes = base64.b64decode(data["image_b64"])
|
| 14 |
img = Image.open(io.BytesIO(img_bytes))
|
|
|
|
| 21 |
return response
|
| 22 |
|
| 23 |
except Exception as e:
|
| 24 |
+
# Return error as a JSON dictionary which Gradio handles
|
| 25 |
return {"error": str(e)}
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=process,
|
| 29 |
+
# Change input type to Textbox
|
| 30 |
+
inputs=gr.Textbox(label="Input JSON as Plain Text"),
|
| 31 |
outputs=gr.JSON(label="Reply to Jetson"),
|
| 32 |
)
|
| 33 |
|