shiue2000 commited on
Commit
a761827
·
verified ·
1 Parent(s): fb7598d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -9,12 +9,25 @@ import networkx as nx
9
  from datetime import datetime, timedelta
10
  import gradio as gr
11
  import logging
 
12
 
13
  # 設置日誌
14
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
15
 
16
  # 中文顯示設置
17
- plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei', 'Arial Unicode MS', 'SimHei', 'DejaVu Sans']
 
 
 
 
 
 
 
 
 
 
 
 
18
  plt.rcParams['axes.unicode_minus'] = False
19
 
20
  # 參數設定
 
9
  from datetime import datetime, timedelta
10
  import gradio as gr
11
  import logging
12
+ import matplotlib.font_manager as fm
13
 
14
  # 設置日誌
15
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
16
 
17
  # 中文顯示設置
18
+ font_list = ['Microsoft JhengHei', 'SimHei', 'Arial Unicode MS', 'DejaVu Sans']
19
+ available_fonts = [f.name for f in fm.fontManager.ttflist]
20
+ selected_font = None
21
+ for font in font_list:
22
+ if font in available_fonts:
23
+ selected_font = font
24
+ break
25
+
26
+ if selected_font:
27
+ logging.info(f"Using font: {selected_font}")
28
+ plt.rcParams['font.sans-serif'] = [selected_font]
29
+ else:
30
+ logging.warning("No specified Chinese fonts found. Falling back to default. Chinese text may not render correctly.")
31
  plt.rcParams['axes.unicode_minus'] = False
32
 
33
  # 參數設定