Matan Kriel commited on
Commit
ded317b
·
1 Parent(s): f3e939d

updated app

Browse files
Files changed (1) hide show
  1. app.py +45 -1
app.py CHANGED
@@ -95,7 +95,51 @@ def find_best_matches(user_image):
95
  except Exception as e:
96
  return [], f"Error: {str(e)}"
97
 
98
- # --- 3. Build Interface ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  with gr.Blocks(title="Famous Face Matcher") as demo:
100
  gr.Markdown("# 🎭 Who is your Celebrity Twin?")
101
  gr.Markdown(f"Searching **{len(df_db) if df_db is not None else 0} faces** using **{MODEL_NAME}**.")
 
95
  except Exception as e:
96
  return [], f"Error: {str(e)}"
97
 
98
+ # --- 3. Monkey Patch to Fix Gradio API Bug ---
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 get_type function in gradio_client.utils
103
+ try:
104
+ from gradio_client import utils as client_utils
105
+
106
+ _original_get_type = client_utils.get_type
107
+
108
+ def safe_get_type(schema):
109
+ """Safe version that checks if schema is a dict before using 'in'"""
110
+ if not isinstance(schema, dict):
111
+ # If schema is not a dict (e.g., it's a bool), return a default type
112
+ return "Any"
113
+ return _original_get_type(schema)
114
+
115
+ client_utils.get_type = safe_get_type
116
+ print("✓ Patched gradio_client.utils.get_type")
117
+ except Exception as e:
118
+ print(f"Could not patch gradio_client.utils.get_type: {e}")
119
+
120
+ # Patch 2: Fix the get_api_info method in gradio.blocks
121
+ try:
122
+ from gradio import blocks
123
+
124
+ _original_get_api_info = blocks.Blocks.get_api_info
125
+
126
+ def safe_get_api_info(self):
127
+ """Safe version that catches schema introspection errors"""
128
+ try:
129
+ return _original_get_api_info(self)
130
+ except TypeError as e:
131
+ if "argument of type 'bool' is not iterable" in str(e) or "'bool' is not iterable" in str(e):
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 TypeError
136
+
137
+ blocks.Blocks.get_api_info = safe_get_api_info
138
+ print("✓ Patched gradio.blocks.Blocks.get_api_info")
139
+ except Exception as e:
140
+ print(f"Could not patch gradio.blocks.get_api_info: {e}")
141
+
142
+ # --- 4. Build Interface ---
143
  with gr.Blocks(title="Famous Face Matcher") as demo:
144
  gr.Markdown("# 🎭 Who is your Celebrity Twin?")
145
  gr.Markdown(f"Searching **{len(df_db) if df_db is not None else 0} faces** using **{MODEL_NAME}**.")