Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
app.py
CHANGED
@@ -515,20 +515,24 @@ import os
|
|
515 |
import logging
|
516 |
from matplotlib import font_manager
|
517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
518 |
def generate_kg_image(entities, relations):
|
519 |
"""
|
520 |
中文知识图谱生成函数,支持自动匹配系统中的中文字体,避免中文显示为方框。
|
521 |
"""
|
522 |
try:
|
523 |
# === 1. 确保使用合适的中文字体 ===
|
524 |
-
|
525 |
-
# 使用字体路径而非字体名,这里硬编码路径
|
526 |
-
font_path = "/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc"
|
527 |
-
if os.path.exists(font_path):
|
528 |
-
return font_path
|
529 |
-
return None
|
530 |
-
|
531 |
-
chinese_font = find_chinese_font()
|
532 |
if chinese_font:
|
533 |
plt.rcParams['font.sans-serif'] = [chinese_font]
|
534 |
else:
|
@@ -617,6 +621,7 @@ def generate_kg_image(entities, relations):
|
|
617 |
|
618 |
|
619 |
|
|
|
620 |
# ======================== 文件处理 ========================
|
621 |
def process_file(file, model_type="bert"):
|
622 |
try:
|
|
|
515 |
import logging
|
516 |
from matplotlib import font_manager
|
517 |
|
518 |
+
# 这个函数用于查找并验证中文字体路径
|
519 |
+
def find_chinese_font():
|
520 |
+
# 使用字体路径而非字体名,这里硬编码路径
|
521 |
+
font_path = "/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc"
|
522 |
+
if os.path.exists(font_path):
|
523 |
+
logging.info(f"Found font at {font_path}")
|
524 |
+
return font_path
|
525 |
+
else:
|
526 |
+
logging.error("Font not found!")
|
527 |
+
return None
|
528 |
+
|
529 |
def generate_kg_image(entities, relations):
|
530 |
"""
|
531 |
中文知识图谱生成函数,支持自动匹配系统中的中文字体,避免中文显示为方框。
|
532 |
"""
|
533 |
try:
|
534 |
# === 1. 确保使用合适的中文字体 ===
|
535 |
+
chinese_font = find_chinese_font() # 调用查找字体函数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
if chinese_font:
|
537 |
plt.rcParams['font.sans-serif'] = [chinese_font]
|
538 |
else:
|
|
|
621 |
|
622 |
|
623 |
|
624 |
+
|
625 |
# ======================== 文件处理 ========================
|
626 |
def process_file(file, model_type="bert"):
|
627 |
try:
|