Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -165,12 +165,20 @@ def parse_excel(data_bytes: bytes):
|
|
| 165 |
def read_book_bytes(b: bytes): return parse_excel(b) if b else {}
|
| 166 |
|
| 167 |
def ensure_cols(df, cols):
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
if miss:
|
| 170 |
-
st.error(f"Missing columns: {miss}\nFound: {list(
|
| 171 |
return False
|
|
|
|
|
|
|
| 172 |
return True
|
| 173 |
|
|
|
|
| 174 |
def find_sheet(book, names):
|
| 175 |
low2orig = {k.lower(): k for k in book.keys()}
|
| 176 |
for nm in names:
|
|
@@ -863,6 +871,7 @@ if st.session_state.app_step == "predict":
|
|
| 863 |
# Run preview modal after all other elements
|
| 864 |
# =========================
|
| 865 |
if st.session_state.show_preview_modal:
|
|
|
|
| 866 |
book_to_preview = {}
|
| 867 |
if st.session_state.app_step == "dev":
|
| 868 |
book_to_preview = read_book_bytes(st.session_state.dev_file_bytes)
|
|
@@ -877,22 +886,32 @@ if st.session_state.show_preview_modal:
|
|
| 877 |
tabs = st.tabs(names)
|
| 878 |
for t, name in zip(tabs, names):
|
| 879 |
with t:
|
| 880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 881 |
t1, t2 = st.tabs(["Tracks", "Summary"])
|
| 882 |
with t1:
|
| 883 |
st.pyplot(preview_tracks(df, FEATURES), use_container_width=True)
|
|
|
|
|
|
|
| 884 |
with t2:
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 889 |
st.session_state.show_preview_modal = False
|
| 890 |
|
| 891 |
-
# === Bottom-of-page Export (per step) =========================================
|
| 892 |
-
if st.session_state.app_step in ("dev", "validate", "predict"):
|
| 893 |
-
has_results = any(k in st.session_state.results for k in ("Train", "Test", "Validate", "PredictOnly"))
|
| 894 |
-
if has_results:
|
| 895 |
-
render_export_button(key=f"export_{st.session_state.app_step}")
|
| 896 |
|
| 897 |
# =========================
|
| 898 |
# Footer
|
|
|
|
| 165 |
def read_book_bytes(b: bytes): return parse_excel(b) if b else {}
|
| 166 |
|
| 167 |
def ensure_cols(df, cols):
|
| 168 |
+
"""
|
| 169 |
+
Check required columns exist; auto-fix common typos first.
|
| 170 |
+
"""
|
| 171 |
+
# Auto-fix known variants before checking
|
| 172 |
+
fixed = _normalize_columns(df)
|
| 173 |
+
miss = [c for c in cols if c not in fixed.columns]
|
| 174 |
if miss:
|
| 175 |
+
st.error(f"Missing columns: {miss}\nFound: {list(fixed.columns)}")
|
| 176 |
return False
|
| 177 |
+
# If everything exists in the fixed version, reflect back to caller
|
| 178 |
+
# (callers typically use the same df instance; we return True only)
|
| 179 |
return True
|
| 180 |
|
| 181 |
+
|
| 182 |
def find_sheet(book, names):
|
| 183 |
low2orig = {k.lower(): k for k in book.keys()}
|
| 184 |
for nm in names:
|
|
|
|
| 871 |
# Run preview modal after all other elements
|
| 872 |
# =========================
|
| 873 |
if st.session_state.show_preview_modal:
|
| 874 |
+
# Select the correct workbook bytes for this step
|
| 875 |
book_to_preview = {}
|
| 876 |
if st.session_state.app_step == "dev":
|
| 877 |
book_to_preview = read_book_bytes(st.session_state.dev_file_bytes)
|
|
|
|
| 886 |
tabs = st.tabs(names)
|
| 887 |
for t, name in zip(tabs, names):
|
| 888 |
with t:
|
| 889 |
+
# 🔧 Normalize columns BEFORE plotting/summarizing
|
| 890 |
+
df_raw = book_to_preview[name]
|
| 891 |
+
df = _normalize_columns(df_raw)
|
| 892 |
+
|
| 893 |
+
# Tracks
|
| 894 |
t1, t2 = st.tabs(["Tracks", "Summary"])
|
| 895 |
with t1:
|
| 896 |
st.pyplot(preview_tracks(df, FEATURES), use_container_width=True)
|
| 897 |
+
|
| 898 |
+
# Summary (guard against any missing cols after normalization)
|
| 899 |
with t2:
|
| 900 |
+
feat_present = [c for c in FEATURES if c in df.columns]
|
| 901 |
+
if not feat_present:
|
| 902 |
+
st.info("No feature columns found to summarize.")
|
| 903 |
+
else:
|
| 904 |
+
tbl = (
|
| 905 |
+
df[feat_present]
|
| 906 |
+
.agg(['min','max','mean','std'])
|
| 907 |
+
.T.rename(columns={"min":"Min","max":"Max","mean":"Mean","std":"Std"})
|
| 908 |
+
.reset_index(names="Feature")
|
| 909 |
+
)
|
| 910 |
+
df_centered_rounded(tbl)
|
| 911 |
+
|
| 912 |
+
# Reset the flag so the modal doesn't stick around
|
| 913 |
st.session_state.show_preview_modal = False
|
| 914 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 915 |
|
| 916 |
# =========================
|
| 917 |
# Footer
|