CodingBuddy's picture
Upload folder using huggingface_hub
d2e033b verified
import streamlit as st
import pandas as pd
from huggingface_hub import hf_hub_download
import joblib
import os
# Assuming config.py is in the same directory or accessible via PYTHONPATH
# from config import HF_REPO_ID # If you want to load HF_REPO_ID from config.py
# For now, hardcode the repo ID as it's defined elsewhere in the notebook
HF_REPO_ID = "CodingBuddy/Predictive-maintenance"
# Download and load the model
try:
#model_path = hf_hub_download(repo_id=HF_REPO_ID, filename="Predictive_maintenance_project_best_model.joblib", repo_type="model")
#hf_hub_download('https://huggingface.co/CodingBuddy/Predictive-maintenance/blob/main/Predictive_maintenance_best_model.joblib')
#model = joblib.load(model_path)
#https://huggingface.co/CodingBuddy/Predictive-maintenance/blob/main/Predictive_maintenance_best_model.joblib
# using above path , download the hf model
model_path_downloaded = hf_hub_download(repo_id=HF_REPO_ID, filename="Predictive_maintenance_best_model.joblib", repo_type="model")
model = joblib.load(model_path_downloaded)
st.success("Model loaded successfully!")
#https://huggingface.co/CodingBuddy/Predictive-maintenance/blob/main/Predictive_maintenance_best_model.joblib
#https://huggingface.co/CodingBuddy/Predictive-maintenance/resolve/main/Predictive_maintenance_project_best_model.joblib
#https://huggingface.co/CodingBuddy/Predictive-maintenance/resolve/main/blob/main/Predictive_maintenance_project_best_model.joblib
except Exception as e:
st.error(f"Error loading model: {e}")
st.stop()
# Streamlit UI for Predictive Maintenance
st.title("Engine Predictive Maintenance App")
st.write("""
This application predicts whether an engine requires maintenance based on its sensor readings.
Please enter the engine sensor data below to get a prediction.
""")
# User input
st.header("Engine Sensor Data Input")
Engine_RPM = st.number_input("Engine RPM (Revolutions per Minute)", min_value=0.0, max_value=10000.0, value=700.0, step=1.0)
Lub_oil_pressure = st.number_input("Lubricating Oil Pressure (bar/kPa)", min_value=0.0, max_value=50.0, value=2.493592, step=0.000001, format="%.6f")
Fuel_pressure = st.number_input("Fuel Pressure (bar/kPa)", min_value=0.0, max_value=50.0, value=11.790927, step=0.000001, format="%.6f")
Coolant_pressure = st.number_input("Coolant Pressure (bar/kPa)", min_value=0.0, max_value=50.0, value=3.178981, step=0.000001, format="%.6f")
lub_oil_temp = st.number_input("Lubricating Oil Temperature (°C)", min_value=0.0, max_value=200.0, value=84.144163, step=0.000001, format="%.6f")
Coolant_temp = st.number_input("Coolant Temperature (°C)", min_value=0.0, max_value=200.0, value=81.632187, step=0.000001, format="%.6f")
# Assemble input into DataFrame
input_data = pd.DataFrame({
'Engine_rpm': [Engine_RPM],
'Lub_oil_pressure': [Lub_oil_pressure],
'Fuel_pressure': [Fuel_pressure],
'Coolant_pressure': [Coolant_pressure],
'lub_oil_temp': [lub_oil_temp],
'Coolant_temp': [Coolant_temp]
})
if st.button("Predict Engine Condition"):
try:
# Ensure the model is loaded before predicting
if 'model' in locals() and model is not None:
prediction = model.predict(input_data)[0]
# Assuming 0 = Normal, 1 = Requires Maintenance (Faulty)
result = "Requires Maintenance (Faulty)" if prediction == 1 else "Operating Normally"
st.subheader("Prediction Result:")
if prediction == 1:
st.error(f"The model predicts: **{result}**")
else:
st.success(f"The model predicts: **{result}**")
else:
st.warning("Model is not loaded. Please check the model loading process.")
except Exception as e:
st.error(f"An error occurred during prediction: {e}")