Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,74 +6,45 @@ LEADERBOARD_FILE = "results.csv"
|
|
| 6 |
def load_leaderboard():
|
| 7 |
return pd.read_csv(LEADERBOARD_FILE)
|
| 8 |
|
| 9 |
-
def
|
| 10 |
df = load_leaderboard()
|
| 11 |
|
| 12 |
-
if
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
elif score_type == "HITL Split":
|
| 22 |
-
df = df[["Model", "HITL Safe Tasks Score", "HITL Harm Tasks Score"]]
|
| 23 |
-
sort_col = "HITL Safe Tasks Score"
|
| 24 |
else:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
if open_filter == "Open":
|
| 35 |
-
df = df[df["Open"] == True]
|
| 36 |
-
elif open_filter == "Closed":
|
| 37 |
-
df = df[df["Open"] == False]
|
| 38 |
-
|
| 39 |
-
df = df[["Model", "Bias", "Cybercrime", "Harassment", "Misinformation", "Illegal Activity"]]
|
| 40 |
-
return df
|
| 41 |
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
gr.Markdown("# SafeArena Leaderboard")
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
gr.Markdown("### Filter Models")
|
| 50 |
-
open_both = gr.Button("Both", variant="primary")
|
| 51 |
-
open_open = gr.Button("Open")
|
| 52 |
-
open_closed = gr.Button("Closed")
|
| 53 |
-
|
| 54 |
-
table_overall = gr.Dataframe(value=display_leaderboard("Overall", "Both"), interactive=False)
|
| 55 |
-
table_categories = gr.Dataframe(value=display_category_scores("Both"), interactive=False)
|
| 56 |
-
|
| 57 |
-
open_both.click(
|
| 58 |
-
lambda score: (display_leaderboard(score, "Both"), display_category_scores("Both"), "Both"),
|
| 59 |
-
inputs=[score_filter],
|
| 60 |
-
outputs=[table_overall, table_categories, open_state]
|
| 61 |
-
)
|
| 62 |
-
open_open.click(
|
| 63 |
-
lambda score: (display_leaderboard(score, "Open"), display_category_scores("Open"), "Open"),
|
| 64 |
-
inputs=[score_filter],
|
| 65 |
-
outputs=[table_overall, table_categories, open_state]
|
| 66 |
-
)
|
| 67 |
-
open_closed.click(
|
| 68 |
-
lambda score: (display_leaderboard(score, "Closed"), display_category_scores("Closed"), "Closed"),
|
| 69 |
-
inputs=[score_filter],
|
| 70 |
-
outputs=[table_overall, table_categories, open_state]
|
| 71 |
)
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
)
|
| 78 |
|
| 79 |
-
demo.launch(share=True)
|
|
|
|
| 6 |
def load_leaderboard():
|
| 7 |
return pd.read_csv(LEADERBOARD_FILE)
|
| 8 |
|
| 9 |
+
def display_data(data_type="Overall"):
|
| 10 |
df = load_leaderboard()
|
| 11 |
|
| 12 |
+
if data_type == "Overall":
|
| 13 |
+
new_df = pd.DataFrame({
|
| 14 |
+
"Model": df["Model"],
|
| 15 |
+
"Safe Score": df["Overall Safe Tasks Score"],
|
| 16 |
+
"Harm Score": df["Overall Harm Tasks Score"],
|
| 17 |
+
"Refusal Rate": df["Refusal Rate"],
|
| 18 |
+
"Normalized Safety Score": df["Normalized Safety Score"],
|
| 19 |
+
"Open": df["Open"]
|
| 20 |
+
})
|
|
|
|
|
|
|
|
|
|
| 21 |
else:
|
| 22 |
+
new_df = pd.DataFrame({
|
| 23 |
+
"Model": df["Model"],
|
| 24 |
+
"Safe Score": df[data_type],
|
| 25 |
+
"Harm Score": "",
|
| 26 |
+
"Refusal Rate": "",
|
| 27 |
+
"Normalized Safety Score": "",
|
| 28 |
+
"Open": df["Open"]
|
| 29 |
+
})
|
| 30 |
|
| 31 |
+
return new_df.sort_values(by="Safe Score", ascending=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
gr.Markdown("# SafeArena Leaderboard")
|
| 35 |
|
| 36 |
+
data_type_dropdown = gr.Dropdown(
|
| 37 |
+
label="Data Type",
|
| 38 |
+
choices=["Overall", "Bias", "Cybercrime", "Harassment", "Misinformation", "Illegal Activity"],
|
| 39 |
+
value="Overall"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
)
|
| 41 |
|
| 42 |
+
table = gr.Dataframe(value=display_data("Overall"), interactive=False)
|
| 43 |
+
|
| 44 |
+
data_type_dropdown.change(
|
| 45 |
+
fn=display_data,
|
| 46 |
+
inputs=data_type_dropdown,
|
| 47 |
+
outputs=table
|
| 48 |
)
|
| 49 |
|
| 50 |
+
demo.launch(share=True)
|