Spaces:
Runtime error
Runtime error
# import required libraries | |
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from datetime import datetime | |
from datetime import timedelta | |
from sklearn.model_selection import RandomizedSearchCV, GridSearchCV, train_test_split | |
from sklearn.ensemble import RandomForestRegressor | |
from sklearn.metrics import r2_score | |
from sklearn.preprocessing import LabelEncoder | |
from sklearn.preprocessing import StandardScaler | |
import streamlit as st | |
import warnings | |
warnings.filterwarnings('ignore') | |
st.title("Prediction of Maximum Number of Repairs") | |
st.sidebar.header('Enter the Components Details here') | |
st.write("""This model helps to know the probable maximum number of times a component can be repaired. | |
After which, we can straight away replace it with a new component""") | |
import pandas as pd | |
import numpy as np | |
import pickle | |
# load the saved model using pickle | |
with open('max_repair_model.pkl', 'rb') as file: | |
model = pickle.load(file) | |
# Load the saved manufacturer label encoder object using pickle | |
with open('manufacturer_le.pkl', 'rb') as file1: | |
le = pickle.load(file1) | |
# DATA from user | |
def user_report(): | |
manufacturer = st.sidebar.selectbox("Manufacturer", | |
("JKL Company", "GHI Company","DEF Company","ABC Company","XYZ Company" )) | |
if manufacturer=='JKL Company': | |
manufacturer=3 | |
elif manufacturer=="GHI Company": | |
manufacturer=2 | |
elif manufacturer=="DEF Company": | |
manufacturer=1 | |
elif manufacturer=="ABC Company": | |
manufacturer =0 | |
else: | |
manufacturer=4 | |
component_age = st.sidebar.slider('Component Age (in hours)', 100,250, 300 ) | |
total_operating_hours = st.sidebar.slider('Total Operating Hours)', 400,1500, 500 ) | |
operating_temperature = st.sidebar.slider('Operating Temperature', 70,80, 75 ) | |
humidity = st.sidebar.slider('Humidity', 50,70, 55 ) | |
Vibration_Level = st.sidebar.slider('Vibration Level', 2,4, 2 ) | |
Pressure = st.sidebar.slider('Pressure', 28,32, 30 ) | |
Power_Input_Voltage= st.sidebar.slider('Power Input Voltage (V)',105,120,115) | |
previous_number_of_repairs = st.sidebar.number_input('Enter the Previous Number of Repairs Undergone 0 to 5 )',min_value=0,max_value=5,step=1) | |
load_factor = st.sidebar.slider('Load Factor',3,10,4) | |
engine_speed=st.sidebar.slider('Engine Speed',7000,8000,7800) | |
Oil_Temperature=st.sidebar.slider('Oil Temperature',170,185,172) | |
user_report_data = { | |
'Manufacturer': manufacturer, | |
'Component_Age': component_age, | |
'Total_Operating_Hours': total_operating_hours, | |
'Operating_Temperature': operating_temperature, | |
'Humidity': humidity, | |
'Vibration_Level': Vibration_Level, | |
'Pressure': Pressure, | |
'Power_Input_Voltage': Power_Input_Voltage, | |
'Previous_number_of_repairs': previous_number_of_repairs, | |
'Load_Factor': load_factor, | |
'Engine_Speed': engine_speed, | |
'Oil_Temperature':Oil_Temperature | |
} | |
report_data = pd.DataFrame(user_report_data, index=[0]) | |
return report_data | |
#Customer Data | |
user_data = user_report() | |
st.subheader("Component Details") | |
st.write(user_data) | |
# define the prediction function | |
def predict_max_number_of_repairs(user_data): | |
# encode the manufacturer using the loaded LabelEncoder object | |
#manufacturer_encoded = le.transform([manufacturer])[0] | |
# make the prediction using the loaded model and input data | |
predicted_max_number_of_repairs = model.predict(user_data) | |
# return the predicted max number of repairs as output | |
return np.round(predicted_max_number_of_repairs[0]) | |
# Function calling | |
y_pred = int(predict_max_number_of_repairs(user_data)) | |
st.write("Click here to see the Predictions") | |
if st.button("Predict"): | |
st.subheader(f"Maximun Number of Repairs is {y_pred} ") |