Update app.py
Browse files
app.py
CHANGED
|
@@ -257,8 +257,11 @@ if "explainer" not in st.session_state:
|
|
| 257 |
|
| 258 |
# ---------------- TRAIN ----------------
|
| 259 |
with tab_train:
|
|
|
|
|
|
|
| 260 |
train_file = st.file_uploader("Upload training Excel (.xlsx)", type=["xlsx"])
|
| 261 |
-
|
|
|
|
| 262 |
df = pd.read_excel(train_file, engine="openpyxl")
|
| 263 |
st.dataframe(df.head())
|
| 264 |
|
|
@@ -269,8 +272,10 @@ with tab_train:
|
|
| 269 |
|
| 270 |
st.session_state.pipe = pipe
|
| 271 |
st.session_state.explainer = explainer
|
|
|
|
| 272 |
|
| 273 |
st.success("Training complete. model.joblib and meta.json created.")
|
|
|
|
| 274 |
m = meta["metrics"]
|
| 275 |
c1, c2, c3, c4 = st.columns(4)
|
| 276 |
c1.metric("ROC AUC", f"{m['roc_auc']:.3f}")
|
|
@@ -278,6 +283,31 @@ with tab_train:
|
|
| 278 |
c3.metric("Train N", m["n_train"])
|
| 279 |
c4.metric("Test N", m["n_test"])
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
# ---------------- PREDICT ----------------
|
| 283 |
with tab_predict:
|
|
|
|
| 257 |
|
| 258 |
# ---------------- TRAIN ----------------
|
| 259 |
with tab_train:
|
| 260 |
+
st.subheader("Train model")
|
| 261 |
+
|
| 262 |
train_file = st.file_uploader("Upload training Excel (.xlsx)", type=["xlsx"])
|
| 263 |
+
|
| 264 |
+
if train_file is not None:
|
| 265 |
df = pd.read_excel(train_file, engine="openpyxl")
|
| 266 |
st.dataframe(df.head())
|
| 267 |
|
|
|
|
| 272 |
|
| 273 |
st.session_state.pipe = pipe
|
| 274 |
st.session_state.explainer = explainer
|
| 275 |
+
st.session_state.meta = meta
|
| 276 |
|
| 277 |
st.success("Training complete. model.joblib and meta.json created.")
|
| 278 |
+
|
| 279 |
m = meta["metrics"]
|
| 280 |
c1, c2, c3, c4 = st.columns(4)
|
| 281 |
c1.metric("ROC AUC", f"{m['roc_auc']:.3f}")
|
|
|
|
| 283 |
c3.metric("Train N", m["n_train"])
|
| 284 |
c4.metric("Test N", m["n_test"])
|
| 285 |
|
| 286 |
+
# ---------------- PUBLISH (only after training) ----------------
|
| 287 |
+
if st.session_state.get("pipe") is not None:
|
| 288 |
+
st.divider()
|
| 289 |
+
st.subheader("Publish trained model to Hugging Face Hub")
|
| 290 |
+
|
| 291 |
+
MODEL_REPO_ID = "Synav/LogiSHAP-Studio-LogReg"
|
| 292 |
+
default_version = datetime.utcnow().strftime("%Y%m%d-%H%M%S")
|
| 293 |
+
|
| 294 |
+
version_tag = st.text_input(
|
| 295 |
+
"Version tag",
|
| 296 |
+
value=default_version,
|
| 297 |
+
help="Used as releases/<version>/ in the model repository",
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
if st.button("Publish model.joblib + meta.json to Model Repo"):
|
| 301 |
+
try:
|
| 302 |
+
with st.spinner("Uploading to Hugging Face Model repo..."):
|
| 303 |
+
paths = publish_to_hub(MODEL_REPO_ID, version_tag)
|
| 304 |
+
|
| 305 |
+
st.success("Uploaded successfully to your model repository.")
|
| 306 |
+
st.json(paths)
|
| 307 |
+
|
| 308 |
+
except Exception as e:
|
| 309 |
+
st.error(f"Upload failed: {e}")
|
| 310 |
+
|
| 311 |
|
| 312 |
# ---------------- PREDICT ----------------
|
| 313 |
with tab_predict:
|