Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -37,11 +37,10 @@ MODEL_NAMES = get_model_names(DATA)
|
|
37 |
# Define the six metrics in the desired order.
|
38 |
METRICS = ["Correctness", "Completeness", "Conciseness", "Helpfulness", "Honesty", "Harmlessness"]
|
39 |
|
40 |
-
def generate_heatmap_image(model_entry
|
41 |
"""
|
42 |
For a given model entry, extract the six metrics and compute a 6x6 similarity matrix
|
43 |
using the definition: similarity = 1 - |v_i - v_j|, then return the heatmap as a PIL image.
|
44 |
-
The image is then resized (via thumbnail) to fit the specified max_size.
|
45 |
"""
|
46 |
scores = model_entry["claude-3.5-sonnet Scores"]["3C3H Scores"]
|
47 |
# Create a vector with the metrics in the defined order.
|
@@ -51,7 +50,8 @@ def generate_heatmap_image(model_entry, max_size=(20, 20)):
|
|
51 |
# Create a mask for the upper triangle (keeping the diagonal visible).
|
52 |
mask = np.triu(np.ones_like(matrix, dtype=bool), k=1)
|
53 |
|
54 |
-
|
|
|
55 |
sns.heatmap(matrix,
|
56 |
mask=mask,
|
57 |
annot=True,
|
@@ -71,9 +71,8 @@ def generate_heatmap_image(model_entry, max_size=(20, 20)):
|
|
71 |
plt.close()
|
72 |
buf.seek(0)
|
73 |
|
74 |
-
# Convert the buffer into a PIL Image
|
75 |
image = Image.open(buf).convert("RGB")
|
76 |
-
image.thumbnail(max_size) # e.g., (400, 400)
|
77 |
return image
|
78 |
|
79 |
def generate_heatmaps(selected_model_names):
|
@@ -105,7 +104,13 @@ with gr.Blocks() as demo:
|
|
105 |
|
106 |
generate_btn = gr.Button("Generate Heatmaps")
|
107 |
# The 'columns' parameter will display images in a grid with 2 columns.
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
generate_btn.click(fn=generate_heatmaps, inputs=model_dropdown, outputs=gallery)
|
111 |
|
|
|
37 |
# Define the six metrics in the desired order.
|
38 |
METRICS = ["Correctness", "Completeness", "Conciseness", "Helpfulness", "Honesty", "Harmlessness"]
|
39 |
|
40 |
+
def generate_heatmap_image(model_entry):
|
41 |
"""
|
42 |
For a given model entry, extract the six metrics and compute a 6x6 similarity matrix
|
43 |
using the definition: similarity = 1 - |v_i - v_j|, then return the heatmap as a PIL image.
|
|
|
44 |
"""
|
45 |
scores = model_entry["claude-3.5-sonnet Scores"]["3C3H Scores"]
|
46 |
# Create a vector with the metrics in the defined order.
|
|
|
50 |
# Create a mask for the upper triangle (keeping the diagonal visible).
|
51 |
mask = np.triu(np.ones_like(matrix, dtype=bool), k=1)
|
52 |
|
53 |
+
# Make the figure itself smaller
|
54 |
+
plt.figure(figsize=(4, 4))
|
55 |
sns.heatmap(matrix,
|
56 |
mask=mask,
|
57 |
annot=True,
|
|
|
71 |
plt.close()
|
72 |
buf.seek(0)
|
73 |
|
74 |
+
# Convert the buffer into a PIL Image
|
75 |
image = Image.open(buf).convert("RGB")
|
|
|
76 |
return image
|
77 |
|
78 |
def generate_heatmaps(selected_model_names):
|
|
|
104 |
|
105 |
generate_btn = gr.Button("Generate Heatmaps")
|
106 |
# The 'columns' parameter will display images in a grid with 2 columns.
|
107 |
+
# 'image_size=(300, 300)' ensures each image is displayed at 300x300 px.
|
108 |
+
gallery = gr.Gallery(
|
109 |
+
label="Heatmaps",
|
110 |
+
columns=2,
|
111 |
+
image_size=(200, 200),
|
112 |
+
object_fit="contain"
|
113 |
+
)
|
114 |
|
115 |
generate_btn.click(fn=generate_heatmaps, inputs=model_dropdown, outputs=gallery)
|
116 |
|