Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,6 +43,35 @@ def plot_scatter(cat, x, y, col):
|
|
43 |
# Show the plot
|
44 |
return fig
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# Gradio Interface
|
48 |
with gr.Blocks() as demo:
|
@@ -86,6 +115,15 @@ with gr.Blocks() as demo:
|
|
86 |
],
|
87 |
gr.Plot(label="plot", format="png",), allow_flagging="never",
|
88 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
# Launch the Gradio app
|
91 |
-
demo.launch()
|
|
|
43 |
# Show the plot
|
44 |
return fig
|
45 |
|
46 |
+
# Tab 3
|
47 |
+
def plot_scatter_tab3(subcat, col):
|
48 |
+
if subcat != "All":
|
49 |
+
data = raw_data[raw_data["Category"] == subcat]
|
50 |
+
else:
|
51 |
+
data = raw_data
|
52 |
+
# Group by model and tag
|
53 |
+
grouped_cat = data.groupby(["model", "tag"]).size().reset_index(name="count").sort_values(by="count", ascending=False)
|
54 |
+
|
55 |
+
# map for harm and helpful
|
56 |
+
grouped_cat["Harmful"] = grouped_cat.apply(lambda x: x["count"] if x["tag"] in ["A", "W"] else 0, axis=1)
|
57 |
+
grouped_cat["Helpful"] = grouped_cat.apply(lambda x: x["count"] if x["tag"] in ["A", "W", "R"] else 0, axis=1)
|
58 |
+
|
59 |
+
# sum harm and helpful for each model
|
60 |
+
grouped_cat = grouped_cat.groupby("model").sum().reset_index()
|
61 |
+
# normalize
|
62 |
+
grouped_cat["Harmful"] = grouped_cat["Harmful"] / grouped_cat["count"]
|
63 |
+
grouped_cat["Helpful"] = grouped_cat["Helpful"] / grouped_cat["count"]
|
64 |
+
|
65 |
+
# add color vis
|
66 |
+
if col == "Size":
|
67 |
+
grouped_cat[col] = grouped_cat["model"].apply(lambda x: size_map[x])
|
68 |
+
else:
|
69 |
+
grouped_cat[col] = grouped_cat["model"].apply(lambda x: x.split("/")[0])
|
70 |
+
|
71 |
+
fig = px.scatter(grouped_cat, x="Harmful", y="Helpful", hover_name=grouped_cat["model"], title="Harmfulness vs Helpfulness", color=col, color_continuous_scale="agsunset")
|
72 |
+
|
73 |
+
return fig
|
74 |
+
|
75 |
|
76 |
# Gradio Interface
|
77 |
with gr.Blocks() as demo:
|
|
|
115 |
],
|
116 |
gr.Plot(label="plot", format="png",), allow_flagging="never",
|
117 |
)
|
118 |
+
with gr.TabItem("Helpfulness vs Harmfulness"):
|
119 |
+
gr.Interface(
|
120 |
+
plot_scatter_tab3,
|
121 |
+
[
|
122 |
+
gr.Radio(["Copyright", "Malware", "Unfair/dangerous", "All"], value="All", label="Category Selection"),
|
123 |
+
gr.Radio(['Organisation', 'Size'], value="Organisation", label="Color Label"),
|
124 |
+
],
|
125 |
+
gr.Plot(label="forecast", format="png"),
|
126 |
+
)
|
127 |
|
128 |
# Launch the Gradio app
|
129 |
+
demo.launch(share=True)
|