|
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
|
|
|
|
|
|
df=pd.read_csv(r"C:\Users\91879\Downloads\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")
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
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_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:")
|
|
|
|
|
|
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.")
|
|
|
|
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.")
|
|
|
|
|
|
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).")
|
|
|
|
|
|
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).")
|
|
|
|
|
|
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).")
|
|
|
|
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.")
|
|
|
|
|
|
if 20 < Pedal_Position < 60:
|
|
issues.append("π‘ **Moderate Brake Pedal Pressed** β normal city or highway braking.")
|
|
|
|
|
|
if 60 <= Pedal_Position <= 100:
|
|
issues.append("π **Brake Pedal Fully Pressed** β full braking detected. If pressure or wheel speed is abnormal, check for faults.")
|
|
|
|
|
|
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.")
|
|
|
|
|