Sheldon Zheng commited on
Commit
8b791f2
·
1 Parent(s): ca9ebec

fix: pin plotly<6.0.0 to eliminate bdata binary encoding

Browse files

Root cause: Plotly 6.x encodes numpy arrays as bdata (base64 binary)
at the to_dict() level - NOT during JSON serialization. This means
all orjson/json-engine patches were ineffective since bdata is baked
into the Figure data structure itself.

Solution: Pin plotly to 5.x which uses standard list format for arrays.
Also remove all orjson-related patches (no longer needed) and kaleido
(was irrelevant to the rendering issue).

Files changed (2) hide show
  1. app.py +0 -8
  2. requirements.txt +1 -2
app.py CHANGED
@@ -27,14 +27,6 @@ import gradio as gr
27
  import sys
28
  from pathlib import Path
29
 
30
- # ── 屏蔽 Plotly 使用 orjson (必须在 import gradio 之后) ──
31
- # Gradio 在 utils.py:52 直接 import orjson,所以不能在导入前屏蔽。
32
- # 但 Gradio 导入后 orjson 已绑定到 gradio.utils.orjson,修改 sys.modules 不影响它。
33
- # Plotly 6.x 在每次序列化时通过 get_module("orjson") 动态查询 sys.modules,
34
- # 设为 None 后 get_module 返回 None,Plotly 回退到标准 json 引擎 (无 bdata)。
35
- sys.modules["orjson"] = None
36
- # ── End orjson block ──
37
-
38
  # 添加项目路径 (HuggingFace Spaces 兼容)
39
  DEMO_DIR = Path(__file__).parent
40
  sys.path.insert(0, str(DEMO_DIR))
 
27
  import sys
28
  from pathlib import Path
29
 
 
 
 
 
 
 
 
 
30
  # 添加项目路径 (HuggingFace Spaces 兼容)
31
  DEMO_DIR = Path(__file__).parent
32
  sys.path.insert(0, str(DEMO_DIR))
requirements.txt CHANGED
@@ -1,6 +1,5 @@
1
  gradio==4.44.1
2
- plotly>=5.18.0
3
- kaleido>=0.2.1
4
  pandas>=2.0.0
5
  numpy>=1.24.0
6
  scikit-learn>=1.3.0
 
1
  gradio==4.44.1
2
+ plotly>=5.18.0,<6.0.0
 
3
  pandas>=2.0.0
4
  numpy>=1.24.0
5
  scikit-learn>=1.3.0