Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,60 +1,78 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
| 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 |
input_data = pd.DataFrame([{
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
}])
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
# Prediction
|
| 51 |
-
#
|
| 52 |
if st.button("Predict Engine Condition"):
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
if prediction == 1 or prediction == "Good":
|
| 58 |
-
st.success("✅ Engine Condition: GOOD")
|
| 59 |
-
else:
|
| 60 |
-
st.error("⚠️ Engine Condition: BAD")
|
|
|
|
| 1 |
+
# %%writefile app.py
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import joblib
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
+
from sklearn.ensemble import AdaBoostClassifier # ensure scikit-learn flavor
|
| 7 |
+
from sklearn.metrics import classification_report
|
| 8 |
|
| 9 |
+
# -------------------------------
|
| 10 |
+
# Streamlit App Title & Description
|
| 11 |
+
# -------------------------------
|
| 12 |
+
st.set_page_config(page_title="Engine Condition Predictor", layout="centered")
|
| 13 |
+
st.title("Engine Condition Prediction")
|
| 14 |
+
st.write("""
|
| 15 |
+
Predict if an engine's condition is Good or Bad based on sensor readings.
|
| 16 |
+
""")
|
| 17 |
+
|
| 18 |
+
# -------------------------------
|
| 19 |
+
# Load the model from Hugging Face
|
| 20 |
+
# -------------------------------
|
| 21 |
+
|
| 22 |
+
@st.cache_resource(show_spinner=True)
|
| 23 |
+
def load_model():
|
| 24 |
+
"""
|
| 25 |
+
Load the pre-trained AdaBoost model from Hugging Face.
|
| 26 |
+
Uses caching to prevent re-downloading every restart.
|
| 27 |
+
"""
|
| 28 |
+
HF_DATASET = "vihu21/predictive_maintenance"
|
| 29 |
+
|
| 30 |
+
MODEL_FILE = "engine_predict/best_ada_model.joblib" # ⚠️ make sure this matches HF exactly
|
| 31 |
+
|
| 32 |
+
model_path = hf_hub_download(
|
| 33 |
+
repo_id=HF_DATASET,
|
| 34 |
+
filename=MODEL_FILE,
|
| 35 |
+
repo_type="model"
|
| 36 |
+
)
|
| 37 |
+
return joblib.load(model_path)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
ada_model = load_model()
|
| 42 |
+
st.success("✅ Model loaded successfully!")
|
| 43 |
+
|
| 44 |
+
# -------------------------------
|
| 45 |
+
# User Input
|
| 46 |
+
# -------------------------------
|
| 47 |
+
st.subheader("Engine Sensor Inputs")
|
| 48 |
+
Engine_Details = st.number_input("Engine Details Size (MB)", min_value=1.0, max_value=4000.0, value=50.0, step=0.1)
|
| 49 |
+
EngineRpm = st.number_input("Engine rpm", min_value=50, max_value=10000, value=3000)
|
| 50 |
+
LubOilPressure = st.number_input("Lubrication Oil Pressure", min_value=0.0, value=7.25)
|
| 51 |
+
FuelPressure = st.number_input("Fuel Pressure", min_value=0.0, value=21.4)
|
| 52 |
+
CoolantPressure = st.number_input("Coolant Pressure", min_value=0.0, value=7.5)
|
| 53 |
+
LubOilTemp = st.number_input("Lubrication Oil Temperature", min_value=0.0, value=90.0)
|
| 54 |
+
CoolantTemp = st.number_input("Coolant Temperature", min_value=0.0, value=195.0)
|
| 55 |
+
|
| 56 |
+
# -------------------------------
|
| 57 |
+
# Prepare input dataframe
|
| 58 |
+
# -------------------------------
|
| 59 |
input_data = pd.DataFrame([{
|
| 60 |
+
'Engine rpm': EngineRpm,
|
| 61 |
+
'Lub oil pressure': LubOilPressure,
|
| 62 |
+
'Fuel pressure': FuelPressure,
|
| 63 |
+
'Coolant pressure': CoolantPressure,
|
| 64 |
+
'lub oil temp': LubOilTemp,
|
| 65 |
+
'Coolant temp': CoolantTemp
|
| 66 |
}])
|
| 67 |
|
| 68 |
+
# -------------------------------
|
| 69 |
+
# Make Prediction
|
| 70 |
+
# -------------------------------
|
| 71 |
if st.button("Predict Engine Condition"):
|
| 72 |
+
try:
|
| 73 |
+
prediction = ada_model.predict(input_data)[0]
|
| 74 |
+
st.subheader("Prediction Result")
|
| 75 |
+
st.success(f"Estimated Engine Condition: **{prediction}**")
|
| 76 |
+
except Exception as e:
|
| 77 |
+
st.error(f"❌ Error during prediction: {str(e)}")
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|