darly9991 commited on
Commit
4e5ebe4
·
verified ·
1 Parent(s): 77711e5

Delete water_index_quality.py

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