Spaces:
Sleeping
Sleeping
Matan Kriel commited on
Commit ·
1458622
1
Parent(s): ded317b
updated app
Browse files
app.py
CHANGED
|
@@ -99,7 +99,33 @@ def find_best_matches(user_image):
|
|
| 99 |
# The error occurs in gradio_client/utils.py line 882: if "const" in schema:
|
| 100 |
# but schema is a boolean instead of a dict. We'll patch multiple places.
|
| 101 |
|
| 102 |
-
# Patch 1: Fix the
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
try:
|
| 104 |
from gradio_client import utils as client_utils
|
| 105 |
|
|
@@ -117,9 +143,10 @@ try:
|
|
| 117 |
except Exception as e:
|
| 118 |
print(f"Could not patch gradio_client.utils.get_type: {e}")
|
| 119 |
|
| 120 |
-
# Patch
|
| 121 |
try:
|
| 122 |
from gradio import blocks
|
|
|
|
| 123 |
|
| 124 |
_original_get_api_info = blocks.Blocks.get_api_info
|
| 125 |
|
|
@@ -127,12 +154,16 @@ try:
|
|
| 127 |
"""Safe version that catches schema introspection errors"""
|
| 128 |
try:
|
| 129 |
return _original_get_api_info(self)
|
| 130 |
-
except TypeError as e:
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
# Known Gradio bug - return empty API info
|
| 133 |
-
print("Warning: Caught Gradio API schema bug, returning empty API info")
|
| 134 |
return {}
|
| 135 |
-
raise # Re-raise if it's a different
|
| 136 |
|
| 137 |
blocks.Blocks.get_api_info = safe_get_api_info
|
| 138 |
print("✓ Patched gradio.blocks.Blocks.get_api_info")
|
|
|
|
| 99 |
# The error occurs in gradio_client/utils.py line 882: if "const" in schema:
|
| 100 |
# but schema is a boolean instead of a dict. We'll patch multiple places.
|
| 101 |
|
| 102 |
+
# Patch 1: Fix the _json_schema_to_python_type function to handle boolean schemas
|
| 103 |
+
try:
|
| 104 |
+
from gradio_client import utils as client_utils
|
| 105 |
+
|
| 106 |
+
_original_json_schema_to_python_type = client_utils._json_schema_to_python_type
|
| 107 |
+
|
| 108 |
+
def safe_json_schema_to_python_type(schema, defs=None):
|
| 109 |
+
"""Safe version that handles boolean schemas"""
|
| 110 |
+
if isinstance(schema, bool):
|
| 111 |
+
# Boolean schemas are not valid JSON schemas, return "Any"
|
| 112 |
+
return "Any"
|
| 113 |
+
if not isinstance(schema, dict):
|
| 114 |
+
# If schema is not a dict or bool, return "Any"
|
| 115 |
+
return "Any"
|
| 116 |
+
try:
|
| 117 |
+
return _original_json_schema_to_python_type(schema, defs)
|
| 118 |
+
except Exception as e:
|
| 119 |
+
# Catch any parsing errors and return "Any"
|
| 120 |
+
print(f"Warning: Schema parsing failed: {e}, returning 'Any'")
|
| 121 |
+
return "Any"
|
| 122 |
+
|
| 123 |
+
client_utils._json_schema_to_python_type = safe_json_schema_to_python_type
|
| 124 |
+
print("✓ Patched gradio_client.utils._json_schema_to_python_type")
|
| 125 |
+
except Exception as e:
|
| 126 |
+
print(f"Could not patch _json_schema_to_python_type: {e}")
|
| 127 |
+
|
| 128 |
+
# Patch 2: Fix the get_type function in gradio_client.utils
|
| 129 |
try:
|
| 130 |
from gradio_client import utils as client_utils
|
| 131 |
|
|
|
|
| 143 |
except Exception as e:
|
| 144 |
print(f"Could not patch gradio_client.utils.get_type: {e}")
|
| 145 |
|
| 146 |
+
# Patch 3: Fix the get_api_info method in gradio.blocks
|
| 147 |
try:
|
| 148 |
from gradio import blocks
|
| 149 |
+
from gradio_client.utils import APIInfoParseError
|
| 150 |
|
| 151 |
_original_get_api_info = blocks.Blocks.get_api_info
|
| 152 |
|
|
|
|
| 154 |
"""Safe version that catches schema introspection errors"""
|
| 155 |
try:
|
| 156 |
return _original_get_api_info(self)
|
| 157 |
+
except (TypeError, APIInfoParseError) as e:
|
| 158 |
+
error_str = str(e)
|
| 159 |
+
if ("argument of type 'bool' is not iterable" in error_str or
|
| 160 |
+
"'bool' is not iterable" in error_str or
|
| 161 |
+
"Cannot parse schema True" in error_str or
|
| 162 |
+
"Cannot parse schema False" in error_str):
|
| 163 |
# Known Gradio bug - return empty API info
|
| 164 |
+
print(f"Warning: Caught Gradio API schema bug ({type(e).__name__}), returning empty API info")
|
| 165 |
return {}
|
| 166 |
+
raise # Re-raise if it's a different error
|
| 167 |
|
| 168 |
blocks.Blocks.get_api_info = safe_get_api_info
|
| 169 |
print("✓ Patched gradio.blocks.Blocks.get_api_info")
|