import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np from PIL import Image import io DIMENSIONS = ["Generalization", "Relevance", "Artistry", "Efficiency"] def compute_sample_scores(results, prompt): """模拟评分 - 实际项目应替换为真实评估逻辑""" return { "sd_v1_5": [4, 4, 4, 3], "openjourney_v4": [3, 4, 5, 3], "ldm_256": [2, 3, 3, 5] } def plot_radar(scores_dict, out_path="radar.png"): fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, polar=True) angles = np.linspace(0, 2*np.pi, len(DIMENSIONS), endpoint=False) angles = np.concatenate((angles, [angles[0]])) for model, scores in scores_dict.items(): data = np.concatenate((scores, [scores[0]])) ax.plot(angles, data, linewidth=2, linestyle='solid', label=model) ax.fill(angles, data, alpha=0.1) ax.set_thetagrids(angles[:-1] * 180/np.pi, DIMENSIONS) ax.set_title("GRACE Evaluation Radar", size=14, pad=20) ax.legend(loc='upper right') buf = io.BytesIO() plt.savefig(buf, format='png', bbox_inches='tight') plt.close() buf.seek(0) return Image.open(buf)