Spaces:
Running
Running
Commit
·
574aa10
1
Parent(s):
2ee3fae
Frame for 2 Models
Browse files
app.py
CHANGED
@@ -4,44 +4,7 @@ from bokeh.plotting import figure
|
|
4 |
from bokeh.models import ColumnDataSource
|
5 |
from bokeh.palettes import Category10
|
6 |
|
7 |
-
|
8 |
-
st.markdown(
|
9 |
-
"""
|
10 |
-
<style>
|
11 |
-
.main-title {
|
12 |
-
font-size: 50px;
|
13 |
-
color: #4CAF50;
|
14 |
-
text-align: center;
|
15 |
-
}
|
16 |
-
.sub-title {
|
17 |
-
font-size: 30px;
|
18 |
-
color: #555;
|
19 |
-
}
|
20 |
-
.custom-text {
|
21 |
-
font-size: 18px;
|
22 |
-
line-height: 1.5;
|
23 |
-
}
|
24 |
-
</style>
|
25 |
-
""",
|
26 |
-
unsafe_allow_html=True
|
27 |
-
)
|
28 |
-
|
29 |
-
st.markdown('<h1 class="main-title">Merit Secret Embeddings 🎒📃🏆</h1>', unsafe_allow_html=True)
|
30 |
-
st.markdown('<h2 class="sub-title">Donut</h2>', unsafe_allow_html=True)
|
31 |
-
st.markdown(
|
32 |
-
"""
|
33 |
-
<p class="custom-text">
|
34 |
-
Explore how Donut perceives real data.
|
35 |
-
</p>
|
36 |
-
""",
|
37 |
-
unsafe_allow_html=True
|
38 |
-
)
|
39 |
-
|
40 |
-
# Cargar el CSV
|
41 |
-
df = pd.read_csv("data/data.csv")
|
42 |
-
unique_labels = df['label'].unique().tolist()
|
43 |
-
|
44 |
-
# Definir tooltips para la imagen y la etiqueta
|
45 |
TOOLTIPS = """
|
46 |
<div>
|
47 |
<div>
|
@@ -53,17 +16,14 @@ TOOLTIPS = """
|
|
53 |
</div>
|
54 |
"""
|
55 |
|
56 |
-
# Crear contenedor para el gráfico
|
57 |
-
plot_placeholder = st.empty()
|
58 |
|
59 |
-
|
60 |
-
def render_plot(selected_labels):
|
61 |
if not selected_labels:
|
62 |
st.write("No data to display. Please select at least one subset.")
|
63 |
return
|
64 |
|
65 |
filtered_data = df[df['label'].isin(selected_labels)]
|
66 |
-
p = figure(width=400, height=400, tooltips=TOOLTIPS
|
67 |
|
68 |
num_labels = len(selected_labels)
|
69 |
# Ajuste de la paleta
|
@@ -74,7 +34,7 @@ def render_plot(selected_labels):
|
|
74 |
else:
|
75 |
palette = Category10[10][:num_labels]
|
76 |
|
77 |
-
# Graficar cada label por separado
|
78 |
for label, color in zip(selected_labels, palette):
|
79 |
subset = filtered_data[filtered_data['label'] == label]
|
80 |
source = ColumnDataSource(data=dict(
|
@@ -91,15 +51,94 @@ def render_plot(selected_labels):
|
|
91 |
|
92 |
plot_placeholder.bokeh_chart(p)
|
93 |
|
94 |
-
# Mostrar inicialmente el gráfico con todas las etiquetas
|
95 |
-
render_plot(unique_labels)
|
96 |
|
97 |
-
|
98 |
-
selected_labels
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
-
#
|
105 |
-
|
|
|
4 |
from bokeh.models import ColumnDataSource
|
5 |
from bokeh.palettes import Category10
|
6 |
|
7 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
TOOLTIPS = """
|
9 |
<div>
|
10 |
<div>
|
|
|
16 |
</div>
|
17 |
"""
|
18 |
|
|
|
|
|
19 |
|
20 |
+
def render_plot(selected_labels, df, plot_placeholder):
|
|
|
21 |
if not selected_labels:
|
22 |
st.write("No data to display. Please select at least one subset.")
|
23 |
return
|
24 |
|
25 |
filtered_data = df[df['label'].isin(selected_labels)]
|
26 |
+
p = figure(width=400, height=400, tooltips=TOOLTIPS)
|
27 |
|
28 |
num_labels = len(selected_labels)
|
29 |
# Ajuste de la paleta
|
|
|
34 |
else:
|
35 |
palette = Category10[10][:num_labels]
|
36 |
|
37 |
+
# Graficar cada label por separado
|
38 |
for label, color in zip(selected_labels, palette):
|
39 |
subset = filtered_data[filtered_data['label'] == label]
|
40 |
source = ColumnDataSource(data=dict(
|
|
|
51 |
|
52 |
plot_placeholder.bokeh_chart(p)
|
53 |
|
|
|
|
|
54 |
|
55 |
+
def render_plot_donut(selected_labels):
|
56 |
+
render_plot(selected_labels, df, plot_placeholder)
|
57 |
+
|
58 |
+
|
59 |
+
def render_plot_idefics2(selected_labels):
|
60 |
+
render_plot(selected_labels, df2, plot_placeholder2)
|
61 |
+
|
62 |
+
|
63 |
+
def config_style():
|
64 |
+
|
65 |
+
st.markdown(
|
66 |
+
"""
|
67 |
+
<style>
|
68 |
+
.main-title {
|
69 |
+
font-size: 50px;
|
70 |
+
color: #4CAF50;
|
71 |
+
text-align: center;
|
72 |
+
}
|
73 |
+
.sub-title {
|
74 |
+
font-size: 30px;
|
75 |
+
color: #555;
|
76 |
+
}
|
77 |
+
.custom-text {
|
78 |
+
font-size: 18px;
|
79 |
+
line-height: 1.5;
|
80 |
+
}
|
81 |
+
</style>
|
82 |
+
""",
|
83 |
+
unsafe_allow_html=True
|
84 |
+
)
|
85 |
+
|
86 |
+
st.markdown('<h1 class="main-title">Merit Secret Embeddings 🎒📃🏆</h1>', unsafe_allow_html=True)
|
87 |
+
st.markdown('<h2 class="sub-title">Donut</h2>', unsafe_allow_html=True)
|
88 |
+
st.markdown(
|
89 |
+
"""
|
90 |
+
<p class="custom-text">
|
91 |
+
Explore how Donut perceives real data.
|
92 |
+
</p>
|
93 |
+
""",
|
94 |
+
unsafe_allow_html=True
|
95 |
+
)
|
96 |
+
|
97 |
+
if __name__ == "__main__":
|
98 |
+
|
99 |
+
config_style()
|
100 |
+
|
101 |
+
# --- Primer gráfico: datos de data.csv ---
|
102 |
+
df = pd.read_csv("data/data_donut_pca.csv")
|
103 |
+
unique_labels = df['label'].unique().tolist()
|
104 |
+
|
105 |
+
# Contenedor para el primer gráfico
|
106 |
+
plot_placeholder = st.empty()
|
107 |
+
|
108 |
+
# Mostrar inicialmente el primer gráfico con todas las etiquetas
|
109 |
+
render_plot_donut(unique_labels)
|
110 |
+
|
111 |
+
# Desplegable (multiselect) para el primer gráfico
|
112 |
+
selected_labels = st.multiselect(
|
113 |
+
"",
|
114 |
+
options=unique_labels,
|
115 |
+
default=unique_labels
|
116 |
+
)
|
117 |
+
|
118 |
+
# Actualizar gráfico al cambiar la selección
|
119 |
+
render_plot_donut(selected_labels)
|
120 |
+
|
121 |
+
# --- Segundo gráfico: datos de data_idefics2.csv ---
|
122 |
+
st.markdown('<h2 class="sub-title">Idefics2</h2>', unsafe_allow_html=True)
|
123 |
+
|
124 |
+
df2 = pd.read_csv("data/data_donut_tnse.csv")
|
125 |
+
unique_labels2 = df2['label'].unique().tolist()
|
126 |
+
|
127 |
+
|
128 |
+
# Contenedor para el segundo gráfico
|
129 |
+
plot_placeholder2 = st.empty()
|
130 |
+
|
131 |
+
|
132 |
+
# Mostrar inicialmente el segundo gráfico con todas las etiquetas
|
133 |
+
render_plot_idefics2(unique_labels2)
|
134 |
+
|
135 |
+
# Desplegable (multiselect) para el segundo gráfico
|
136 |
+
selected_labels2 = st.multiselect(
|
137 |
+
"",
|
138 |
+
options=unique_labels2,
|
139 |
+
default=unique_labels2,
|
140 |
+
key="idefics2"
|
141 |
+
)
|
142 |
|
143 |
+
# Actualizar el gráfico del segundo conjunto de datos al cambiar la selección
|
144 |
+
render_plot_idefics2(selected_labels2)
|