Download src/streamlit_app.py from jalesummak/binary_classification_with_bank: direct link, hf CLI and curl.
- Browser
- Download file 3.57 kB
-
https://huggingface.co/spaces/jalesummak/binary_classification_with_bank/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/jalesummak/binary_classification_with_bank/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/jalesummak/binary_classification_with_bank/resolve/main/src/streamlit_app.py
3.57 kB
| import os | |
| import joblib | |
| import pandas as pd | |
| import streamlit as st | |
| st.set_page_config(page_title="General Classification Lab", page_icon="π", layout="wide") | |
| ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| def load_models(): | |
| return ( | |
| joblib.load(os.path.join(ROOT, "spaceship_bundle.joblib")), | |
| joblib.load(os.path.join(ROOT, "iris_bundle.joblib")), | |
| ) | |
| spaceship, iris = load_models() | |
| st.title("π General Classification AI Lab") | |
| st.caption("Two classic classification problems rebuilt as interactive, tested applications.") | |
| spaceship_tab, iris_tab = st.tabs(["Spaceship Titanic", "Iris Flower"]) | |
| with spaceship_tab: | |
| st.subheader("Will a passenger be transported to another dimension?") | |
| a, b, c = st.columns(3) | |
| home = a.selectbox("Home planet", ["Earth", "Europa", "Mars"]) | |
| destination = a.selectbox("Destination", ["TRAPPIST-1e", "55 Cancri e", "PSO J318.5-22"]) | |
| age = a.slider("Age", 0, 90, 30) | |
| cryo = a.checkbox("CryoSleep") | |
| vip = a.checkbox("VIP passenger") | |
| group_size = b.slider("Travel group size", 1, 8, 1) | |
| deck = b.selectbox("Cabin deck", list("ABCDEFGT"), index=5) | |
| side = b.selectbox("Cabin side", ["P", "S"], format_func=lambda x: "Port" if x == "P" else "Starboard") | |
| room = b.number_input("Room service spend", 0.0, 30000.0, 0.0, 50.0) | |
| food = b.number_input("Food court spend", 0.0, 30000.0, 500.0, 50.0) | |
| shopping = c.number_input("Shopping mall spend", 0.0, 30000.0, 0.0, 50.0) | |
| spa = c.number_input("Spa spend", 0.0, 30000.0, 0.0, 50.0) | |
| vr = c.number_input("VR deck spend", 0.0, 30000.0, 0.0, 50.0) | |
| if st.button("Predict transportation", type="primary"): | |
| values = { | |
| "HomePlanet": home, "CryoSleep": cryo, "Destination": destination, "Age": age, "VIP": vip, | |
| "RoomService": room, "FoodCourt": food, "ShoppingMall": shopping, "Spa": spa, "VRDeck": vr, | |
| "GroupSize": group_size, "Deck": deck, "CabinSide": side, | |
| "TotalSpend": room + food + shopping + spa + vr, | |
| } | |
| row = pd.DataFrame([values], columns=spaceship["features"]) | |
| probability = float(spaceship["model"].predict_proba(row)[0, 1]) | |
| st.metric("Transportation probability", f"{probability:.1%}") | |
| st.success("Likely transported") if probability >= .5 else st.warning("Likely not transported") | |
| st.caption("Validation accuracy: 80.16% on held-out Spaceship Titanic competition passengers.") | |
| with iris_tab: | |
| st.subheader("Classify an Iris flower from four measurements") | |
| a, b = st.columns(2) | |
| sepal_length = a.slider("Sepal length (cm)", 4.0, 8.0, 5.8, .1) | |
| sepal_width = a.slider("Sepal width (cm)", 2.0, 5.0, 3.0, .1) | |
| petal_length = b.slider("Petal length (cm)", 1.0, 7.0, 4.3, .1) | |
| petal_width = b.slider("Petal width (cm)", .1, 2.5, 1.3, .1) | |
| if st.button("Classify flower", type="primary"): | |
| row = pd.DataFrame([[sepal_length, sepal_width, petal_length, petal_width]], columns=iris["features"]) | |
| probabilities = iris["model"].predict_proba(row)[0] | |
| prediction = int(probabilities.argmax()) | |
| st.success(f"Predicted species: **Iris {iris['target_names'][prediction].title()}**") | |
| chart = pd.DataFrame({"Species": [x.title() for x in iris["target_names"]], "Probability": probabilities}).set_index("Species") | |
| st.bar_chart(chart) | |
| st.caption("Validation accuracy: 96.67% on held-out Iris samples.") | |
| st.divider() | |
| st.caption("Portfolio of Jale Summak Β· Educational classification applications") | |