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