Faraz618 commited on
Commit
3ae2e3b
Β·
verified Β·
1 Parent(s): f535624

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
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