Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,6 @@ 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 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,8 +50,7 @@ def generate_heatmap_image(model_entry):
|
|
| 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 |
-
plt.figure(figsize=(4, 4))
|
| 56 |
sns.heatmap(matrix,
|
| 57 |
mask=mask,
|
| 58 |
annot=True,
|
|
@@ -71,11 +69,8 @@ def generate_heatmap_image(model_entry):
|
|
| 71 |
plt.savefig(buf, format="png")
|
| 72 |
plt.close()
|
| 73 |
buf.seek(0)
|
| 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((600, 600), Image.LANCZOS)
|
| 79 |
return image
|
| 80 |
|
| 81 |
def generate_heatmaps(selected_model_names):
|
|
@@ -84,7 +79,10 @@ 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 = [
|
|
|
|
|
|
|
|
|
|
| 88 |
return images
|
| 89 |
|
| 90 |
# -------------------------------
|
|
@@ -95,15 +93,10 @@ with gr.Blocks() as demo:
|
|
| 95 |
gr.Markdown("Select the models you want to compare and generate their heatmaps below.")
|
| 96 |
|
| 97 |
with gr.Row():
|
| 98 |
-
model_dropdown = gr.Dropdown(
|
| 99 |
-
choices=MODEL_NAMES,
|
| 100 |
-
label="Select Model(s)",
|
| 101 |
-
multiselect=True,
|
| 102 |
-
value=MODEL_NAMES[:3]
|
| 103 |
-
)
|
| 104 |
|
| 105 |
generate_btn = gr.Button("Generate Heatmaps")
|
| 106 |
-
#
|
| 107 |
gallery = gr.Gallery(label="Heatmaps", columns=2)
|
| 108 |
|
| 109 |
generate_btn.click(fn=generate_heatmaps, inputs=model_dropdown, outputs=gallery)
|
|
|
|
| 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 |
+
plt.figure(figsize=(6, 5))
|
|
|
|
| 54 |
sns.heatmap(matrix,
|
| 55 |
mask=mask,
|
| 56 |
annot=True,
|
|
|
|
| 69 |
plt.savefig(buf, format="png")
|
| 70 |
plt.close()
|
| 71 |
buf.seek(0)
|
| 72 |
+
# Convert the buffer into a PIL Image.
|
|
|
|
| 73 |
image = Image.open(buf).convert("RGB")
|
|
|
|
|
|
|
| 74 |
return image
|
| 75 |
|
| 76 |
def generate_heatmaps(selected_model_names):
|
|
|
|
| 79 |
generate a heatmap for each, and return a list of PIL images.
|
| 80 |
"""
|
| 81 |
filtered_entries = [entry for entry in DATA if entry["Meta"]["Model Name"] in selected_model_names]
|
| 82 |
+
images = []
|
| 83 |
+
for entry in filtered_entries:
|
| 84 |
+
img = generate_heatmap_image(entry)
|
| 85 |
+
images.append(img)
|
| 86 |
return images
|
| 87 |
|
| 88 |
# -------------------------------
|
|
|
|
| 93 |
gr.Markdown("Select the models you want to compare and generate their heatmaps below.")
|
| 94 |
|
| 95 |
with gr.Row():
|
| 96 |
+
model_dropdown = gr.Dropdown(choices=MODEL_NAMES, label="Select Model(s)", multiselect=True, value=MODEL_NAMES[:3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
generate_btn = gr.Button("Generate Heatmaps")
|
| 99 |
+
# Use the 'columns' parameter to set a grid layout in the gallery.
|
| 100 |
gallery = gr.Gallery(label="Heatmaps", columns=2)
|
| 101 |
|
| 102 |
generate_btn.click(fn=generate_heatmaps, inputs=model_dropdown, outputs=gallery)
|