network01 commited on
Commit
f1c6a8d
·
verified ·
1 Parent(s): d22607c

Patch Gradio schema parsing on startup

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -2,11 +2,33 @@ import gradio as gr
2
  from PIL import Image, ImageDraw
3
  import tempfile
4
  import json
5
- import os
6
- import requests
7
-
8
- # Roboflow API configuration
9
- ROBOFLOW_API_KEY = os.getenv("ROBOFLOW_API_KEY")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ROOM_MODEL = "room-segmentation-frntt/1"
11
  DOOR_WINDOW_MODEL = "door-detection-model/2"
12
 
 
2
  from PIL import Image, ImageDraw
3
  import tempfile
4
  import json
5
+ import os
6
+ import requests
7
+ from gradio_client import utils as gradio_client_utils
8
+
9
+
10
+ _original_json_schema_to_python_type = gradio_client_utils._json_schema_to_python_type
11
+
12
+
13
+ def _safe_json_schema_to_python_type(schema, defs=None):
14
+ """Compatibility patch for Gradio 4.44 / gradio_client 1.3 schema parsing.
15
+
16
+ Some component schemas contain additionalProperties as a boolean. Older
17
+ gradio_client assumes that value is always a dict and crashes while building
18
+ API info during Space startup.
19
+ """
20
+ if isinstance(schema, bool):
21
+ return "Any"
22
+ if isinstance(schema, dict) and isinstance(schema.get("additionalProperties"), bool):
23
+ schema = dict(schema)
24
+ schema["additionalProperties"] = {}
25
+ return _original_json_schema_to_python_type(schema, defs)
26
+
27
+
28
+ gradio_client_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
29
+
30
+ # Roboflow API configuration
31
+ ROBOFLOW_API_KEY = os.getenv("ROBOFLOW_API_KEY")
32
  ROOM_MODEL = "room-segmentation-frntt/1"
33
  DOOR_WINDOW_MODEL = "door-detection-model/2"
34