Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,7 +54,7 @@ def ensure_sno(df):
|
|
| 54 |
|
| 55 |
|
| 56 |
# -----------------------------
|
| 57 |
-
# Upload (
|
| 58 |
# -----------------------------
|
| 59 |
uploaded = st.file_uploader("Upload Excel (.xlsx)", type=["xlsx"])
|
| 60 |
|
|
@@ -62,10 +62,21 @@ if uploaded is None:
|
|
| 62 |
st.info("Upload an Excel file to begin.")
|
| 63 |
st.stop()
|
| 64 |
|
| 65 |
-
#
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
if not file_bytes:
|
| 68 |
-
st.
|
| 69 |
st.stop()
|
| 70 |
|
| 71 |
# Force openpyxl
|
|
@@ -87,6 +98,9 @@ except Exception as e:
|
|
| 87 |
|
| 88 |
raw = normalize_headers(raw)
|
| 89 |
|
|
|
|
|
|
|
|
|
|
| 90 |
grade_col = pick_grade_column(raw)
|
| 91 |
df = raw.copy()
|
| 92 |
df, sno_col = ensure_sno(df)
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
# -----------------------------
|
| 57 |
+
# Upload (fully defensive)
|
| 58 |
# -----------------------------
|
| 59 |
uploaded = st.file_uploader("Upload Excel (.xlsx)", type=["xlsx"])
|
| 60 |
|
|
|
|
| 62 |
st.info("Upload an Excel file to begin.")
|
| 63 |
st.stop()
|
| 64 |
|
| 65 |
+
# User action gate (prevents HF startup/bare-mode crash)
|
| 66 |
+
load = st.button("✅ Load file")
|
| 67 |
+
if not load:
|
| 68 |
+
st.warning("After uploading, click **Load file**.")
|
| 69 |
+
st.stop()
|
| 70 |
+
|
| 71 |
+
# Read bytes safely (prefer read() on HF)
|
| 72 |
+
try:
|
| 73 |
+
file_bytes = uploaded.read()
|
| 74 |
+
except Exception as e:
|
| 75 |
+
st.error(f"Failed to read uploaded file: {e}")
|
| 76 |
+
st.stop()
|
| 77 |
+
|
| 78 |
if not file_bytes:
|
| 79 |
+
st.error("Uploaded file is empty. Please re-upload.")
|
| 80 |
st.stop()
|
| 81 |
|
| 82 |
# Force openpyxl
|
|
|
|
| 98 |
|
| 99 |
raw = normalize_headers(raw)
|
| 100 |
|
| 101 |
+
# -----------------------------
|
| 102 |
+
# Build dataframe
|
| 103 |
+
# -----------------------------
|
| 104 |
grade_col = pick_grade_column(raw)
|
| 105 |
df = raw.copy()
|
| 106 |
df, sno_col = ensure_sno(df)
|