wxy01giser commited on
Commit
e8e9cff
·
verified ·
1 Parent(s): fadd831

Update sankey_plot.py

Browse files
Files changed (1) hide show
  1. sankey_plot.py +12 -1
sankey_plot.py CHANGED
@@ -8,7 +8,18 @@ import base64
8
  import pandas as pd
9
 
10
  # ========== 关键修改1:统一使用 Plotly 内置中文字体 ==========
11
- CHINESE_FONT = "Noto Sans SC" # 和聚类图保持一致,避免混乱
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  def plot_sankey_from_df(sankey_df: pd.DataFrame, title="问题 → 关键词共现") -> str:
14
  if sankey_df.empty:
 
8
  import pandas as pd
9
 
10
  # ========== 关键修改1:统一使用 Plotly 内置中文字体 ==========
11
+ from plotly.io._kaleido import KaleidoProcess # 导入 Kaleido 进程类
12
+
13
+ # ========== 关键1:指定字体文件路径(HF Spaces 根目录) ==========
14
+ FONT_FILE_PATH = "./SourceHanSansSC-Light.otf" # 字体文件和 main.py 同级
15
+ CHINESE_FONT = "Source Han Sans SC" # 字体名称(必须和字体文件内置名称一致)
16
+
17
+ # ========== 关键2:验证字体文件是否存在(避免路径错误) ==========
18
+ if not os.path.exists(FONT_FILE_PATH):
19
+ print(f"⚠️ 字体文件不存在!当前路径:{os.getcwd()},文件列表:{os.listdir('.')}")
20
+ else:
21
+ print(f"✅ 找到字体文件:{FONT_FILE_PATH},大小:{os.path.getsize(FONT_FILE_PATH)/1024:.1f}KB")
22
+ # CHINESE_FONT = "Noto Sans SC" # 和聚类图保持一致,避免混乱
23
 
24
  def plot_sankey_from_df(sankey_df: pd.DataFrame, title="问题 → 关键词共现") -> str:
25
  if sankey_df.empty: