Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -195,6 +195,43 @@ def df_centered_rounded(df: pd.DataFrame, hide_index=True):
|
|
| 195 |
.set_table_styles(TABLE_CENTER_CSS)
|
| 196 |
)
|
| 197 |
st.dataframe(styler, use_container_width=True, hide_index=hide_index)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
# --- target transform helpers (to support models trained on log(GR)) ---
|
| 200 |
def inverse_target(x: np.ndarray, transform: str) -> np.ndarray:
|
|
@@ -753,11 +790,7 @@ if st.session_state.show_preview_modal:
|
|
| 753 |
with t1:
|
| 754 |
st.pyplot(preview_tracks(df, FEATURES), use_container_width=True)
|
| 755 |
with t2:
|
| 756 |
-
|
| 757 |
-
.agg(['min','max','mean','std'])
|
| 758 |
-
.T.rename(columns={"min":"Min","max":"Max","mean":"Mean","std":"Std"}))
|
| 759 |
-
df_centered_rounded(tbl.reset_index(names="Feature"))
|
| 760 |
-
st.session_state.show_preview_modal = False
|
| 761 |
# =========================
|
| 762 |
# Footer
|
| 763 |
# =========================
|
|
|
|
| 195 |
.set_table_styles(TABLE_CENTER_CSS)
|
| 196 |
)
|
| 197 |
st.dataframe(styler, use_container_width=True, hide_index=hide_index)
|
| 198 |
+
def safe_summary(df: pd.DataFrame, features: list[str]) -> None:
|
| 199 |
+
"""
|
| 200 |
+
Show a centered, 2-decimal summary for whatever expected features
|
| 201 |
+
actually exist in `df`. Never crashes if some are missing or non-numeric.
|
| 202 |
+
"""
|
| 203 |
+
# Which expected columns are present / missing in this sheet?
|
| 204 |
+
present = [c for c in features if c in df.columns]
|
| 205 |
+
missing = [c for c in features if c not in df.columns]
|
| 206 |
+
|
| 207 |
+
if not present:
|
| 208 |
+
st.info(
|
| 209 |
+
"None of the expected feature columns were found in this sheet.\n"
|
| 210 |
+
f"Expected any of: {features}\n"
|
| 211 |
+
f"Found: {list(df.columns)}"
|
| 212 |
+
)
|
| 213 |
+
return
|
| 214 |
+
|
| 215 |
+
if missing:
|
| 216 |
+
st.caption(f"Columns not found in this sheet (omitted): {missing}")
|
| 217 |
+
|
| 218 |
+
# Work only with present columns and coerce to numeric (text → NaN)
|
| 219 |
+
work = df[present].copy()
|
| 220 |
+
for c in present:
|
| 221 |
+
work[c] = pd.to_numeric(work[c], errors="coerce")
|
| 222 |
+
|
| 223 |
+
# Build stats, 2 decimals, then show centered
|
| 224 |
+
tbl = (
|
| 225 |
+
work.agg(["min", "max", "mean", "std"])
|
| 226 |
+
.T.rename(columns={"min": "Min", "max": "Max", "mean": "Mean", "std": "Std"})
|
| 227 |
+
.round(2)
|
| 228 |
+
)
|
| 229 |
+
df_centered_rounded(tbl.reset_index(names="Feature"))
|
| 230 |
+
|
| 231 |
+
# Small note if coercion created NaNs
|
| 232 |
+
if work.isna().any().any():
|
| 233 |
+
st.caption("Note: non-numeric values were ignored after numeric coercion.")
|
| 234 |
+
|
| 235 |
|
| 236 |
# --- target transform helpers (to support models trained on log(GR)) ---
|
| 237 |
def inverse_target(x: np.ndarray, transform: str) -> np.ndarray:
|
|
|
|
| 790 |
with t1:
|
| 791 |
st.pyplot(preview_tracks(df, FEATURES), use_container_width=True)
|
| 792 |
with t2:
|
| 793 |
+
safe_summary(df, FEATURES)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 794 |
# =========================
|
| 795 |
# Footer
|
| 796 |
# =========================
|