Spaces:
Running
Running
Upload app_space.py
Browse files- app_space.py +20 -12
app_space.py
CHANGED
|
@@ -9,6 +9,7 @@ import gradio as gr
|
|
| 9 |
import matplotlib.pyplot as plt
|
| 10 |
import numpy as np
|
| 11 |
import matplotlib.image as mpimg
|
|
|
|
| 12 |
|
| 13 |
# Ensure local package is importable when running in Hugging Face Spaces
|
| 14 |
ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
@@ -75,18 +76,21 @@ def plot_gating(signal_text: str):
|
|
| 75 |
buf.seek(0)
|
| 76 |
np_img = mpimg.imread(buf)
|
| 77 |
windows = meta.get("windows", [])
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
summary = f"Windows kept: {meta.get('selected_windows',0)}/{meta.get('total_windows',0)} • ratio={meta.get('ratio',1):.2f}"
|
| 89 |
-
return np_img, summary,
|
| 90 |
|
| 91 |
|
| 92 |
# Demo signals with more structure so gating can skip/keep meaningfully
|
|
@@ -117,7 +121,11 @@ with gr.Blocks(title="Sundew ECG Demo") as demo:
|
|
| 117 |
)
|
| 118 |
img = gr.Image(type="numpy", label="Raw vs Gated")
|
| 119 |
summary_box = gr.Textbox(label="Gating summary")
|
| 120 |
-
table = gr.Dataframe(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
btn2 = gr.Button("Show gating")
|
| 122 |
btn2.click(plot_gating, inputs=inp2, outputs=[img, summary_box, table])
|
| 123 |
with gr.Tab("Demos"):
|
|
|
|
| 9 |
import matplotlib.pyplot as plt
|
| 10 |
import numpy as np
|
| 11 |
import matplotlib.image as mpimg
|
| 12 |
+
import pandas as pd
|
| 13 |
|
| 14 |
# Ensure local package is importable when running in Hugging Face Spaces
|
| 15 |
ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
| 76 |
buf.seek(0)
|
| 77 |
np_img = mpimg.imread(buf)
|
| 78 |
windows = meta.get("windows", [])
|
| 79 |
+
table_rows = []
|
| 80 |
+
for w in windows:
|
| 81 |
+
table_rows.append(
|
| 82 |
+
[
|
| 83 |
+
w.get("start"),
|
| 84 |
+
w.get("end"),
|
| 85 |
+
round(float(w.get("significance", 0.0)), 3),
|
| 86 |
+
round(float(w.get("probability", 0.0)), 3),
|
| 87 |
+
bool(w.get("selected")),
|
| 88 |
+
bool(w.get("forced", False)),
|
| 89 |
+
]
|
| 90 |
+
)
|
| 91 |
+
df = pd.DataFrame(table_rows, columns=["start", "end", "significance", "prob", "selected", "forced"])
|
| 92 |
summary = f"Windows kept: {meta.get('selected_windows',0)}/{meta.get('total_windows',0)} • ratio={meta.get('ratio',1):.2f}"
|
| 93 |
+
return np_img, summary, df
|
| 94 |
|
| 95 |
|
| 96 |
# Demo signals with more structure so gating can skip/keep meaningfully
|
|
|
|
| 121 |
)
|
| 122 |
img = gr.Image(type="numpy", label="Raw vs Gated")
|
| 123 |
summary_box = gr.Textbox(label="Gating summary")
|
| 124 |
+
table = gr.Dataframe(
|
| 125 |
+
headers=["start", "end", "significance", "prob", "selected", "forced"],
|
| 126 |
+
datatype=["number", "number", "number", "number", "bool", "bool"],
|
| 127 |
+
wrap=True,
|
| 128 |
+
)
|
| 129 |
btn2 = gr.Button("Show gating")
|
| 130 |
btn2.click(plot_gating, inputs=inp2, outputs=[img, summary_box, table])
|
| 131 |
with gr.Tab("Demos"):
|