Spaces:
Running
Running
github-actions[bot]
commited on
Commit
·
e8e5833
1
Parent(s):
45c78fb
Sync from GitHub: c50110bd1af680c2b2d7056b9e14748dad3003e2
Browse files- demos/compare.py +100 -16
demos/compare.py
CHANGED
@@ -43,16 +43,71 @@ custom_css = """
|
|
43 |
object-fit: contain; /* Scale the content to fit within the element */
|
44 |
}
|
45 |
|
|
|
46 |
.iscc-unit-sim {
|
47 |
-
height: 300px !important;
|
|
|
|
|
|
|
48 |
}
|
49 |
|
50 |
-
|
|
|
51 |
height: 100% !important;
|
|
|
|
|
52 |
}
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
55 |
height: 100% !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
|
58 |
.modebar-btn {
|
@@ -105,6 +160,9 @@ def similarity_plot(sim_data):
|
|
105 |
# Define color for bars based on value
|
106 |
data_df["Color"] = ["#f56169" if x < 0 else "#a6db50" for x in data_df["Value"]]
|
107 |
|
|
|
|
|
|
|
108 |
# Create Plotly Figure
|
109 |
fig = go.Figure()
|
110 |
fig.add_trace(
|
@@ -130,23 +188,40 @@ def similarity_plot(sim_data):
|
|
130 |
)
|
131 |
)
|
132 |
|
133 |
-
# Update layout for
|
134 |
fig.update_layout(
|
135 |
-
height=
|
136 |
-
autosize=
|
137 |
xaxis=dict(
|
138 |
title="",
|
139 |
tickformat=",.0%",
|
140 |
showticklabels=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
),
|
142 |
yaxis=dict(
|
143 |
title="",
|
144 |
showticklabels=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
),
|
146 |
paper_bgcolor="rgba(0,0,0,0)",
|
147 |
plot_bgcolor="rgba(0,0,0,0)",
|
148 |
showlegend=False,
|
149 |
-
margin=dict(l=
|
|
|
|
|
150 |
modebar_remove=[
|
151 |
"toImage",
|
152 |
"zoom",
|
@@ -156,17 +231,26 @@ def similarity_plot(sim_data):
|
|
156 |
"autoScale",
|
157 |
"resetScale",
|
158 |
],
|
|
|
|
|
159 |
)
|
160 |
|
161 |
-
#
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
return fig
|
172 |
|
|
|
43 |
object-fit: contain; /* Scale the content to fit within the element */
|
44 |
}
|
45 |
|
46 |
+
/* Comprehensive fix for ISCC-UNIT Similarities panel */
|
47 |
.iscc-unit-sim {
|
48 |
+
height: 300px !important;
|
49 |
+
min-height: 300px !important;
|
50 |
+
display: block !important;
|
51 |
+
position: relative !important;
|
52 |
}
|
53 |
|
54 |
+
/* Target Gradio's container structure */
|
55 |
+
.iscc-unit-sim > div {
|
56 |
height: 100% !important;
|
57 |
+
min-height: 280px !important;
|
58 |
+
position: relative !important;
|
59 |
}
|
60 |
|
61 |
+
/* Target plotly containers with multiple selectors for robustness */
|
62 |
+
.iscc-unit-sim .plot-container,
|
63 |
+
.iscc-unit-sim .js-plotly-plot,
|
64 |
+
.iscc-unit-sim .plotly,
|
65 |
+
.iscc-unit-sim .plotly-graph-div,
|
66 |
+
.iscc-unit-sim > div > div {
|
67 |
height: 100% !important;
|
68 |
+
min-height: 280px !important;
|
69 |
+
position: relative !important;
|
70 |
+
}
|
71 |
+
|
72 |
+
/* Ensure SVG fills container */
|
73 |
+
.iscc-unit-sim svg,
|
74 |
+
.iscc-unit-sim .main-svg {
|
75 |
+
height: 100% !important;
|
76 |
+
min-height: 280px !important;
|
77 |
+
}
|
78 |
+
|
79 |
+
/* Force plot container to expand in HF Spaces */
|
80 |
+
.iscc-unit-sim [class*="svelte"] {
|
81 |
+
height: 100% !important;
|
82 |
+
min-height: 280px !important;
|
83 |
+
}
|
84 |
+
|
85 |
+
/* Additional targeting for Gradio 5 structure */
|
86 |
+
.iscc-unit-sim .contain {
|
87 |
+
height: 100% !important;
|
88 |
+
min-height: 280px !important;
|
89 |
+
}
|
90 |
+
|
91 |
+
/* Plotly specific fixes for HF Spaces */
|
92 |
+
.iscc-unit-sim .plotly-notifier {
|
93 |
+
visibility: hidden !important;
|
94 |
+
}
|
95 |
+
|
96 |
+
/* Force Plotly graph to fill container */
|
97 |
+
.iscc-unit-sim .svg-container {
|
98 |
+
height: 100% !important;
|
99 |
+
position: relative !important;
|
100 |
+
}
|
101 |
+
|
102 |
+
.iscc-unit-sim .plot-container.plotly {
|
103 |
+
height: 100% !important;
|
104 |
+
width: 100% !important;
|
105 |
+
}
|
106 |
+
|
107 |
+
/* Override any inline styles */
|
108 |
+
.iscc-unit-sim div[style*="height"] {
|
109 |
+
height: 100% !important;
|
110 |
+
min-height: 280px !important;
|
111 |
}
|
112 |
|
113 |
.modebar-btn {
|
|
|
160 |
# Define color for bars based on value
|
161 |
data_df["Color"] = ["#f56169" if x < 0 else "#a6db50" for x in data_df["Value"]]
|
162 |
|
163 |
+
# Calculate appropriate bar thickness
|
164 |
+
num_categories = len(data_df)
|
165 |
+
|
166 |
# Create Plotly Figure
|
167 |
fig = go.Figure()
|
168 |
fig.add_trace(
|
|
|
188 |
)
|
189 |
)
|
190 |
|
191 |
+
# Update layout for HF Spaces compatibility
|
192 |
fig.update_layout(
|
193 |
+
height=295, # Maximize within container while leaving small buffer
|
194 |
+
autosize=False,
|
195 |
xaxis=dict(
|
196 |
title="",
|
197 |
tickformat=",.0%",
|
198 |
showticklabels=False,
|
199 |
+
fixedrange=True,
|
200 |
+
range=[-1.1, 1.1],
|
201 |
+
showline=False,
|
202 |
+
zeroline=False,
|
203 |
+
showgrid=False,
|
204 |
+
gridcolor="rgba(0,0,0,0)",
|
205 |
),
|
206 |
yaxis=dict(
|
207 |
title="",
|
208 |
showticklabels=False,
|
209 |
+
fixedrange=True,
|
210 |
+
showline=False,
|
211 |
+
zeroline=False,
|
212 |
+
showgrid=False,
|
213 |
+
gridcolor="rgba(0,0,0,0)",
|
214 |
+
categoryorder="array",
|
215 |
+
categoryarray=data_df["Category"].tolist(),
|
216 |
+
# Explicitly set y-axis range to distribute bars evenly
|
217 |
+
range=[-0.5, num_categories - 0.5],
|
218 |
),
|
219 |
paper_bgcolor="rgba(0,0,0,0)",
|
220 |
plot_bgcolor="rgba(0,0,0,0)",
|
221 |
showlegend=False,
|
222 |
+
margin=dict(l=2, r=2, t=2, b=2), # Minimal margins
|
223 |
+
bargap=0.2, # Consistent spacing between bars
|
224 |
+
# Remove all modebar buttons
|
225 |
modebar_remove=[
|
226 |
"toImage",
|
227 |
"zoom",
|
|
|
231 |
"autoScale",
|
232 |
"resetScale",
|
233 |
],
|
234 |
+
# Ensure plot fills container
|
235 |
+
template="none",
|
236 |
)
|
237 |
|
238 |
+
# Configure responsive behavior
|
239 |
+
config = {
|
240 |
+
"displayModeBar": False,
|
241 |
+
"responsive": True,
|
242 |
+
"fillFrame": True,
|
243 |
+
"frameMargins": 0,
|
244 |
+
"displaylogo": False,
|
245 |
+
"modeBarButtonsToRemove": ["toImage"],
|
246 |
+
"toImageButtonOptions": {
|
247 |
+
"height": 295,
|
248 |
+
"width": None,
|
249 |
+
},
|
250 |
+
}
|
251 |
+
|
252 |
+
# Set the config on the figure object
|
253 |
+
fig._config = config
|
254 |
|
255 |
return fig
|
256 |
|