hutiger commited on
Commit
e03b72a
·
verified ·
1 Parent(s): 7e18bc7

Fix Gradio 5.0.0 additionalProperties bug

Browse files
Files changed (1) hide show
  1. app.py +30 -2
app.py CHANGED
@@ -3,14 +3,18 @@ Hugging Face Spaces 入口
3
  """
4
  import sys
5
 
6
- # 补丁: audioop (Python 3.13)
 
 
7
  try:
8
  import audioop_lts as audioop
9
  sys.modules["pyaudioop"] = audioop
10
  except ImportError:
11
  pass
12
 
13
- # 补丁: HfFolder
 
 
14
  try:
15
  import huggingface_hub
16
  if not hasattr(huggingface_hub, "HfFolder"):
@@ -23,6 +27,30 @@ try:
23
  except Exception:
24
  pass
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # 启动
 
27
  from webui import demo
28
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)
 
3
  """
4
  import sys
5
 
6
+ # --------------------------------------------------
7
+ # 补丁 1: audioop (Python 3.13)
8
+ # --------------------------------------------------
9
  try:
10
  import audioop_lts as audioop
11
  sys.modules["pyaudioop"] = audioop
12
  except ImportError:
13
  pass
14
 
15
+ # --------------------------------------------------
16
+ # 补丁 2: HfFolder (huggingface-hub>=0.25)
17
+ # --------------------------------------------------
18
  try:
19
  import huggingface_hub
20
  if not hasattr(huggingface_hub, "HfFolder"):
 
27
  except Exception:
28
  pass
29
 
30
+ # --------------------------------------------------
31
+ # 补丁 3: Gradio 5.0.0 bug - additionalProperties 布尔值
32
+ # --------------------------------------------------
33
+ try:
34
+ import gradio_client.utils as gcu
35
+ _orig = gcu._json_schema_to_python_type
36
+ def _patched(schema, defs=None):
37
+ if isinstance(schema, bool):
38
+ return "any"
39
+ return _orig(schema, defs)
40
+ gcu._json_schema_to_python_type = _patched
41
+ # 也 patche get_type 以防被直接调用
42
+ if hasattr(gcu, "get_type"):
43
+ _orig_get = gcu.get_type
44
+ def _patched_get(schema):
45
+ if isinstance(schema, bool):
46
+ return "any"
47
+ return _orig_get(schema)
48
+ gcu.get_type = _patched_get
49
+ except Exception:
50
+ pass
51
+
52
+ # --------------------------------------------------
53
  # 启动
54
+ # --------------------------------------------------
55
  from webui import demo
56
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)