dhani10 commited on
Commit
82050c4
·
verified ·
1 Parent(s): 4166380

Deploy Engine Condition Predictor

Browse files
Files changed (4) hide show
  1. Dockerfile +20 -0
  2. README.md +5 -6
  3. requirements.txt +6 -0
  4. streamlit_app.py +119 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y gcc g++ && rm -rf /var/lib/apt/lists/*
7
+
8
+ # Copy requirements
9
+ COPY requirements.txt .
10
+
11
+ # Install Python packages
12
+ RUN pip install --upgrade pip
13
+ RUN pip install -r requirements.txt
14
+
15
+ # Copy app
16
+ COPY streamlit_app.py .
17
+
18
+ EXPOSE 7860
19
+
20
+ CMD ["streamlit", "run", "streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0"]
README.md CHANGED
@@ -1,10 +1,9 @@
1
  ---
2
- title: Engine Maintenance App
3
- emoji: 📊
4
- colorFrom: yellow
5
- colorTo: red
6
  sdk: docker
7
  pinned: false
8
  ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Engine Condition App
3
+ emoji: "🚧"
4
+ colorFrom: indigo
5
+ colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  ---
9
+ This Space runs a Streamlit app that predicts engine condition from sensor data.
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit==1.39.0
2
+ pandas==2.2.2
3
+ numpy==1.26.4
4
+ scikit-learn==1.5.0
5
+ joblib==1.4.2
6
+ huggingface_hub==0.25.1
streamlit_app.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+ from huggingface_hub import hf_hub_download
7
+ import os
8
+
9
+ # Configuration
10
+ HF_MODEL_REPO = os.getenv("HF_MODEL_REPO", "dhani10/engine-maintenance-model")
11
+ MODEL_FILE = os.getenv("MODEL_FILE", "best_engine_model.joblib")
12
+
13
+ # Expected features (match your training data exactly)
14
+ EXPECTED_COLS = [
15
+ 'Engine rpm', 'Lub oil pressure', 'Fuel pressure',
16
+ 'Coolant pressure', 'lub oil temp', 'Coolant temp'
17
+ ]
18
+
19
+ @st.cache_resource
20
+ def load_model():
21
+ """Load the model from Hugging Face Hub"""
22
+ try:
23
+ model_path = hf_hub_download(
24
+ repo_id=HF_MODEL_REPO,
25
+ filename=MODEL_FILE,
26
+ repo_type="model",
27
+ token=os.getenv("HF_TOKEN")
28
+ )
29
+ model = joblib.load(model_path)
30
+ st.success("Model loaded successfully!")
31
+ return model
32
+ except Exception as e:
33
+ st.error(f"Failed to load model: {e}")
34
+ return None
35
+
36
+ def main():
37
+ st.set_page_config(
38
+ page_title="Engine Condition Predictor",
39
+ layout="centered",
40
+ page_icon="🚧"
41
+ )
42
+
43
+ st.title("Predictive Maintenance — Engine Condition")
44
+ st.markdown("Monitor engine health using real-time sensor data")
45
+ st.caption(f"Model: {HF_MODEL_REPO}")
46
+
47
+ # Load model
48
+ with st.spinner("Loading AI model..."):
49
+ model = load_model()
50
+
51
+ if model is None:
52
+ st.stop()
53
+
54
+ # Input form
55
+ st.header("🔧 Engine Sensor Readings")
56
+
57
+ with st.form("prediction_form"):
58
+ col1, col2 = st.columns(2)
59
+
60
+ with col1:
61
+ engine_rpm = st.slider("Engine RPM", 100, 2500, 1200)
62
+ lub_oil_pressure = st.slider("Lub Oil Pressure (bar)", 0.5, 7.0, 3.0, 0.1)
63
+ fuel_pressure = st.slider("Fuel Pressure (bar)", 0.5, 20.0, 6.0, 0.1)
64
+
65
+ with col2:
66
+ coolant_pressure = st.slider("Coolant Pressure (bar)", 0.5, 7.0, 2.0, 0.1)
67
+ lub_oil_temp = st.slider("Lub Oil Temp (°C)", 70.0, 110.0, 80.0, 0.1)
68
+ coolant_temp = st.slider("Coolant Temp (°C)", 60.0, 100.0, 75.0, 0.1)
69
+
70
+ submitted = st.form_submit_button("Analyze Engine Condition", type="primary")
71
+
72
+ if submitted:
73
+ # Create input data with EXACT column names from training
74
+ input_data = pd.DataFrame([{
75
+ 'Engine rpm': engine_rpm,
76
+ 'Lub oil pressure': lub_oil_pressure,
77
+ 'Fuel pressure': fuel_pressure,
78
+ 'Coolant pressure': coolant_pressure,
79
+ 'lub oil temp': lub_oil_temp,
80
+ 'Coolant temp': coolant_temp
81
+ }])
82
+
83
+ try:
84
+ # Make prediction
85
+ prediction = model.predict(input_data)[0]
86
+ probability = model.predict_proba(input_data)[0]
87
+
88
+ # Display results
89
+ st.header("Analysis Results")
90
+
91
+ if prediction == 1:
92
+ st.error("**FAULTY ENGINE DETECTED**")
93
+ st.progress(probability[1])
94
+ st.warning(f"**Risk Probability:** {probability[1]*100:.1f}%")
95
+ st.markdown("""
96
+ **Recommended Actions:**
97
+ - Schedule immediate maintenance
98
+ - Inspect lubrication system
99
+ - Check cooling system
100
+ """)
101
+ else:
102
+ st.success("**ENGINE OPERATING NORMALLY**")
103
+ st.progress(probability[0])
104
+ st.info(f"**Health Score:** {probability[0]*100:.1f}%")
105
+ st.markdown("""
106
+ **Status:** Continue routine monitoring
107
+ **Next maintenance:** As scheduled
108
+ """)
109
+
110
+ # Show input data
111
+ with st.expander("View Input Data"):
112
+ st.dataframe(input_data)
113
+
114
+ except Exception as e:
115
+ st.error(f"Prediction error: {str(e)}")
116
+ st.info("Please check that the model expects the correct feature names")
117
+
118
+ if __name__ == "__main__":
119
+ main()