Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -542,19 +542,18 @@ def generate_kg_image(entities, relations):
|
|
542 |
font_prop = font_manager.FontProperties(fname=chinese_font)
|
543 |
plt.rcParams['font.family'] = font_prop.get_name()
|
544 |
else:
|
545 |
-
# 如果字体路径未找到,使用默认字体(DejaVu Sans)
|
546 |
logging.warning("Using default font")
|
547 |
-
|
548 |
-
|
549 |
plt.rcParams['axes.unicode_minus'] = False
|
550 |
|
551 |
# === 2. 创建图谱 ===
|
552 |
G = nx.DiGraph()
|
553 |
entity_colors = {
|
554 |
-
'PER': '#FF6B6B',
|
555 |
-
'ORG': '#4ECDC4',
|
556 |
-
'LOC': '#45B7D1',
|
557 |
-
'TIME': '#96CEB4'
|
|
|
558 |
}
|
559 |
|
560 |
for entity in entities:
|
@@ -595,7 +594,7 @@ def generate_kg_image(entities, relations):
|
|
595 |
G, pos,
|
596 |
labels=node_labels,
|
597 |
font_size=10,
|
598 |
-
|
599 |
font_weight='bold'
|
600 |
)
|
601 |
|
@@ -604,17 +603,15 @@ def generate_kg_image(entities, relations):
|
|
604 |
G, pos,
|
605 |
edge_labels=edge_labels,
|
606 |
font_size=8,
|
607 |
-
|
608 |
)
|
609 |
|
610 |
plt.axis('off')
|
611 |
plt.tight_layout()
|
612 |
|
613 |
# === 4. 保存图片 ===
|
614 |
-
temp_dir = tempfile.mkdtemp()
|
615 |
output_path = os.path.join(temp_dir, "kg.png")
|
616 |
-
|
617 |
-
# 打印路径以方便调试
|
618 |
logging.info(f"Saving graph image to {output_path}")
|
619 |
|
620 |
plt.savefig(output_path, bbox_inches='tight', pad_inches=0.1)
|
|
|
542 |
font_prop = font_manager.FontProperties(fname=chinese_font)
|
543 |
plt.rcParams['font.family'] = font_prop.get_name()
|
544 |
else:
|
|
|
545 |
logging.warning("Using default font")
|
546 |
+
font_prop = font_manager.FontProperties() # fallback
|
|
|
547 |
plt.rcParams['axes.unicode_minus'] = False
|
548 |
|
549 |
# === 2. 创建图谱 ===
|
550 |
G = nx.DiGraph()
|
551 |
entity_colors = {
|
552 |
+
'PER': '#FF6B6B',
|
553 |
+
'ORG': '#4ECDC4',
|
554 |
+
'LOC': '#45B7D1',
|
555 |
+
'TIME': '#96CEB4',
|
556 |
+
'TITLE': '#D3D3D3'
|
557 |
}
|
558 |
|
559 |
for entity in entities:
|
|
|
594 |
G, pos,
|
595 |
labels=node_labels,
|
596 |
font_size=10,
|
597 |
+
font_properties=font_prop,
|
598 |
font_weight='bold'
|
599 |
)
|
600 |
|
|
|
603 |
G, pos,
|
604 |
edge_labels=edge_labels,
|
605 |
font_size=8,
|
606 |
+
font_properties=font_prop
|
607 |
)
|
608 |
|
609 |
plt.axis('off')
|
610 |
plt.tight_layout()
|
611 |
|
612 |
# === 4. 保存图片 ===
|
613 |
+
temp_dir = tempfile.mkdtemp()
|
614 |
output_path = os.path.join(temp_dir, "kg.png")
|
|
|
|
|
615 |
logging.info(f"Saving graph image to {output_path}")
|
616 |
|
617 |
plt.savefig(output_path, bbox_inches='tight', pad_inches=0.1)
|