| import streamlit as st |
| import pandas as pd |
| import joblib |
|
|
| |
| |
| |
| st.set_page_config(page_title="Engine Condition App", layout="wide") |
|
|
| st.title("π Engine Condition Classification") |
|
|
| |
| |
| |
| @st.cache_resource |
| def load_model(): |
| model = joblib.load("best_model.pkl") |
| return model |
|
|
| model = load_model() |
|
|
| |
| feature_names = model.feature_names_in_ |
|
|
| |
| |
| |
| st.header("π§ Manual Prediction") |
|
|
| input_values = [] |
|
|
| cols = st.columns(3) |
|
|
| for i, feature in enumerate(feature_names): |
| with cols[i % 3]: |
| value = st.number_input(feature, value=0.0) |
| input_values.append(value) |
|
|
| if st.button("Predict Engine Condition"): |
|
|
| input_df = pd.DataFrame([input_values], columns=feature_names) |
|
|
| prediction = model.predict(input_df)[0] |
| probability = model.predict_proba(input_df)[0][1] |
|
|
| if prediction == 1: |
| st.error("β Engine Needs Maintenance") |
| else: |
| st.success("β
Engine Operating Normally") |
|
|
| st.write(f"**Failure Probability:** {probability:.3f}") |
|
|
| |
| |
| |
| st.header("π Batch Prediction") |
|
|
| uploaded_file = st.file_uploader("Upload CSV file", type=["csv"]) |
|
|
| if uploaded_file is not None: |
| try: |
| df = pd.read_csv(uploaded_file) |
|
|
| |
| if len(df) > 20000: |
| st.warning("β File too large. Max 10,000 rows allowed.") |
| else: |
| |
| missing_cols = [col for col in feature_names if col not in df.columns] |
|
|
| if missing_cols: |
| st.error(f"Missing required columns: {missing_cols}") |
| else: |
| df = df[feature_names] |
|
|
| probabilities = model.predict_proba(df)[:, 1] |
| df["Failure_Probability"] = probabilities |
| df["Prediction"] = (probabilities >= 0.5).astype(int) |
|
|
| st.success("β
Predictions completed!") |
|
|
| st.dataframe(df.head()) |
|
|
| csv = df.to_csv(index=False).encode("utf-8") |
|
|
| st.download_button( |
| label="Download Results", |
| data=csv, |
| file_name="engine_predictions.csv", |
| mime="text/csv", |
| ) |
|
|
| except Exception as e: |
| st.error(f"Error processing file: {e}") |
|
|