Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -106,6 +106,33 @@ def plot_scatter_tab4(cat, subcat, x, y, col):
|
|
106 |
# Show the plot
|
107 |
return fig
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Gradio Interface
|
110 |
with gr.Blocks() as demo:
|
111 |
with gr.Tabs(elem_classes="tab-buttons") as tabs:
|
@@ -179,6 +206,18 @@ with gr.Blocks() as demo:
|
|
179 |
col = gr.Radio(['Organisation', 'Size'], value="Organisation", label="Color Label")
|
180 |
plot_button = gr.Button("Plot Scatter")
|
181 |
plot_button.click(fn=plot_scatter_tab4, inputs=[category, subcategory, x, y, col], outputs=gr.Plot())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
# Launch the Gradio app
|
184 |
demo.launch(share=True)
|
|
|
106 |
# Show the plot
|
107 |
return fig
|
108 |
|
109 |
+
# Tab 5
|
110 |
+
def plot_scatter_tab5(cat, x, y, z, col):
|
111 |
+
if cat != "All":
|
112 |
+
data = raw_data[raw_data["Category"] == cat]
|
113 |
+
else:
|
114 |
+
data = raw_data
|
115 |
+
# Group and normalize the data
|
116 |
+
grouped_cat = data.groupby(["model", "tag"]).size().reset_index(name="count").sort_values(by="count", ascending=False)
|
117 |
+
grouped_cat["count"] = grouped_cat.groupby(["model"])["count"].transform(lambda x: x / x.sum())
|
118 |
+
|
119 |
+
# Pivot the data for stacking
|
120 |
+
pivot_df = grouped_cat.pivot(index='model', columns='tag', values='count').fillna(0)
|
121 |
+
# pivot_df = pivot_df.sort_values(by="A", ascending=False)
|
122 |
+
# add color vis
|
123 |
+
if col == "Size":
|
124 |
+
pivot_df[col] = pivot_df.index.map(size_map)
|
125 |
+
else:
|
126 |
+
pivot_df[col] = pivot_df.index.str.split("/").str[0]
|
127 |
+
|
128 |
+
# Create an interactive scatter plot
|
129 |
+
# 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")
|
130 |
+
# fig = plt.figure()
|
131 |
+
|
132 |
+
# plot = px.scatter_3d(pivot_df[x], pivot_df[y], pivot_df[z]) #c=pivot_df[col], cmap='viridis')
|
133 |
+
fig = px.scatter_3d(pivot_df, x=x, y=y,z=z, hover_name=pivot_df.index, title=f'{x} vs {y} vs {z}', color=col, color_continuous_scale="agsunset")
|
134 |
+
return fig
|
135 |
+
|
136 |
# Gradio Interface
|
137 |
with gr.Blocks() as demo:
|
138 |
with gr.Tabs(elem_classes="tab-buttons") as tabs:
|
|
|
206 |
col = gr.Radio(['Organisation', 'Size'], value="Organisation", label="Color Label")
|
207 |
plot_button = gr.Button("Plot Scatter")
|
208 |
plot_button.click(fn=plot_scatter_tab4, inputs=[category, subcategory, x, y, col], outputs=gr.Plot())
|
209 |
+
with gr.TabItem("3D Visualisation"):
|
210 |
+
gr.Interface(
|
211 |
+
plot_scatter,
|
212 |
+
[
|
213 |
+
gr.Radio(["Copyright", "Malware", "Unfair/dangerous", "All"], value="All", label="Category Selection"),
|
214 |
+
gr.Radio(['H', 'A', 'W', 'R'], value="H", label="X-axis Label"),
|
215 |
+
gr.Radio(['H', 'A', 'W', 'R'], value="R", label="Y-axis Label"),
|
216 |
+
gr.Radio(['H', 'A', 'W', 'R'], value="A", label="Z-axis Label"),
|
217 |
+
gr.Radio(['Organisation', 'Size'], value="Organisation", label="Color Label"),
|
218 |
+
],
|
219 |
+
gr.Plot(label="plot", format="png",), allow_flagging="never",
|
220 |
+
)
|
221 |
|
222 |
# Launch the Gradio app
|
223 |
demo.launch(share=True)
|