Spaces:
Sleeping
Sleeping
BioOps Team commited on
Commit ·
9aeb08a
1
Parent(s): 8aafcf0
Consolidate telemetry polling to prevent 429 Rate Limit; remove clear_color from 3D Model
Browse files
bioops/simulation_ui/callbacks.py
CHANGED
|
@@ -146,6 +146,22 @@ def get_telemetry_dataframe() -> pd.DataFrame:
|
|
| 146 |
return pd.DataFrame(rows)
|
| 147 |
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
# ---------------------------------------------------------------------------
|
| 150 |
# Health Score
|
| 151 |
# ---------------------------------------------------------------------------
|
|
|
|
| 146 |
return pd.DataFrame(rows)
|
| 147 |
|
| 148 |
|
| 149 |
+
def get_dashboard_updates() -> tuple[str, pd.DataFrame, pd.DataFrame, pd.DataFrame, pd.DataFrame]:
|
| 150 |
+
"""Retrieve all dashboard telemetry values in a single call.
|
| 151 |
+
|
| 152 |
+
This bundles the requests to prevent hitting the Hugging Face Space
|
| 153 |
+
Rate Limits (429) that occur when individual components poll via `every=`.
|
| 154 |
+
"""
|
| 155 |
+
df = get_telemetry_dataframe()
|
| 156 |
+
return (
|
| 157 |
+
get_state_display(),
|
| 158 |
+
df,
|
| 159 |
+
df,
|
| 160 |
+
df,
|
| 161 |
+
get_audit_log_dataframe(),
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
# ---------------------------------------------------------------------------
|
| 166 |
# Health Score
|
| 167 |
# ---------------------------------------------------------------------------
|
bioops/simulation_ui/dashboard.py
CHANGED
|
@@ -305,14 +305,11 @@ def build_dashboard() -> gr.Blocks:
|
|
| 305 |
# -- Machine State Card ------------------------------------
|
| 306 |
state_display = gr.Markdown(
|
| 307 |
value=callbacks.get_state_display,
|
| 308 |
-
every=telemetry_timer,
|
| 309 |
elem_id="state-display",
|
| 310 |
)
|
| 311 |
|
| 312 |
-
# -- Plots in a compact vertical stack ----------------------
|
| 313 |
vibration_plot = gr.LinePlot(
|
| 314 |
value=callbacks.get_telemetry_dataframe,
|
| 315 |
-
every=telemetry_timer,
|
| 316 |
x="time_s",
|
| 317 |
y="Vibration",
|
| 318 |
title="Vibration Intensity (Real-Time)",
|
|
@@ -324,7 +321,6 @@ def build_dashboard() -> gr.Blocks:
|
|
| 324 |
with gr.Row():
|
| 325 |
rpm_plot = gr.LinePlot(
|
| 326 |
value=callbacks.get_telemetry_dataframe,
|
| 327 |
-
every=telemetry_timer,
|
| 328 |
x="time_s",
|
| 329 |
y="RPM",
|
| 330 |
title="Rotor Speed (RPM)",
|
|
@@ -334,7 +330,6 @@ def build_dashboard() -> gr.Blocks:
|
|
| 334 |
)
|
| 335 |
zscore_plot = gr.LinePlot(
|
| 336 |
value=callbacks.get_telemetry_dataframe,
|
| 337 |
-
every=telemetry_timer,
|
| 338 |
x="time_s",
|
| 339 |
y="Z-Score",
|
| 340 |
title="Anomaly Detection (Z-Score)",
|
|
@@ -349,7 +344,6 @@ def build_dashboard() -> gr.Blocks:
|
|
| 349 |
model_3d = gr.Model3D(
|
| 350 |
value=_resolve_model_path(),
|
| 351 |
label="Centrifuge Rotor Assembly",
|
| 352 |
-
clear_color=(0.05, 0.07, 0.1, 1.0),
|
| 353 |
height=260,
|
| 354 |
)
|
| 355 |
|
|
@@ -360,13 +354,17 @@ def build_dashboard() -> gr.Blocks:
|
|
| 360 |
)
|
| 361 |
audit_table = gr.Dataframe(
|
| 362 |
value=callbacks.get_audit_log_dataframe,
|
| 363 |
-
every=telemetry_timer,
|
| 364 |
label="Audit Log (Latest 30 Records)",
|
| 365 |
elem_id="audit-table",
|
| 366 |
wrap=True,
|
| 367 |
)
|
| 368 |
|
| 369 |
# -- Wire events ----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
send_btn.click(
|
| 371 |
fn=callbacks.chat_respond,
|
| 372 |
inputs=[user_input, chatbot],
|
|
|
|
| 305 |
# -- Machine State Card ------------------------------------
|
| 306 |
state_display = gr.Markdown(
|
| 307 |
value=callbacks.get_state_display,
|
|
|
|
| 308 |
elem_id="state-display",
|
| 309 |
)
|
| 310 |
|
|
|
|
| 311 |
vibration_plot = gr.LinePlot(
|
| 312 |
value=callbacks.get_telemetry_dataframe,
|
|
|
|
| 313 |
x="time_s",
|
| 314 |
y="Vibration",
|
| 315 |
title="Vibration Intensity (Real-Time)",
|
|
|
|
| 321 |
with gr.Row():
|
| 322 |
rpm_plot = gr.LinePlot(
|
| 323 |
value=callbacks.get_telemetry_dataframe,
|
|
|
|
| 324 |
x="time_s",
|
| 325 |
y="RPM",
|
| 326 |
title="Rotor Speed (RPM)",
|
|
|
|
| 330 |
)
|
| 331 |
zscore_plot = gr.LinePlot(
|
| 332 |
value=callbacks.get_telemetry_dataframe,
|
|
|
|
| 333 |
x="time_s",
|
| 334 |
y="Z-Score",
|
| 335 |
title="Anomaly Detection (Z-Score)",
|
|
|
|
| 344 |
model_3d = gr.Model3D(
|
| 345 |
value=_resolve_model_path(),
|
| 346 |
label="Centrifuge Rotor Assembly",
|
|
|
|
| 347 |
height=260,
|
| 348 |
)
|
| 349 |
|
|
|
|
| 354 |
)
|
| 355 |
audit_table = gr.Dataframe(
|
| 356 |
value=callbacks.get_audit_log_dataframe,
|
|
|
|
| 357 |
label="Audit Log (Latest 30 Records)",
|
| 358 |
elem_id="audit-table",
|
| 359 |
wrap=True,
|
| 360 |
)
|
| 361 |
|
| 362 |
# -- Wire events ----------------------------------------------------
|
| 363 |
+
telemetry_timer.tick(
|
| 364 |
+
fn=callbacks.get_dashboard_updates,
|
| 365 |
+
outputs=[state_display, vibration_plot, rpm_plot, zscore_plot, audit_table],
|
| 366 |
+
)
|
| 367 |
+
|
| 368 |
send_btn.click(
|
| 369 |
fn=callbacks.chat_respond,
|
| 370 |
inputs=[user_input, chatbot],
|