Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,10 +37,11 @@ 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
|
|
|
|
| 44 |
"""
|
| 45 |
scores = model_entry["claude-3.5-sonnet Scores"]["3C3H Scores"]
|
| 46 |
# Create a vector with the metrics in the defined order.
|
|
@@ -69,14 +70,16 @@ def generate_heatmap_image(model_entry):
|
|
| 69 |
plt.savefig(buf, format="png")
|
| 70 |
plt.close()
|
| 71 |
buf.seek(0)
|
| 72 |
-
|
|
|
|
| 73 |
image = Image.open(buf).convert("RGB")
|
|
|
|
| 74 |
return image
|
| 75 |
|
| 76 |
def generate_heatmaps(selected_model_names):
|
| 77 |
"""
|
| 78 |
Filter the global DATA for entries matching the selected model names,
|
| 79 |
-
generate a heatmap for each, and return a list of
|
| 80 |
"""
|
| 81 |
filtered_entries = [entry for entry in DATA if entry["Meta"]["Model Name"] in selected_model_names]
|
| 82 |
images = []
|
|
@@ -93,10 +96,15 @@ with gr.Blocks() as demo:
|
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
generate_btn = gr.Button("Generate Heatmaps")
|
| 99 |
-
#
|
| 100 |
gallery = gr.Gallery(label="Heatmaps", columns=2)
|
| 101 |
|
| 102 |
generate_btn.click(fn=generate_heatmaps, inputs=model_dropdown, outputs=gallery)
|
|
|
|
| 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, max_size=(400, 400)):
|
| 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.
|
|
|
|
| 70 |
plt.savefig(buf, format="png")
|
| 71 |
plt.close()
|
| 72 |
buf.seek(0)
|
| 73 |
+
|
| 74 |
+
# Convert the buffer into a PIL Image and resize it
|
| 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):
|
| 80 |
"""
|
| 81 |
Filter the global DATA for entries matching the selected model names,
|
| 82 |
+
generate a heatmap for each, and return a list of PIL images.
|
| 83 |
"""
|
| 84 |
filtered_entries = [entry for entry in DATA if entry["Meta"]["Model Name"] in selected_model_names]
|
| 85 |
images = []
|
|
|
|
| 96 |
gr.Markdown("Select the models you want to compare and generate their heatmaps below.")
|
| 97 |
|
| 98 |
with gr.Row():
|
| 99 |
+
model_dropdown = gr.Dropdown(
|
| 100 |
+
choices=MODEL_NAMES,
|
| 101 |
+
label="Select Model(s)",
|
| 102 |
+
multiselect=True,
|
| 103 |
+
value=MODEL_NAMES[:3]
|
| 104 |
+
)
|
| 105 |
|
| 106 |
generate_btn = gr.Button("Generate Heatmaps")
|
| 107 |
+
# The 'columns' parameter will display images in a grid with 2 columns.
|
| 108 |
gallery = gr.Gallery(label="Heatmaps", columns=2)
|
| 109 |
|
| 110 |
generate_btn.click(fn=generate_heatmaps, inputs=model_dropdown, outputs=gallery)
|