an0nymous commited on
Commit
cbac2ba
·
verified ·
1 Parent(s): 7c56b57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -3
app.py CHANGED
@@ -1,5 +1,8 @@
1
  import gradio as gr
2
  import pandas as pd
 
 
 
3
 
4
  # Load the CSV file into a DataFrame
5
  df = pd.read_csv("sorted_results.csv") # Replace with the path to your CSV file
@@ -8,6 +11,38 @@ df = pd.read_csv("sorted_results.csv") # Replace with the path to your CSV file
8
  def display_table():
9
  return df
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # Gradio Interface
12
  with gr.Blocks() as demo:
13
  with gr.Tabs(elem_classes="tab-buttons") as tabs:
@@ -28,9 +63,16 @@ with gr.Blocks() as demo:
28
  """)
29
  gr.DataFrame(value=df, label="Benchmark Table", interactive=False) # Display the DataFrame
30
  with gr.TabItem("Tab2"):
31
- gr.Markdown("""
32
- tab2
33
- """)
 
 
 
 
 
 
 
34
 
35
  # Launch the Gradio app
36
  demo.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+ from tqdm.auto import tqdm
6
 
7
  # Load the CSV file into a DataFrame
8
  df = pd.read_csv("sorted_results.csv") # Replace with the path to your CSV file
 
11
  def display_table():
12
  return df
13
 
14
+ # Other tabs preprocessing
15
+ size_df = pd.read_excel("../models.xlsx", sheet_name="Selected Models")
16
+ size_df["Size"] = size_df["Size"].str.replace("b", "").astype(float)
17
+ size_map = size_df.set_index("id")["Size"].to_dict()
18
+ raw_data = pd.read_csv("./tagged_data.csv")
19
+
20
+ def plot_scatter(cat, x, y, col):
21
+ if cat != "All":
22
+ data = raw_data[raw_data["Category"] == cat]
23
+ else:
24
+ data = raw_data
25
+ # Group and normalize the data
26
+ grouped_cat = data.groupby(["model", "tag"]).size().reset_index(name="count").sort_values(by="count", ascending=False)
27
+ grouped_cat["count"] = grouped_cat.groupby(["model"])["count"].transform(lambda x: x / x.sum())
28
+
29
+ # Pivot the data for stacking
30
+ pivot_df = grouped_cat.pivot(index='model', columns='tag', values='count').fillna(0)
31
+ # pivot_df = pivot_df.sort_values(by="A", ascending=False)
32
+ # add color vis
33
+ if col == "Size":
34
+ pivot_df[col] = pivot_df.index.map(size_map)
35
+ grouped_cat = grouped_cat.dropna(inplace=True)
36
+ else:
37
+ pivot_df[col] = pivot_df.index.str.split("/").str[0]
38
+
39
+ # Create an interactive scatter plot
40
+ 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")
41
+
42
+ # Show the plot
43
+ return fig
44
+
45
+
46
  # Gradio Interface
47
  with gr.Blocks() as demo:
48
  with gr.Tabs(elem_classes="tab-buttons") as tabs:
 
63
  """)
64
  gr.DataFrame(value=df, label="Benchmark Table", interactive=False) # Display the DataFrame
65
  with gr.TabItem("Tab2"):
66
+ gr.Interface(
67
+ plot_scatter,
68
+ [
69
+ gr.Radio(["Copyright", "Malware", "Unfair/dangerous", "All"], value="All", label="Category Selection"),
70
+ gr.Radio(['H', 'A', 'W', 'R'], value="H", label="X-axis Label"),
71
+ gr.Radio(['H', 'A', 'W', 'R'], value="R", label="Y-axis Label"),
72
+ gr.Radio(['Organisation', 'Size'], value="Organisation", label="Color Label"),
73
+ ],
74
+ gr.Plot(label="plot", format="png",), allow_flagging="never",
75
+ )
76
 
77
  # Launch the Gradio app
78
  demo.launch()