Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,52 @@
|
|
| 1 |
import sys
|
|
|
|
| 2 |
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
try:
|
| 5 |
import gradio_client.utils as client_utils
|
| 6 |
-
orig_get_type = client_utils
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
return
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
print("
|
| 17 |
-
|
| 18 |
-
print(f"Failed to apply serialization patch: {patch_err}")
|
| 19 |
-
# -----------------------------------------------------------------
|
| 20 |
|
| 21 |
import os
|
| 22 |
import cv2
|
|
|
|
| 1 |
import sys
|
| 2 |
+
import types
|
| 3 |
|
| 4 |
+
# =================================================================
|
| 5 |
+
# CRITICAL PYTHON 3.13 / GRADIO SDK CONFLICT MONKEY-PATCHES
|
| 6 |
+
# Must execute before ANY other library import to intercept Gradio
|
| 7 |
+
# =================================================================
|
| 8 |
+
|
| 9 |
+
# 1. Force-inject HfFolder into sys.modules to satisfy older Gradio imports
|
| 10 |
+
try:
|
| 11 |
+
# Create a dynamic mock class for HfFolder matching its historical signatures
|
| 12 |
+
class MockHfFolder:
|
| 13 |
+
@classmethod
|
| 14 |
+
def get_token(cls): return None
|
| 15 |
+
@classmethod
|
| 16 |
+
def save_token(cls, token): pass
|
| 17 |
+
@classmethod
|
| 18 |
+
def delete_token(cls): pass
|
| 19 |
+
|
| 20 |
+
# If huggingface_hub isn't fully loaded yet, build a stub module layout for it
|
| 21 |
+
if 'huggingface_hub' not in sys.modules:
|
| 22 |
+
hf_hub_mock = types.ModuleType('huggingface_hub')
|
| 23 |
+
hf_hub_mock.HfFolder = MockHfFolder
|
| 24 |
+
hf_hub_mock.whoami = lambda *args, **kwargs: {"name": "anonymous", "auth": {"type": "none"}}
|
| 25 |
+
sys.modules['huggingface_hub'] = hf_hub_mock
|
| 26 |
+
else:
|
| 27 |
+
# If it is loaded, inject the missing class descriptor directly into the object surface
|
| 28 |
+
import huggingface_hub
|
| 29 |
+
if not hasattr(huggingface_hub, 'HfFolder'):
|
| 30 |
+
huggingface_hub.HfFolder = MockHfFolder
|
| 31 |
+
sys.modules['huggingface_hub'].HfFolder = MockHfFolder
|
| 32 |
+
except Exception as patch_err_1:
|
| 33 |
+
print(f"Pre-import HfFolder patch skipped or failed: {patch_err_1}")
|
| 34 |
+
|
| 35 |
+
# 2. Patch the Gradio client schema serialization parser to avoid the 'bool' type loop error
|
| 36 |
try:
|
| 37 |
import gradio_client.utils as client_utils
|
| 38 |
+
orig_get_type = getattr(client_utils, 'get_type', None)
|
| 39 |
|
| 40 |
+
if orig_get_type:
|
| 41 |
+
def safe_get_type(schema):
|
| 42 |
+
if isinstance(schema, bool):
|
| 43 |
+
return "boolean"
|
| 44 |
+
return orig_get_type(schema)
|
| 45 |
+
client_utils.get_type = safe_get_type
|
| 46 |
+
print("Successfully patched gradio_client schema serialization engine.")
|
| 47 |
+
except Exception as patch_err_2:
|
| 48 |
+
print(f"Schema serialization engine patch deferred: {patch_err_2}")
|
| 49 |
+
# =================================================================
|
|
|
|
|
|
|
| 50 |
|
| 51 |
import os
|
| 52 |
import cv2
|