OppaAI commited on
Commit
cf34c2f
·
verified ·
1 Parent(s): 95881bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -4,9 +4,11 @@ from PIL import Image
4
  import io
5
  import json
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))
@@ -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
- inputs=gr.JSON(label="Input JSON from Jetson"),
 
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