Raghu commited on
Commit
97d71ca
·
1 Parent(s): 05779db

Fully bypass Gradio API schema parse (bool-safe + api_info noop)

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -8,6 +8,7 @@ import torch
8
  import torch.nn as nn
9
  import numpy as np
10
  import gradio as gr
 
11
  import easyocr
12
  import json
13
  import re
@@ -20,17 +21,33 @@ import warnings
20
  warnings.filterwarnings('ignore')
21
 
22
  # ---------------------------------------------------------------------------
23
- # Work around Gradio json_schema traversal crash: guard bool schema entries
 
 
24
  # ---------------------------------------------------------------------------
25
  import gradio_client.utils as grc_utils
26
  _orig_get_type = grc_utils.get_type
 
27
 
28
  def _safe_get_type(schema):
29
  if isinstance(schema, bool):
30
  return "any"
31
  return _orig_get_type(schema)
32
 
 
 
 
 
 
 
 
 
33
  grc_utils.get_type = _safe_get_type
 
 
 
 
 
34
 
35
  # ============================================================================
36
  # Configuration
 
8
  import torch.nn as nn
9
  import numpy as np
10
  import gradio as gr
11
+ import gradio.routes as gr_routes
12
  import easyocr
13
  import json
14
  import re
 
21
  warnings.filterwarnings('ignore')
22
 
23
  # ---------------------------------------------------------------------------
24
+ # Work around Gradio json_schema traversal crash:
25
+ # - guard bool schema entries
26
+ # - short-circuit API info generation
27
  # ---------------------------------------------------------------------------
28
  import gradio_client.utils as grc_utils
29
  _orig_get_type = grc_utils.get_type
30
+ _orig_json_schema_to_python_type = grc_utils.json_schema_to_python_type
31
 
32
  def _safe_get_type(schema):
33
  if isinstance(schema, bool):
34
  return "any"
35
  return _orig_get_type(schema)
36
 
37
+ def _safe_json_schema_to_python_type(schema, defs=None):
38
+ if isinstance(schema, bool):
39
+ return "any"
40
+ try:
41
+ return _orig_json_schema_to_python_type(schema, defs)
42
+ except Exception:
43
+ return "any"
44
+
45
  grc_utils.get_type = _safe_get_type
46
+ grc_utils.json_schema_to_python_type = _safe_json_schema_to_python_type
47
+
48
+ # Avoid API schema generation entirely to prevent upstream traversal
49
+ gr_routes.api_info = lambda serialize=True: {}
50
+ gr.Blocks.get_api_info = lambda self: {}
51
 
52
  # ============================================================================
53
  # Configuration