Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import os
2
  import sys
3
 
4
- # Set environment variables before importing any libraries
5
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
6
 
7
  # Import libraries
@@ -11,9 +11,9 @@ import torch
11
  from transformers import BertTokenizer, BertForSequenceClassification, pipeline
12
  from app.questions import get_question
13
 
14
- # Apply monkey patch to prevent the API generation error
15
  try:
16
- # Save original method reference
17
  original_method = gr.Blocks.get_api_info
18
 
19
  # Create a safer version of the method that catches the specific error
@@ -22,9 +22,9 @@ try:
22
  return original_method(self)
23
  except TypeError as e:
24
  print(f"API info generation error suppressed: {str(e)}", file=sys.stderr)
25
- return {} # Return empty API info instead of crashing
26
 
27
- # Apply the patch
28
  gr.Blocks.get_api_info = safe_get_api_info
29
  print("Applied API info generation patch", file=sys.stderr)
30
  except Exception as e:
@@ -189,15 +189,15 @@ try:
189
  # Original function reference
190
  original_json_schema = gradio_client.utils._json_schema_to_python_type
191
 
192
- # Create patched version
193
  def patched_json_schema(schema, defs=None):
194
  try:
195
  if isinstance(schema, bool):
196
- return "bool" # Handle boolean schema case directly
197
  return original_json_schema(schema, defs)
198
  except Exception as e:
199
  print(f"JSON schema conversion error suppressed: {str(e)}", file=sys.stderr)
200
- return "any" # Return a safe fallback type
201
 
202
  # Apply patch
203
  gradio_client.utils._json_schema_to_python_type = patched_json_schema
@@ -211,7 +211,7 @@ if __name__ == "__main__":
211
  demo.launch(show_api=False)
212
  except Exception as e:
213
  print(f"Launch failed: {str(e)}", file=sys.stderr)
214
- # Try minimal launch as fallback
215
  try:
216
  demo.launch()
217
  except Exception as e:
 
1
  import os
2
  import sys
3
 
4
+
5
  os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
6
 
7
  # Import libraries
 
11
  from transformers import BertTokenizer, BertForSequenceClassification, pipeline
12
  from app.questions import get_question
13
 
14
+ # patch(niranjan)
15
  try:
16
+ # original method
17
  original_method = gr.Blocks.get_api_info
18
 
19
  # Create a safer version of the method that catches the specific error
 
22
  return original_method(self)
23
  except TypeError as e:
24
  print(f"API info generation error suppressed: {str(e)}", file=sys.stderr)
25
+ return {} # Return empty api
26
 
27
+
28
  gr.Blocks.get_api_info = safe_get_api_info
29
  print("Applied API info generation patch", file=sys.stderr)
30
  except Exception as e:
 
189
  # Original function reference
190
  original_json_schema = gradio_client.utils._json_schema_to_python_type
191
 
192
+ # patched version
193
  def patched_json_schema(schema, defs=None):
194
  try:
195
  if isinstance(schema, bool):
196
+ return "bool"
197
  return original_json_schema(schema, defs)
198
  except Exception as e:
199
  print(f"JSON schema conversion error suppressed: {str(e)}", file=sys.stderr)
200
+ return "any"
201
 
202
  # Apply patch
203
  gradio_client.utils._json_schema_to_python_type = patched_json_schema
 
211
  demo.launch(show_api=False)
212
  except Exception as e:
213
  print(f"Launch failed: {str(e)}", file=sys.stderr)
214
+
215
  try:
216
  demo.launch()
217
  except Exception as e: