|
|
import streamlit as st |
|
|
import joblib |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
pipeline = joblib.load("src/logistic_model_pipeline") |
|
|
model = pipeline["model"] |
|
|
num_scaler = pipeline["num_scaler"] |
|
|
cat_encoder = pipeline["cat_encoder"] |
|
|
y_encoder = pipeline["y_encoder"] |
|
|
num_columns = pipeline["num_columns"] |
|
|
cat_columns = pipeline["cat_columns"] |
|
|
|
|
|
|
|
|
st.set_page_config(page_title="π§ Penguin Classifier", layout="centered") |
|
|
st.title("π§ Penguin Species Prediction") |
|
|
st.subheader("π₯ Enter the Penguin's Features") |
|
|
|
|
|
|
|
|
st.markdown("### π’ Numeric Features") |
|
|
num_inputs = [] |
|
|
|
|
|
slider_ranges = { |
|
|
"bill_length_mm": (32.1, 59.6), |
|
|
"bill_depth_mm": (13.1, 21.5), |
|
|
"flipper_length_mm": (172.0, 231.0), |
|
|
"body_mass_g": (2700.0, 6300.0) |
|
|
} |
|
|
|
|
|
for col in num_columns: |
|
|
min_val, max_val = slider_ranges.get(col, (0.0, 100.0)) |
|
|
val = st.slider( |
|
|
f"{col.replace('_', ' ').title()}", |
|
|
min_value=min_val, |
|
|
max_value=max_val, |
|
|
step=0.1 |
|
|
) |
|
|
num_inputs.append(val) |
|
|
|
|
|
|
|
|
st.markdown("### 𧬠Categorical Features") |
|
|
cat_inputs = [] |
|
|
|
|
|
for col in cat_columns: |
|
|
if "island" in col.lower(): |
|
|
val = st.selectbox(f"{col.replace('_', ' ').title()}:", ["Dream", "Torgersen", "Biscoe"]) |
|
|
else: |
|
|
val = st.text_input(f"{col.replace('_', ' ').title()}:") |
|
|
cat_inputs.append(val) |
|
|
|
|
|
|
|
|
if st.button("π Predict"): |
|
|
try: |
|
|
|
|
|
scaled_nums = num_scaler.transform([num_inputs]) |
|
|
encoded_cats = cat_encoder.transform([cat_inputs]) |
|
|
combined = np.hstack([scaled_nums, encoded_cats]) |
|
|
|
|
|
|
|
|
result = model.predict(combined) |
|
|
final_pred = y_encoder.inverse_transform(result) |
|
|
|
|
|
st.success(f"β
The predicted species is: **{final_pred[0]}**") |
|
|
st.balloons() |
|
|
|
|
|
except Exception as e: |
|
|
st.error(f"Oops! Something went wrong: {e}") |