codealchemist01 commited on
Commit
450676e
·
verified ·
1 Parent(s): 9e438ea

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +31 -11
app.py CHANGED
@@ -1,25 +1,45 @@
1
- # PATCH GRADIO BEFORE ANYTHING ELSE LOADS
2
  import sys
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import gradio.routes as routes_module
4
- import gradio.blocks as blocks_module
5
 
6
- # Patch api_info to return empty dict immediately
7
- original_api_info = getattr(routes_module, 'api_info', None)
8
  def patched_api_info(*args, **kwargs):
9
  return {"api": {}}
10
  routes_module.api_info = patched_api_info
11
 
12
- # Also patch get_api_info in Blocks
13
- original_get_api_info = getattr(blocks_module.Blocks, 'get_api_info', None)
14
- def patched_get_api_info(self):
15
- return {}
16
- if original_get_api_info:
17
- blocks_module.Blocks.get_api_info = patched_get_api_info
18
 
19
  import os
20
  import shutil
21
  from huggingface_hub import hf_hub_download
22
- import gradio as gr
23
  import torch
24
  import torch.nn.functional as F
25
  import numpy as np
 
1
+ # COMPREHENSIVE PATCH - Fix the actual bug
2
  import sys
3
+
4
+ # Patch client_utils BEFORE gradio imports
5
+ def patch_gradio_client():
6
+ # Import client_utils early
7
+ from gradio_client import utils as client_utils
8
+
9
+ # Fix the get_type function that causes TypeError
10
+ original_get_type = client_utils.get_type
11
+ def fixed_get_type(schema):
12
+ if not isinstance(schema, dict):
13
+ return "Any"
14
+ return original_get_type(schema)
15
+ client_utils.get_type = fixed_get_type
16
+
17
+ # Also fix _json_schema_to_python_type
18
+ original_json_schema = client_utils._json_schema_to_python_type
19
+ def fixed_json_schema(schema, defs=None):
20
+ if not isinstance(schema, dict):
21
+ return "Any"
22
+ return original_json_schema(schema, defs)
23
+ client_utils._json_schema_to_python_type = fixed_json_schema
24
+
25
+ # Import gradio to trigger client_utils load
26
+ import gradio as gr
27
  import gradio.routes as routes_module
 
28
 
29
+ # Patch api_info
 
30
  def patched_api_info(*args, **kwargs):
31
  return {"api": {}}
32
  routes_module.api_info = patched_api_info
33
 
34
+ # Now patch client_utils
35
+ try:
36
+ patch_gradio_client()
37
+ except Exception as e:
38
+ print(f"Warning: Could not patch client_utils: {e}")
 
39
 
40
  import os
41
  import shutil
42
  from huggingface_hub import hf_hub_download
 
43
  import torch
44
  import torch.nn.functional as F
45
  import numpy as np