Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,25 +1,45 @@
|
|
| 1 |
-
# PATCH
|
| 2 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import gradio.routes as routes_module
|
| 4 |
-
import gradio.blocks as blocks_module
|
| 5 |
|
| 6 |
-
# Patch api_info
|
| 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 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 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
|