Dyra1204 commited on
Commit
e5590cb
·
verified ·
1 Parent(s): 4e0fe47

Upload main.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. main.py +35 -3
main.py CHANGED
@@ -258,6 +258,7 @@ class BiasGuardDashboard:
258
 
259
  fig.update_layout(
260
  height=350,
 
261
  margin=dict(l=20, r=20, t=80, b=20),
262
  paper_bgcolor="white",
263
  plot_bgcolor="white",
@@ -287,7 +288,12 @@ class BiasGuardDashboard:
287
  showarrow=False,
288
  font=dict(size=18, color="#64748b"),
289
  )
290
- fig.update_layout(height=400, paper_bgcolor="white", plot_bgcolor="white")
 
 
 
 
 
291
  return fig
292
 
293
  words = [word for word, score in shap_scores[:8]]
@@ -325,6 +331,7 @@ class BiasGuardDashboard:
325
  ),
326
  yaxis=dict(title="", showgrid=False),
327
  height=400,
 
328
  showlegend=False,
329
  plot_bgcolor="white",
330
  paper_bgcolor="white",
@@ -1247,6 +1254,31 @@ class BiasGuardDashboard:
1247
  0% { transform: rotate(0deg); }
1248
  100% { transform: rotate(360deg); }
1249
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1250
  """
1251
 
1252
  force_light_js = """
@@ -1459,7 +1491,7 @@ class BiasGuardDashboard:
1459
  # Summary and Bias Meter Row
1460
  with gr.Row(equal_height=False):
1461
  with gr.Column(scale=1):
1462
- bias_meter = gr.Plot(label="")
1463
 
1464
  with gr.Column(scale=2):
1465
  summary_display = gr.HTML(label="")
@@ -1486,7 +1518,7 @@ class BiasGuardDashboard:
1486
  )
1487
  with gr.Row():
1488
  with gr.Column():
1489
- shap_chart = gr.Plot(label="")
1490
 
1491
  gr.HTML(
1492
  "<div style='margin: 24px 0 12px 0;'><h4 style='font-size: 18px; font-weight: 700; color: #334155; margin: 0;'>🎯 Key Biased Terms</h4></div>"
 
258
 
259
  fig.update_layout(
260
  height=350,
261
+ autosize=False,
262
  margin=dict(l=20, r=20, t=80, b=20),
263
  paper_bgcolor="white",
264
  plot_bgcolor="white",
 
288
  showarrow=False,
289
  font=dict(size=18, color="#64748b"),
290
  )
291
+ fig.update_layout(
292
+ height=400,
293
+ autosize=False,
294
+ paper_bgcolor="white",
295
+ plot_bgcolor="white",
296
+ )
297
  return fig
298
 
299
  words = [word for word, score in shap_scores[:8]]
 
331
  ),
332
  yaxis=dict(title="", showgrid=False),
333
  height=400,
334
+ autosize=False,
335
  showlegend=False,
336
  plot_bgcolor="white",
337
  paper_bgcolor="white",
 
1254
  0% { transform: rotate(0deg); }
1255
  100% { transform: rotate(360deg); }
1256
  }
1257
+
1258
+ /*
1259
+ Plotly/Gradio: prevent resize feedback loops that can cause plots to
1260
+ continuously grow in height (observed in Spaces).
1261
+ We clamp the plot containers to the intended fixed heights.
1262
+ */
1263
+ #bias-meter-plot {
1264
+ height: 350px !important;
1265
+ max-height: 350px !important;
1266
+ overflow: hidden !important;
1267
+ }
1268
+
1269
+ #shap-chart-plot {
1270
+ height: 400px !important;
1271
+ max-height: 400px !important;
1272
+ overflow: hidden !important;
1273
+ }
1274
+
1275
+ #bias-meter-plot .js-plotly-plot,
1276
+ #bias-meter-plot .plotly-graph-div,
1277
+ #shap-chart-plot .js-plotly-plot,
1278
+ #shap-chart-plot .plotly-graph-div {
1279
+ height: 100% !important;
1280
+ max-height: 100% !important;
1281
+ }
1282
  """
1283
 
1284
  force_light_js = """
 
1491
  # Summary and Bias Meter Row
1492
  with gr.Row(equal_height=False):
1493
  with gr.Column(scale=1):
1494
+ bias_meter = gr.Plot(label="", elem_id="bias-meter-plot")
1495
 
1496
  with gr.Column(scale=2):
1497
  summary_display = gr.HTML(label="")
 
1518
  )
1519
  with gr.Row():
1520
  with gr.Column():
1521
+ shap_chart = gr.Plot(label="", elem_id="shap-chart-plot")
1522
 
1523
  gr.HTML(
1524
  "<div style='margin: 24px 0 12px 0;'><h4 style='font-size: 18px; font-weight: 700; color: #334155; margin: 0;'>🎯 Key Biased Terms</h4></div>"