Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
import warnings
|
4 |
+
warnings.filterwarnings("ignore")
|
5 |
+
from sklearn.linear_model import LogisticRegression
|
6 |
+
from sklearn.model_selection import train_test_split
|
7 |
+
from sklearn.metrics import accuracy_score
|
8 |
+
import numpy as np
|
9 |
+
import matplotlib.pyplot as plt
|
10 |
+
|
11 |
+
# Load dataset
|
12 |
+
df=pd.read_csv(r"C:\Users\91879\Downloads\data.csv")
|
13 |
+
import streamlit as st
|
14 |
+
|
15 |
+
st.markdown(
|
16 |
+
"""
|
17 |
+
<style>
|
18 |
+
.stApp {
|
19 |
+
background-color: #e3f2fd; /* Try sky blue or another color */
|
20 |
+
padding: 12px;
|
21 |
+
}
|
22 |
+
</style>
|
23 |
+
""",
|
24 |
+
unsafe_allow_html=True
|
25 |
+
)
|
26 |
+
|
27 |
+
|
28 |
+
st.markdown("## π Vehicle Brake System Fault Detection")
|
29 |
+
st.markdown("#### Enter Brake Sensor Values to Predict Any System Fault")
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
### filling the mising values
|
34 |
+
df["Brake_Pressure"] = df["Brake_Pressure"].fillna(df["Brake_Pressure"].mean())
|
35 |
+
df["Pad_Wear_Level"] = df["Pad_Wear_Level"].fillna(df["Pad_Wear_Level"].mean())
|
36 |
+
df["ABS_Status"] = df["ABS_Status"].fillna(df["ABS_Status"].mean())
|
37 |
+
df["Wheel_Speed_FL"] = df["Wheel_Speed_FL"].fillna(df["Wheel_Speed_FL"].mean())
|
38 |
+
df["Wheel_Speed_FR"] = df["Wheel_Speed_FR"].fillna(df["Wheel_Speed_FR"].mean())
|
39 |
+
df["Wheel_Speed_RL"] = df["Wheel_Speed_RL"].fillna(df["Wheel_Speed_RL"].mean())
|
40 |
+
df["Wheel_Speed_RR"] = df["Wheel_Speed_RR"].fillna(df["Wheel_Speed_RR"].mean())
|
41 |
+
df["Fluid_Temperature"] = df["Fluid_Temperature"].fillna(df["Fluid_Temperature"].mean())
|
42 |
+
df["Pedal_Position"] = df["Pedal_Position"].fillna(df["Pedal_Position"].mean())
|
43 |
+
|
44 |
+
|
45 |
+
# Prepare data
|
46 |
+
x=df.drop("Fault",axis=1)
|
47 |
+
y=df["Fault"]
|
48 |
+
|
49 |
+
|
50 |
+
Brake_Pressure = st.slider("π¨ Brake Pressure (psi)", min_value=50.0, max_value=500.0, step=0.1)
|
51 |
+
Pad_Wear_Level = st.slider("π Pad Wear Level (%)", min_value=0.0, max_value=100.0, step=0.1)
|
52 |
+
ABS_Status = st.slider("π ABS Status (0 = Off, 1 = On)", min_value=0, max_value=1, step=1)
|
53 |
+
Wheel_Speed_FL = st.slider("βοΈ Wheel Speed FL (km/h)", min_value=0.0, max_value=400.0, step=0.1)
|
54 |
+
Wheel_Speed_FR = st.slider("βοΈ Wheel Speed FR (km/h)", min_value=0.0, max_value=400.0, step=0.1)
|
55 |
+
Wheel_Speed_RL = st.slider("βοΈ Wheel Speed RL (km/h)", min_value=0.0, max_value=300.0, step=0.1)
|
56 |
+
Wheel_Speed_RR = st.slider("βοΈ Wheel Speed RR (km/h)", min_value=0.0, max_value=300.0, step=0.1)
|
57 |
+
Fluid_Temperature = st.slider("π‘οΈ Fluid Temperature (Β°C)", min_value=-20.0, max_value=150.0, step=0.1)
|
58 |
+
Pedal_Position = st.slider("π¦Ά Pedal Position (%)", min_value=0.0, max_value=100.0, step=0.1)
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
# Split and train
|
63 |
+
from sklearn .linear_model import LogisticRegression
|
64 |
+
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=29)
|
65 |
+
lr = LogisticRegression()
|
66 |
+
lr.fit(x_train,y_train)
|
67 |
+
y_pred=lr.predict(x_test)
|
68 |
+
print("accuracy_score:",accuracy_score(y_test,y_pred))
|
69 |
+
|
70 |
+
# User input DataFrame
|
71 |
+
user_data = pd.DataFrame([[Brake_Pressure, Pad_Wear_Level, ABS_Status, Wheel_Speed_FL , Wheel_Speed_FR,Wheel_Speed_RL,Wheel_Speed_RR,
|
72 |
+
Fluid_Temperature,Pedal_Position]],
|
73 |
+
columns=["Brake_Pressure", "Pad_Wear_Level", "ABS_Status", "Wheel_Speed_FL", "Wheel_Speed_FR",
|
74 |
+
"Wheel_Speed_RL","Wheel_Speed_RR","Fluid_Temperature","Pedal_Position"])
|
75 |
+
|
76 |
+
|
77 |
+
if st.button("π Predict Brake Fault"):
|
78 |
+
y_pred = lr.predict(user_data)
|
79 |
+
prob = lr.predict_proba(user_data)[0][1]
|
80 |
+
|
81 |
+
if y_pred[0] == 1:
|
82 |
+
st.error(f"π¨ Fault Detected in Brake System! (Confidence: {prob:.2%})")
|
83 |
+
st.subheader("π Identified Possible Issues:")
|
84 |
+
|
85 |
+
# Diagnosis based on user inputs
|
86 |
+
issues = []
|
87 |
+
if Brake_Pressure < 60 or Brake_Pressure > 130:
|
88 |
+
issues.append("π΄ **Abnormal Brake Pressure** β should be between 60 and 130. Check hydraulic pressure or brake fluid levels.")
|
89 |
+
|
90 |
+
if Pad_Wear_Level >= 80:
|
91 |
+
issues.append("π **Brake Pads Critically Worn** β pad wear is above 80%. Immediate replacement recommended.")
|
92 |
+
elif Pad_Wear_Level >= 60:
|
93 |
+
issues.append("π‘ **Brake Pads Heavily Worn** β nearing replacement. Monitor closely.")
|
94 |
+
|
95 |
+
if ABS_Status == 0:
|
96 |
+
issues.append("π΅ **ABS System Not Active** β ABS is off or malfunctioning. This may reduce braking safety on wet or slippery roads.")
|
97 |
+
## for Wheel_Speed_FL
|
98 |
+
if Wheel_Speed_FL < 0 or Wheel_Speed_FL > 100:
|
99 |
+
issues.append("π΄ **Front Left Wheel Speed Abnormal** β value out of expected range (0β130 km/h). Check wheel sensor or brake system.")
|
100 |
+
|
101 |
+
# For Front Right Wheel
|
102 |
+
if Wheel_Speed_FR < 0 or Wheel_Speed_FR > 130:
|
103 |
+
issues.append("π΄ **Front Right Wheel Speed Abnormal** β out of expected range (0β130 km/h).")
|
104 |
+
|
105 |
+
# Rear Left
|
106 |
+
if Wheel_Speed_RL < 0 or Wheel_Speed_RL > 130:
|
107 |
+
issues.append("π΄ **Rear Left Wheel Speed Abnormal** β out of expected range (0β130 km/h).")
|
108 |
+
|
109 |
+
# Rear Right
|
110 |
+
if Wheel_Speed_RR < 0 or Wheel_Speed_RR > 130:
|
111 |
+
issues.append("π΄ **Rear Right Wheel Speed Abnormal** β out of expected range (0β130 km/h).")
|
112 |
+
## Fluid_Temperature
|
113 |
+
if Fluid_Temperature < -20 or Fluid_Temperature > 120:
|
114 |
+
issues.append("π₯ **Abnormal Brake Fluid Temperature** β should be between -20Β°C and 120Β°C. Check for overheating or freezing issues.")
|
115 |
+
|
116 |
+
# Moderate brake pedal press (between 20 and 60)
|
117 |
+
if 20 < Pedal_Position < 60:
|
118 |
+
issues.append("π‘ **Moderate Brake Pedal Pressed** β normal city or highway braking.")
|
119 |
+
|
120 |
+
# Hard/full brake press (between 60 and 100)
|
121 |
+
if 60 <= Pedal_Position <= 100:
|
122 |
+
issues.append("π **Brake Pedal Fully Pressed** β full braking detected. If pressure or wheel speed is abnormal, check for faults.")
|
123 |
+
|
124 |
+
# Low or no brake engagement
|
125 |
+
if Pedal_Position <= 20:
|
126 |
+
issues.append("π **Low Brake Pedal Engagement** β either not braking or sensor reading may be inaccurate.")
|
127 |
+
|
128 |
+
|
129 |
+
if len(issues) > 0:
|
130 |
+
for issue in issues:
|
131 |
+
st.markdown(f"- {issue}")
|
132 |
+
else:
|
133 |
+
st.info("No specific fault signals from input values, but model still detected an issue. Please consult a technician.")
|
134 |
+
|
135 |
+
else:
|
136 |
+
st.success(f"β
No Fault Detected. (Confidence: {1 - prob:.2%})")
|
137 |
+
st.info("π Your vehicle's brake system appears healthy.")
|
138 |
+
|