Nekochu commited on
Commit
0b7b5c9
·
1 Parent(s): e779ae1

Also patch recursive _json_schema_to_python_type for bool schemas

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -3,9 +3,8 @@ import gc
3
  import subprocess
4
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
5
 
6
- # Workaround for gradio_client get_type crash on bool additionalProperties.
7
- # Must run BEFORE `import gradio as gr` so the patched function is what gradio's
8
- # Blocks.get_api_info ultimately calls.
9
  import gradio_client.utils as _gcu
10
  _orig_get_type = _gcu.get_type
11
  def _safe_get_type(schema):
@@ -14,6 +13,13 @@ def _safe_get_type(schema):
14
  return _orig_get_type(schema)
15
  _gcu.get_type = _safe_get_type
16
 
 
 
 
 
 
 
 
17
  import spaces
18
  import gradio as gr
19
  import torch
 
3
  import subprocess
4
  subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"}, shell=True)
5
 
6
+ # Workaround for gradio_client crashes on bool schemas (e.g. additionalProperties: True/False).
7
+ # Must run BEFORE `import gradio as gr` so the patched functions are used.
 
8
  import gradio_client.utils as _gcu
9
  _orig_get_type = _gcu.get_type
10
  def _safe_get_type(schema):
 
13
  return _orig_get_type(schema)
14
  _gcu.get_type = _safe_get_type
15
 
16
+ _orig_json_schema = _gcu._json_schema_to_python_type
17
+ def _safe_json_schema(schema, defs=None):
18
+ if isinstance(schema, bool):
19
+ return "any"
20
+ return _orig_json_schema(schema, defs)
21
+ _gcu._json_schema_to_python_type = _safe_json_schema
22
+
23
  import spaces
24
  import gradio as gr
25
  import torch