darly9991 commited on
Commit
5fab46a
·
verified ·
1 Parent(s): 1d3e918

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -91
app.py DELETED
@@ -1,91 +0,0 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import numpy as np
4
- import joblib
5
- import plotly.express as px
6
- import plotly.graph_objects as go
7
- import altair as alt
8
- import base64
9
- from sklearn.calibration import calibration_curve
10
- from sklearn.preprocessing import LabelEncoder
11
- from sklearn.metrics import accuracy_score, f1_score, log_loss, confusion_matrix
12
- from sklearn.utils.multiclass import unique_labels
13
-
14
- # === Load models ===
15
- svc_model = joblib.load("svc_pipeline.pkl")
16
- xgb_model = joblib.load("xgb_pipeline.pkl")
17
-
18
- # === App Config ===
19
- st.set_page_config(page_title="Water Quality Classifier Dashboard", layout="wide")
20
- st.title("💧 Water Quality Prediction and Model Dashboard")
21
-
22
- # === Model Selector ===
23
- model_choice = st.selectbox("Select Model", ["SVC + SMOTETomek", "XGBoost + SMOTETomek"])
24
- model = svc_model if model_choice == "SVC + SMOTETomek" else xgb_model
25
-
26
- # === Input Section ===
27
- st.header("📥 Input Data")
28
- data_option = st.radio("Input Method", ["Upload CSV", "Manual Entry"])
29
- input_df = None
30
-
31
- if data_option == "Upload CSV":
32
- uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
33
- if uploaded_file:
34
- input_df = pd.read_csv(uploaded_file)
35
- else:
36
- with st.form("manual_form"):
37
- ph = st.number_input("pH", min_value=1.0, max_value=14.0, value=7.0)
38
- bod = st.number_input("BOD (mg/L)", min_value=0.0, max_value=100.0, value=2.0)
39
- cod = st.number_input("COD (mg/L)", min_value=0.0, max_value=500.0, value=10.0)
40
- tss = st.number_input("TSS (mg/L)", min_value=0.0, max_value=1000.0, value=20.0)
41
- do = st.number_input("DO (mg/L)", min_value=0.0, max_value=20.0, value=5.0)
42
- no3 = st.number_input("NO3N (mg/L)", min_value=0.0, max_value=10.0, value=1.0)
43
- tp = st.number_input("Total Phosphat (mg/L)", min_value=0.0, max_value=10.0, value=0.1)
44
- fecal = st.number_input("Fecal Coliform (MPN/100mL)", min_value=0.0, max_value=1000000.0, value=500.0)
45
- submitted = st.form_submit_button("Predict")
46
-
47
- if submitted:
48
- input_df = pd.DataFrame([{
49
- "pH (Potential Hydrogen)": ph,
50
- "BOD (Biological Oxygen Demand) (mg/L)": bod,
51
- "COD (Chemical Oxygen Demand) (mg/L)": cod,
52
- "TSS (Total Suspended Solid) (mg/L)": tss,
53
- "DO (Dissolved Oxygen) (mg/L)": do,
54
- "NO3N (Nitrat) (mg/L)": no3,
55
- "Total Phosphat (mg/L)": tp,
56
- "Fecal Coliform (MPN/100 mL)": fecal
57
- }])
58
-
59
- # === Prediction Section ===
60
- if input_df is not None:
61
- st.header("🔍 Prediction Results")
62
- y_proba = model.predict_proba(input_df)
63
- y_pred = model.predict(input_df)
64
-
65
- label_encoder = LabelEncoder()
66
- label_encoder.classes_ = np.array(["Biological", "Chemical", "Eutrophication", "Safe"])
67
- pred_class = label_encoder.inverse_transform(y_pred)[0]
68
-
69
- st.markdown(f"### 🧪 Predicted Class: `{pred_class}`")
70
-
71
- fig_pie = px.pie(
72
- names=label_encoder.classes_,
73
- values=y_proba[0],
74
- title="Prediction Probability per Class",
75
- color_discrete_sequence=px.colors.qualitative.Set3
76
- )
77
- st.plotly_chart(fig_pie, use_container_width=True)
78
-
79
- # === Download CSV ===
80
- st.subheader("📤 Download Prediction")
81
- input_df["Predicted Class"] = pred_class
82
- input_df[[f"Prob_{c}" for c in label_encoder.classes_]] = y_proba
83
- csv = input_df.to_csv(index=False)
84
- b64 = base64.b64encode(csv.encode()).decode()
85
- href = f'<a href="data:file/csv;base64,{b64}" download="prediction_result.csv">Download CSV File</a>'
86
- st.markdown(href, unsafe_allow_html=True)
87
-
88
- # === Footer ===
89
- st.markdown("---")
90
- st.markdown("Developed with ❤️ for real-world decision support in water quality monitoring.")
91
-