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