Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import io
|
|
| 6 |
st.set_page_config(page_title="Excel β Management Insights", layout="wide")
|
| 7 |
|
| 8 |
st.title("π Excel β Interactive Management Dashboard")
|
| 9 |
-
st.caption("
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
# Grade logic
|
|
@@ -15,7 +15,6 @@ def grade_pass_fail(g):
|
|
| 15 |
if pd.isna(g):
|
| 16 |
return "Unknown"
|
| 17 |
g = str(g).strip().upper()
|
| 18 |
-
|
| 19 |
if g.startswith(("D", "E", "F")):
|
| 20 |
return "Fail"
|
| 21 |
if g.startswith("C"):
|
|
@@ -46,28 +45,29 @@ def ensure_sno(df):
|
|
| 46 |
|
| 47 |
|
| 48 |
# -----------------------------
|
| 49 |
-
# Upload section (
|
| 50 |
# -----------------------------
|
| 51 |
uploaded = st.file_uploader("Upload Excel (.xlsx)", type=["xlsx"])
|
| 52 |
|
|
|
|
|
|
|
| 53 |
if uploaded is None:
|
| 54 |
st.info("Upload an Excel file to begin.")
|
| 55 |
st.stop()
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
if not
|
|
|
|
| 60 |
st.warning("Click **Load file** after uploading.")
|
| 61 |
st.stop()
|
| 62 |
|
| 63 |
-
|
| 64 |
-
try:
|
| 65 |
-
file_bytes = uploaded.read()
|
| 66 |
-
except Exception as e:
|
| 67 |
-
st.error(f"Failed to read uploaded file: {e}")
|
| 68 |
-
st.stop()
|
| 69 |
-
|
| 70 |
-
if file_bytes is None or file_bytes == b"":
|
| 71 |
st.error("Uploaded file is empty.")
|
| 72 |
st.stop()
|
| 73 |
|
|
@@ -104,22 +104,13 @@ df["PassFail"] = df["Grade"].apply(grade_pass_fail)
|
|
| 104 |
df["Pass"] = df["PassFail"] == "Pass"
|
| 105 |
df["Fail"] = df["PassFail"] == "Fail"
|
| 106 |
|
| 107 |
-
# -----------------------------
|
| 108 |
-
# Sidebar
|
| 109 |
-
# -----------------------------
|
| 110 |
-
view = st.sidebar.radio(
|
| 111 |
-
"Perspective",
|
| 112 |
-
["Executive", "Risk", "Student", "Export"],
|
| 113 |
-
index=0
|
| 114 |
-
)
|
| 115 |
-
|
| 116 |
# -----------------------------
|
| 117 |
# KPIs
|
| 118 |
# -----------------------------
|
| 119 |
c1, c2, c3, c4 = st.columns(4)
|
| 120 |
c1.metric("Students", len(df))
|
| 121 |
-
c2.metric("Pass", df["Pass"].sum())
|
| 122 |
-
c3.metric("Fail", df["Fail"].sum())
|
| 123 |
c4.metric("Pass Rate", f"{df['Pass'].mean()*100:.1f}%")
|
| 124 |
|
| 125 |
st.divider()
|
|
@@ -127,6 +118,8 @@ st.divider()
|
|
| 127 |
# -----------------------------
|
| 128 |
# Views
|
| 129 |
# -----------------------------
|
|
|
|
|
|
|
| 130 |
if view == "Executive":
|
| 131 |
g = df["Grade"].value_counts().reset_index()
|
| 132 |
g.columns = ["Grade", "Count"]
|
|
@@ -146,4 +139,4 @@ elif view == "Student":
|
|
| 146 |
|
| 147 |
else:
|
| 148 |
csv = df.to_csv(index=False).encode("utf-8")
|
| 149 |
-
st.download_button("β¬οΈ Download CSV", csv, "analysis_for_powerbi.csv", "text/csv")
|
|
|
|
| 6 |
st.set_page_config(page_title="Excel β Management Insights", layout="wide")
|
| 7 |
|
| 8 |
st.title("π Excel β Interactive Management Dashboard")
|
| 9 |
+
st.caption("PASS if Grade β₯ C | FAIL if C- / D / F")
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
# Grade logic
|
|
|
|
| 15 |
if pd.isna(g):
|
| 16 |
return "Unknown"
|
| 17 |
g = str(g).strip().upper()
|
|
|
|
| 18 |
if g.startswith(("D", "E", "F")):
|
| 19 |
return "Fail"
|
| 20 |
if g.startswith("C"):
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
# -----------------------------
|
| 48 |
+
# Upload section (CORRECT)
|
| 49 |
# -----------------------------
|
| 50 |
uploaded = st.file_uploader("Upload Excel (.xlsx)", type=["xlsx"])
|
| 51 |
|
| 52 |
+
file_bytes = None # β
ALWAYS defined
|
| 53 |
+
|
| 54 |
if uploaded is None:
|
| 55 |
st.info("Upload an Excel file to begin.")
|
| 56 |
st.stop()
|
| 57 |
|
| 58 |
+
if st.button("β
Load file"):
|
| 59 |
+
try:
|
| 60 |
+
file_bytes = uploaded.read()
|
| 61 |
+
except Exception as e:
|
| 62 |
+
st.error(f"Failed to read file: {e}")
|
| 63 |
+
st.stop()
|
| 64 |
|
| 65 |
+
# β Stop if button not clicked or file not read
|
| 66 |
+
if file_bytes is None:
|
| 67 |
st.warning("Click **Load file** after uploading.")
|
| 68 |
st.stop()
|
| 69 |
|
| 70 |
+
if file_bytes == b"":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
st.error("Uploaded file is empty.")
|
| 72 |
st.stop()
|
| 73 |
|
|
|
|
| 104 |
df["Pass"] = df["PassFail"] == "Pass"
|
| 105 |
df["Fail"] = df["PassFail"] == "Fail"
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
# -----------------------------
|
| 108 |
# KPIs
|
| 109 |
# -----------------------------
|
| 110 |
c1, c2, c3, c4 = st.columns(4)
|
| 111 |
c1.metric("Students", len(df))
|
| 112 |
+
c2.metric("Pass", int(df["Pass"].sum()))
|
| 113 |
+
c3.metric("Fail", int(df["Fail"].sum()))
|
| 114 |
c4.metric("Pass Rate", f"{df['Pass'].mean()*100:.1f}%")
|
| 115 |
|
| 116 |
st.divider()
|
|
|
|
| 118 |
# -----------------------------
|
| 119 |
# Views
|
| 120 |
# -----------------------------
|
| 121 |
+
view = st.sidebar.radio("View", ["Executive", "Risk", "Student", "Export"])
|
| 122 |
+
|
| 123 |
if view == "Executive":
|
| 124 |
g = df["Grade"].value_counts().reset_index()
|
| 125 |
g.columns = ["Grade", "Count"]
|
|
|
|
| 139 |
|
| 140 |
else:
|
| 141 |
csv = df.to_csv(index=False).encode("utf-8")
|
| 142 |
+
st.download_button("β¬οΈ Download CSV for Power BI", csv, "analysis_for_powerbi.csv", "text/csv")
|