Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,7 @@ 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,7 +51,7 @@ def generate_heatmap_image(model_entry):
|
|
| 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 |
-
#
|
| 54 |
plt.figure(figsize=(4, 4))
|
| 55 |
sns.heatmap(matrix,
|
| 56 |
mask=mask,
|
|
@@ -73,6 +74,8 @@ def generate_heatmap_image(model_entry):
|
|
| 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):
|
|
@@ -81,10 +84,7 @@ def generate_heatmaps(selected_model_names):
|
|
| 81 |
generate a heatmap for each, and return a list of PIL images.
|
| 82 |
"""
|
| 83 |
filtered_entries = [entry for entry in DATA if entry["Meta"]["Model Name"] in selected_model_names]
|
| 84 |
-
images = []
|
| 85 |
-
for entry in filtered_entries:
|
| 86 |
-
img = generate_heatmap_image(entry)
|
| 87 |
-
images.append(img)
|
| 88 |
return images
|
| 89 |
|
| 90 |
# -------------------------------
|
|
@@ -104,13 +104,7 @@ with gr.Blocks() as demo:
|
|
| 104 |
|
| 105 |
generate_btn = gr.Button("Generate Heatmaps")
|
| 106 |
# The 'columns' parameter will display images in a grid with 2 columns.
|
| 107 |
-
|
| 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 |
|
|
|
|
| 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 resized to 300x300 pixels.
|
| 45 |
"""
|
| 46 |
scores = model_entry["claude-3.5-sonnet Scores"]["3C3H Scores"]
|
| 47 |
# Create a vector with the metrics in the defined order.
|
|
|
|
| 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 |
+
# Set a smaller figure size to produce a smaller output image.
|
| 55 |
plt.figure(figsize=(4, 4))
|
| 56 |
sns.heatmap(matrix,
|
| 57 |
mask=mask,
|
|
|
|
| 74 |
|
| 75 |
# Convert the buffer into a PIL Image
|
| 76 |
image = Image.open(buf).convert("RGB")
|
| 77 |
+
# Resize the image to a fixed size of 300x300 pixels.
|
| 78 |
+
image = image.resize((300, 300), Image.LANCZOS)
|
| 79 |
return image
|
| 80 |
|
| 81 |
def generate_heatmaps(selected_model_names):
|
|
|
|
| 84 |
generate a heatmap for each, and return a list of PIL images.
|
| 85 |
"""
|
| 86 |
filtered_entries = [entry for entry in DATA if entry["Meta"]["Model Name"] in selected_model_names]
|
| 87 |
+
images = [generate_heatmap_image(entry) for entry in filtered_entries]
|
|
|
|
|
|
|
|
|
|
| 88 |
return images
|
| 89 |
|
| 90 |
# -------------------------------
|
|
|
|
| 104 |
|
| 105 |
generate_btn = gr.Button("Generate Heatmaps")
|
| 106 |
# The 'columns' parameter will display images in a grid with 2 columns.
|
| 107 |
+
gallery = gr.Gallery(label="Heatmaps", columns=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
generate_btn.click(fn=generate_heatmaps, inputs=model_dropdown, outputs=gallery)
|
| 110 |
|