JoaquinVanschoren commited on
Commit
b5d447a
·
1 Parent(s): 9cc906d

gradio fix

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -7,17 +7,17 @@ import time
7
  import traceback
8
  from validation import validate_json, validate_croissant, validate_records, validate_rai, generate_validation_report
9
 
10
- # Patch gradio_client.utils.get_type to handle boolean JSON schemas.
11
- # gradio_client 1.7.2 crashes with "argument of type 'bool' is not iterable"
12
- # when a component's JSON schema has `additionalProperties: true/false`.
13
- # show_api=False in launch() doesn't remove the /info route in Gradio 5.20,
14
- # so this patch is needed to prevent the crash on every request.
15
- _orig_get_type = _gc_utils.get_type
16
- def _safe_get_type(schema):
17
  if not isinstance(schema, dict):
18
  return "any"
19
- return _orig_get_type(schema)
20
- _gc_utils.get_type = _safe_get_type
21
 
22
  def process_file(file):
23
  results = []
 
7
  import traceback
8
  from validation import validate_json, validate_croissant, validate_records, validate_rai, generate_validation_report
9
 
10
+ # Patch gradio_client.utils to handle boolean JSON schemas.
11
+ # gradio_client 1.7.2 crashes when a component schema has `additionalProperties: true/false`.
12
+ # The inner recursive function _json_schema_to_python_type receives True/False and either
13
+ # raises TypeError ("argument of type 'bool' is not iterable") or APIInfoParseError.
14
+ # Patching the inner function is the correct fix since it's called recursively.
15
+ _orig_json_schema_to_python_type = _gc_utils._json_schema_to_python_type
16
+ def _safe_json_schema_to_python_type(schema, defs=None):
17
  if not isinstance(schema, dict):
18
  return "any"
19
+ return _orig_json_schema_to_python_type(schema, defs)
20
+ _gc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
21
 
22
  def process_file(file):
23
  results = []