Update app.py
Browse files
app.py
CHANGED
|
@@ -15,9 +15,44 @@ from datetime import datetime
|
|
| 15 |
from typing import List, Dict, Tuple, Optional
|
| 16 |
|
| 17 |
import faiss
|
| 18 |
-
import gradio as gr
|
| 19 |
import numpy as np
|
| 20 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
from PIL import Image
|
| 22 |
from transformers import CLIPModel, CLIPProcessor
|
| 23 |
from ultralytics import YOLO
|
|
|
|
| 15 |
from typing import List, Dict, Tuple, Optional
|
| 16 |
|
| 17 |
import faiss
|
|
|
|
| 18 |
import numpy as np
|
| 19 |
import torch
|
| 20 |
+
|
| 21 |
+
# ββ Monkey-patch gradio_client 4.44.x schema-introspection bug ββββββββββββββββ
|
| 22 |
+
# gradio_client/utils.py calls `if "const" in schema` where schema can be a
|
| 23 |
+
# plain bool (valid JSON Schema: additionalProperties=True/False).
|
| 24 |
+
# The `in` operator on a bool raises TypeError and crashes the whole Space.
|
| 25 |
+
# We patch both affected functions before importing gradio.
|
| 26 |
+
try:
|
| 27 |
+
import gradio_client.utils as _gcu
|
| 28 |
+
|
| 29 |
+
# Patch 1: get_type() β guard against non-dict schema argument
|
| 30 |
+
_orig_get_type = _gcu.get_type
|
| 31 |
+
|
| 32 |
+
def _safe_get_type(schema):
|
| 33 |
+
if not isinstance(schema, dict):
|
| 34 |
+
return "Any"
|
| 35 |
+
return _orig_get_type(schema)
|
| 36 |
+
|
| 37 |
+
_gcu.get_type = _safe_get_type
|
| 38 |
+
|
| 39 |
+
# Patch 2: _json_schema_to_python_type() β normalise bool additionalProperties
|
| 40 |
+
_orig_j2p = _gcu._json_schema_to_python_type
|
| 41 |
+
|
| 42 |
+
def _safe_j2p(schema, defs=None):
|
| 43 |
+
if not isinstance(schema, dict):
|
| 44 |
+
return "Any"
|
| 45 |
+
if isinstance(schema.get("additionalProperties"), bool):
|
| 46 |
+
schema = {**schema, "additionalProperties": {}}
|
| 47 |
+
return _orig_j2p(schema, defs)
|
| 48 |
+
|
| 49 |
+
_gcu._json_schema_to_python_type = _safe_j2p
|
| 50 |
+
print("β
gradio_client monkey-patch applied.")
|
| 51 |
+
except Exception as _e:
|
| 52 |
+
print(f"β οΈ gradio_client patch skipped: {_e}")
|
| 53 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 54 |
+
|
| 55 |
+
import gradio as gr
|
| 56 |
from PIL import Image
|
| 57 |
from transformers import CLIPModel, CLIPProcessor
|
| 58 |
from ultralytics import YOLO
|