Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,6 +72,40 @@ def plot_scatter_tab3(subcat, col):
|
|
| 72 |
|
| 73 |
return fig
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
# Gradio Interface
|
| 77 |
with gr.Blocks() as demo:
|
|
@@ -117,7 +151,7 @@ with gr.Blocks() as demo:
|
|
| 117 |
)
|
| 118 |
with gr.TabItem("Helpfulness vs Harmfulness"):
|
| 119 |
gr.Markdown("""
|
| 120 |
-
#
|
| 121 |
|
| 122 |
This scatterplot displays for each model the comparison between the rate of Helpful vs Harmful responses.
|
| 123 |
You can filter the categories and choose the color of the datapoints based on model or size.
|
|
@@ -131,6 +165,15 @@ with gr.Blocks() as demo:
|
|
| 131 |
],
|
| 132 |
gr.Plot(label="forecast", format="png"),
|
| 133 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
# Launch the Gradio app
|
| 136 |
demo.launch(share=True)
|
|
|
|
| 72 |
|
| 73 |
return fig
|
| 74 |
|
| 75 |
+
# Tab 4
|
| 76 |
+
cats = ["Copyright", "Malware", "Unfair/dangerous"]
|
| 77 |
+
sub_cats = {"Copyright" : ['DRM', 'Encryption', 'Watermarking', 'Patent', 'Trademark',
|
| 78 |
+
'Copy left licenses', 'Keygen', 'Reverse engineering',
|
| 79 |
+
'Code sharing platforms', 'Public repositories',
|
| 80 |
+
'Unauthorized distribution channels'], "Malware" : ['Keylogger', 'Ransomware', 'RAT' ,'Phishing' ,'Rootkit' ,'Worm' ,'Spyware'
|
| 81 |
+
'Exploit', 'Adware' ,'Botnet' ,'Anti-detection'], "Unfair/dangerous" : ['Phishing' ,'Biased Code Generation' ,'Cyber Attacks' ,'Model Attacks']}
|
| 82 |
+
|
| 83 |
+
def rs_change(rs):
|
| 84 |
+
return gr.Dropdown(choices=list(sub_cats[rs]))
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def plot_scatter_tab4(cat, subcat, x, y, col):
|
| 88 |
+
data = raw_data[raw_data["Category"] == cat]
|
| 89 |
+
data = data[data["Sub-Category"] == subcat]
|
| 90 |
+
# Group by model and tag
|
| 91 |
+
grouped_cat = data.groupby(["model", "tag"]).size().reset_index(name="count").sort_values(by="count", ascending=False)
|
| 92 |
+
grouped_cat["count"] = grouped_cat.groupby(["model"])["count"].transform(lambda x: x / x.sum())
|
| 93 |
+
|
| 94 |
+
# Pivot the data for stacking
|
| 95 |
+
pivot_df = grouped_cat.pivot(index='model', columns='tag', values='count').fillna(0)
|
| 96 |
+
# pivot_df = pivot_df.sort_values(by="A", ascending=False)
|
| 97 |
+
# add color vis
|
| 98 |
+
if col == "Size":
|
| 99 |
+
pivot_df[col] = pivot_df.index.map(size_map)
|
| 100 |
+
grouped_cat = grouped_cat.dropna(inplace=True)
|
| 101 |
+
else:
|
| 102 |
+
pivot_df[col] = pivot_df.index.str.split("/").str[0]
|
| 103 |
+
|
| 104 |
+
# Create an interactive scatter plot
|
| 105 |
+
fig = px.scatter(pivot_df, x=x, y=y, hover_name=pivot_df.index, title=f'{x} vs {y}', color=col, color_continuous_scale="agsunset")
|
| 106 |
+
|
| 107 |
+
# Show the plot
|
| 108 |
+
return fig
|
| 109 |
|
| 110 |
# Gradio Interface
|
| 111 |
with gr.Blocks() as demo:
|
|
|
|
| 151 |
)
|
| 152 |
with gr.TabItem("Helpfulness vs Harmfulness"):
|
| 153 |
gr.Markdown("""
|
| 154 |
+
# Helpfulness vs Harmfulness plot
|
| 155 |
|
| 156 |
This scatterplot displays for each model the comparison between the rate of Helpful vs Harmful responses.
|
| 157 |
You can filter the categories and choose the color of the datapoints based on model or size.
|
|
|
|
| 165 |
],
|
| 166 |
gr.Plot(label="forecast", format="png"),
|
| 167 |
)
|
| 168 |
+
with gr.TabItem("Category Selection"):
|
| 169 |
+
category = gr.Radio(choices=list(cats), label="Category Selection")
|
| 170 |
+
subcategory = gr.Dropdown(choices=[], label="Subcategory Selection")
|
| 171 |
+
category.change(fn=rs_change, inputs=category, outputs=subcategory)
|
| 172 |
+
x = gr.Radio(['H', 'A', 'W', 'R'], value="H", label="X-axis Label")
|
| 173 |
+
y = gr.Radio(['H', 'A', 'W', 'R'], value="R", label="Y-axis Label")
|
| 174 |
+
col = gr.Radio(['Organisation', 'Size'], value="Organisation", label="Color Label")
|
| 175 |
+
plot_button = gr.Button("Plot Scatter")
|
| 176 |
+
plot_button.click(fn=plot_scatter_tab4, inputs=[category, subcategory, x, y, col], outputs=gr.Plot())
|
| 177 |
|
| 178 |
# Launch the Gradio app
|
| 179 |
demo.launch(share=True)
|