Spaces:
Runtime error
Runtime error
sherzod-hakimov
commited on
Commit
•
b345ff4
1
Parent(s):
62fad80
show legends
Browse files- app.py +20 -4
- src/plot_utils.py +9 -4
app.py
CHANGED
@@ -98,6 +98,15 @@ with main_app:
|
|
98 |
interactive=True,
|
99 |
)
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
with gr.Row():
|
102 |
dummy_plot_df = gr.DataFrame(
|
103 |
value=plot_df,
|
@@ -111,28 +120,35 @@ with main_app:
|
|
111 |
|
112 |
open_models_selection.change(
|
113 |
compare_plots,
|
114 |
-
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names],
|
115 |
plot_output,
|
116 |
queue=True
|
117 |
)
|
118 |
|
119 |
closed_models_selection.change(
|
120 |
compare_plots,
|
121 |
-
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names],
|
122 |
plot_output,
|
123 |
queue=True
|
124 |
)
|
125 |
|
126 |
show_all.change(
|
127 |
compare_plots,
|
128 |
-
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names],
|
129 |
plot_output,
|
130 |
queue=True
|
131 |
)
|
132 |
|
133 |
show_names.change(
|
134 |
compare_plots,
|
135 |
-
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
plot_output,
|
137 |
queue=True
|
138 |
)
|
|
|
98 |
interactive=True,
|
99 |
)
|
100 |
|
101 |
+
with gr.Column():
|
102 |
+
show_legend = gr.CheckboxGroup(
|
103 |
+
["Show Legend"],
|
104 |
+
label ="Show legend on the plot 💡",
|
105 |
+
value=[],
|
106 |
+
elem_id="value-select-5",
|
107 |
+
interactive=True,
|
108 |
+
)
|
109 |
+
|
110 |
with gr.Row():
|
111 |
dummy_plot_df = gr.DataFrame(
|
112 |
value=plot_df,
|
|
|
120 |
|
121 |
open_models_selection.change(
|
122 |
compare_plots,
|
123 |
+
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names, show_legend],
|
124 |
plot_output,
|
125 |
queue=True
|
126 |
)
|
127 |
|
128 |
closed_models_selection.change(
|
129 |
compare_plots,
|
130 |
+
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names, show_legend],
|
131 |
plot_output,
|
132 |
queue=True
|
133 |
)
|
134 |
|
135 |
show_all.change(
|
136 |
compare_plots,
|
137 |
+
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names, show_legend],
|
138 |
plot_output,
|
139 |
queue=True
|
140 |
)
|
141 |
|
142 |
show_names.change(
|
143 |
compare_plots,
|
144 |
+
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names, show_legend],
|
145 |
+
plot_output,
|
146 |
+
queue=True
|
147 |
+
)
|
148 |
+
|
149 |
+
show_legend.change(
|
150 |
+
compare_plots,
|
151 |
+
[dummy_plot_df, open_models_selection, closed_models_selection, show_all, show_names, show_legend],
|
152 |
plot_output,
|
153 |
queue=True
|
154 |
)
|
src/plot_utils.py
CHANGED
@@ -3,7 +3,7 @@ import plotly.express as px
|
|
3 |
|
4 |
from src.assets.text_content import SHORT_NAMES
|
5 |
|
6 |
-
def plotly_plot(df:pd.DataFrame, LIST:list, ALL:list, NAMES:list):
|
7 |
'''
|
8 |
Takes in a list of models for a plotly plot
|
9 |
Args:
|
@@ -11,6 +11,7 @@ def plotly_plot(df:pd.DataFrame, LIST:list, ALL:list, NAMES:list):
|
|
11 |
LIST: List of models to plot
|
12 |
ALL: Either [] or ["Show All Models"] - toggle view to plot all models
|
13 |
NAMES: Either [] or ["Show Names"] - toggle view to show model names on plot
|
|
|
14 |
Returns:
|
15 |
Fig: plotly figure
|
16 |
'''
|
@@ -38,6 +39,9 @@ def plotly_plot(df:pd.DataFrame, LIST:list, ALL:list, NAMES:list):
|
|
38 |
color_discrete_map={"category1": "blue", "category2": "red"},
|
39 |
hover_name=list_columns[0], template="plotly_white")
|
40 |
|
|
|
|
|
|
|
41 |
fig.update_layout(
|
42 |
xaxis_title='% Played',
|
43 |
yaxis_title='Quality Score',
|
@@ -52,7 +56,7 @@ def plotly_plot(df:pd.DataFrame, LIST:list, ALL:list, NAMES:list):
|
|
52 |
|
53 |
|
54 |
# ['Model', 'Clemscore', 'All(Played)', 'All(Quality Score)']
|
55 |
-
def compare_plots(df: pd.DataFrame, LIST1: list, LIST2: list, ALL:list, NAMES:list):
|
56 |
'''
|
57 |
Quality Score v/s % Played plot by selecting models
|
58 |
Args:
|
@@ -60,14 +64,15 @@ def compare_plots(df: pd.DataFrame, LIST1: list, LIST2: list, ALL:list, NAMES:li
|
|
60 |
LIST1: The list of open source models to show in the plot, updated from frontend
|
61 |
LIST2: The list of commercial models to show in the plot, updated from frontend
|
62 |
ALL: Either [] or ["Show All Models"] - toggle view to plot all models
|
63 |
-
NAMES: Either [] or ["Show Names"] - toggle view to show model names on plot
|
|
|
64 |
Returns:
|
65 |
fig: The plot
|
66 |
'''
|
67 |
|
68 |
# Combine lists for Open source and commercial models
|
69 |
LIST = LIST1 + LIST2
|
70 |
-
fig = plotly_plot(df, LIST, ALL, NAMES)
|
71 |
|
72 |
return fig
|
73 |
|
|
|
3 |
|
4 |
from src.assets.text_content import SHORT_NAMES
|
5 |
|
6 |
+
def plotly_plot(df:pd.DataFrame, LIST:list, ALL:list, NAMES:list, LEGEND:list):
|
7 |
'''
|
8 |
Takes in a list of models for a plotly plot
|
9 |
Args:
|
|
|
11 |
LIST: List of models to plot
|
12 |
ALL: Either [] or ["Show All Models"] - toggle view to plot all models
|
13 |
NAMES: Either [] or ["Show Names"] - toggle view to show model names on plot
|
14 |
+
LEGEND: Either [] or ["Show Legend"] - toggle view to show legend on plot
|
15 |
Returns:
|
16 |
Fig: plotly figure
|
17 |
'''
|
|
|
39 |
color_discrete_map={"category1": "blue", "category2": "red"},
|
40 |
hover_name=list_columns[0], template="plotly_white")
|
41 |
|
42 |
+
if not LEGEND:
|
43 |
+
fig.update_layout(showlegend=False)
|
44 |
+
|
45 |
fig.update_layout(
|
46 |
xaxis_title='% Played',
|
47 |
yaxis_title='Quality Score',
|
|
|
56 |
|
57 |
|
58 |
# ['Model', 'Clemscore', 'All(Played)', 'All(Quality Score)']
|
59 |
+
def compare_plots(df: pd.DataFrame, LIST1: list, LIST2: list, ALL:list, NAMES:list, LEGEND: list):
|
60 |
'''
|
61 |
Quality Score v/s % Played plot by selecting models
|
62 |
Args:
|
|
|
64 |
LIST1: The list of open source models to show in the plot, updated from frontend
|
65 |
LIST2: The list of commercial models to show in the plot, updated from frontend
|
66 |
ALL: Either [] or ["Show All Models"] - toggle view to plot all models
|
67 |
+
NAMES: Either [] or ["Show Names"] - toggle view to show model names on plot
|
68 |
+
LEGEND: Either [] or ["Show Legend"] - toggle view to show legend on plot
|
69 |
Returns:
|
70 |
fig: The plot
|
71 |
'''
|
72 |
|
73 |
# Combine lists for Open source and commercial models
|
74 |
LIST = LIST1 + LIST2
|
75 |
+
fig = plotly_plot(df, LIST, ALL, NAMES, LEGEND)
|
76 |
|
77 |
return fig
|
78 |
|