tmdwo commited on
Commit
6cc746a
·
verified ·
1 Parent(s): 26268f4

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -2
app.py CHANGED
@@ -9,11 +9,51 @@ import matplotlib
9
  import matplotlib.pyplot as plt
10
  import pandas as pd
11
  from PIL import Image, ImageDraw
 
12
  from transformers import (
13
  Sam3Model, Sam3Processor,
14
  Sam3TrackerModel, Sam3TrackerProcessor
15
  )
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # ============ THEME SETUP ============
18
  # Theme disabled to avoid API schema issues on HF Spaces
19
 
@@ -645,10 +685,10 @@ with gr.Blocks() as demo:
645
 
646
  @spaces.GPU
647
  def run_spaces():
648
- demo.launch()
649
 
650
  def run_local():
651
- demo.launch(show_error=True)
652
 
653
  if __name__ == "__main__":
654
  # Hugging Spaces 환경 감지
 
9
  import matplotlib.pyplot as plt
10
  import pandas as pd
11
  from PIL import Image, ImageDraw
12
+ import inspect
13
  from transformers import (
14
  Sam3Model, Sam3Processor,
15
  Sam3TrackerModel, Sam3TrackerProcessor
16
  )
17
 
18
+ # ============ GRADIO CLIENT COMPAT PATCH ============
19
+ # HF Spaces (and some Gradio versions) may ship with gradio_client that crashes when
20
+ # it encounters boolean JSON Schema nodes (e.g., additionalProperties: false) while
21
+ # generating /info API schema. Patch defensively to prevent startup failures.
22
+ try:
23
+ import gradio_client.utils as _grc_utils
24
+
25
+ if not getattr(_grc_utils, "_BOOL_SCHEMA_PATCHED", False):
26
+ _orig_get_type = _grc_utils.get_type
27
+
28
+ def _safe_get_type(schema): # noqa: ANN001
29
+ if isinstance(schema, bool) or not isinstance(schema, dict):
30
+ # boolean schema: True => any, False => no additional props
31
+ # For our purposes (API type rendering), treat as Any to avoid crashes.
32
+ return "any"
33
+ return _orig_get_type(schema)
34
+
35
+ _grc_utils.get_type = _safe_get_type
36
+ _grc_utils._BOOL_SCHEMA_PATCHED = True
37
+ except Exception as _e:
38
+ # If gradio_client is unavailable or API changes, ignore and proceed.
39
+ print(f"[warn] gradio_client schema patch skipped: {_e}")
40
+
41
+ # ============ GRADIO LAUNCH COMPAT ============
42
+ def _launch_compat(demo, **kwargs):
43
+ """
44
+ Gradio 버전별로 Blocks.launch() 시그니처가 달라서(예: ssr 지원 여부),
45
+ 현재 설치된 Gradio가 지원하는 키만 골라 launch()를 호출한다.
46
+ """
47
+ try:
48
+ sig = inspect.signature(demo.launch)
49
+ supported = set(sig.parameters.keys())
50
+ filtered = {k: v for k, v in kwargs.items() if k in supported}
51
+ return demo.launch(**filtered)
52
+ except Exception:
53
+ # signature introspection 실패 시, 보수적으로 ssr만 제거 후 재시도
54
+ kwargs.pop("ssr", None)
55
+ return demo.launch(**kwargs)
56
+
57
  # ============ THEME SETUP ============
58
  # Theme disabled to avoid API schema issues on HF Spaces
59
 
 
685
 
686
  @spaces.GPU
687
  def run_spaces():
688
+ _launch_compat(demo, ssr=False)
689
 
690
  def run_local():
691
+ _launch_compat(demo, show_error=True, ssr=False)
692
 
693
  if __name__ == "__main__":
694
  # Hugging Spaces 환경 감지