Mohinikathro commited on
Commit
0f5cce3
·
verified ·
1 Parent(s): 60ad7ee

changes made to app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -6,28 +6,29 @@ import os
6
  import gradio_client.utils as client_utils
7
  import sys
8
 
9
- # ================== FIX START ==================
10
- # Store original reference first
11
- _original_json_schema_handler = client_utils._json_schema_to_python_type
12
-
13
  def _patched_json_schema_to_python_type(schema, defs=None, depth=0):
14
- if depth > 100: # Safety net
 
15
  return "Any"
 
 
16
  if isinstance(schema, bool):
17
  return "Any" if schema else "None"
18
- return _original_json_schema_handler(schema, defs)
 
 
 
 
 
19
 
 
20
  client_utils._json_schema_to_python_type = _patched_json_schema_to_python_type
21
- sys.setrecursionlimit(10000) # Temporarily increase recursion depth
22
- # ================== FIX END ====================
23
 
24
- # Workaround for Gradio schema generation issue
25
- def _patched_json_schema_to_python_type(schema, defs=None):
26
- if isinstance(schema, bool):
27
- return "Any" if schema else "None"
28
- return client_utils._json_schema_to_python_type(schema, defs)
29
-
30
- client_utils._json_schema_to_python_type = _patched_json_schema_to_python_type
31
 
32
  # Set up device
33
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
6
  import gradio_client.utils as client_utils
7
  import sys
8
 
9
+ # ===============================
10
+ # Recursion Handling Fix
11
+ # ===============================
 
12
  def _patched_json_schema_to_python_type(schema, defs=None, depth=0):
13
+ # Safety check to prevent infinite recursion
14
+ if depth > 100:
15
  return "Any"
16
+
17
+ # Handle boolean cases
18
  if isinstance(schema, bool):
19
  return "Any" if schema else "None"
20
+
21
+ # Call the original function with increased depth
22
+ try:
23
+ return client_utils._json_schema_to_python_type(schema, defs)
24
+ except RecursionError:
25
+ return "Any"
26
 
27
+ # Modify the utilities to use the patched function
28
  client_utils._json_schema_to_python_type = _patched_json_schema_to_python_type
 
 
29
 
30
+ # Increase recursion limit as a backup
31
+ sys.setrecursionlimit(10000)
 
 
 
 
 
32
 
33
  # Set up device
34
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")