RajendrakumarPachaiappan commited on
Commit
f17b126
·
verified ·
1 Parent(s): e3a8299

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. DockerFile +20 -0
  2. app.py +82 -0
  3. hosting.py +13 -0
  4. requirements.txt +4 -2
DockerFile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Use a Python base image
3
+ FROM python:3.9-slim
4
+
5
+ # Set the working directory
6
+ WORKDIR /app
7
+
8
+ # Copy the requirements file and install dependencies
9
+ COPY requirements.txt .
10
+ RUN pip install --no-cache-dir -r requirements.txt
11
+
12
+ # Copy the application script
13
+ COPY app.py .
14
+
15
+ # Expose the port Streamlit runs on
16
+ EXPOSE 8501
17
+
18
+ # Set the entry point to run the Streamlit application
19
+ ENTRYPOINT ["streamlit", "run"]
20
+ CMD ["app.py"]
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import numpy as np
5
+ import joblib
6
+ from huggingface_hub import hf_hub_download
7
+ import os
8
+
9
+
10
+ MODEL_REPO_ID = "RajendrakumarPachaiappan/engine-predictive-model"
11
+ MODEL_FILE = "final_random_forest_model.joblib"
12
+ SCALER_FILE = "standard_scaler.joblib"
13
+
14
+ FEATURE_COLS = ['Engine rpm', 'Lub oil pressure', 'Fuel pressure',
15
+ 'Coolant pressure', 'lub oil temp', 'Coolant temp']
16
+
17
+
18
+ @st.cache_resource
19
+ def load_model_and_scaler():
20
+ """Downloads and loads the model and scaler from Hugging Face Hub."""
21
+ st.info("Loading model and scaler from Hugging Face Hub...")
22
+ try:
23
+ model_path = hf_hub_download(repo_id=MODEL_REPO_ID, filename=MODEL_FILE)
24
+ model = joblib.load(model_path)
25
+ scaler_path = hf_hub_download(repo_id=MODEL_REPO_ID, filename=SCALER_FILE)
26
+ scaler = joblib.load(scaler_path)
27
+ st.success("Artifacts loaded successfully!")
28
+ return model, scaler
29
+ except Exception as e:
30
+ st.error(f"Error loading artifacts from Hugging Face Hub: {e}")
31
+ return None, None
32
+
33
+ model, scaler = load_model_and_scaler()
34
+
35
+ # Streamlit UI and Prediction Logic
36
+ st.set_page_config(page_title="Predictive Maintenance", layout="wide")
37
+ st.title("Engine Health Predictor")
38
+ st.markdown("Use the sliders to simulate real-time sensor data and predict the **Engine Condition** (0=Healthy, 1=Faulty).")
39
+
40
+ col1, col2, col3 = st.columns(3)
41
+
42
+ with col1:
43
+
44
+ Engine_rpm = st.slider("Engine RPM (rev/min)", min_value=60, max_value=2300, value=791, step=10)
45
+ Lub_oil_pressure = st.slider("Lub Oil Pressure (bar)", min_value=0.0, max_value=7.3, value=3.3, step=0.1)
46
+ Fuel_pressure = st.slider("Fuel Pressure (bar)", min_value=0.0, max_value=22.0, value=6.7, step=0.1)
47
+
48
+ with col2:
49
+
50
+ Coolant_pressure = st.slider("Coolant Pressure (bar)", min_value=0.0, max_value=7.5, value=2.3, step=0.1)
51
+ Lub_oil_temp = st.slider("Lub Oil Temp (°C)", min_value=71.0, max_value=90.0, value=78.0, step=0.1)
52
+ Coolant_temp = st.slider("Coolant Temp (°C)", min_value=60.0, max_value=200.0, value=78.5, step=0.5)
53
+
54
+ # Prediction
55
+ if st.button("Predict Engine Condition", type="primary"):
56
+ if model and scaler:
57
+
58
+ input_data = pd.DataFrame({
59
+ 'Engine rpm': [Engine_rpm],
60
+ 'Lub oil pressure': [Lub_oil_pressure],
61
+ 'Fuel pressure': [Fuel_pressure],
62
+ 'Coolant pressure': [Coolant_pressure],
63
+ 'lub oil temp': [Lub_oil_temp],
64
+ 'Coolant temp': [Coolant_temp]
65
+ }, index=[0])
66
+
67
+
68
+ scaled_data = scaler.transform(input_data)
69
+
70
+ prediction = model.predict(scaled_data)[0]
71
+ prediction_proba = model.predict_proba(scaled_data)[0]
72
+
73
+ # Display Results
74
+ st.subheader("Prediction Result:")
75
+ if prediction == 1:
76
+ st.error(f"**FAULTY (Requires Maintenance)**")
77
+ st.markdown(f"**Confidence (Faulty):** `{prediction_proba[1]*100:.2f}%`")
78
+ st.warning("**Actionable Insight:** The model predicts a high risk of failure. Schedule maintenance immediately.")
79
+ else:
80
+ st.success(f"**HEALTHY (Normal Operation)**")
81
+ st.markdown(f"**Confidence (Healthy):** `{prediction_proba[0]*100:.2f}%`")
82
+ st.info("Engine is operating within normal parameters. Continue monitoring.")
hosting.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from huggingface_hub import HfApi
3
+ import os
4
+
5
+ api = HfApi(token=os.getenv("HF_TOKEN"))
6
+ api.upload_folder(
7
+ folder_path="/content/Predictive_Maintenance_Project/deployment",
8
+
9
+ repo_id="RajendrakumarPachaiappan/EnginePredictionModel",
10
+
11
+ repo_type="space",
12
+ path_in_repo="",
13
+ )
requirements.txt CHANGED
@@ -1,3 +1,5 @@
1
- altair
2
  pandas
3
- streamlit
 
 
 
 
 
1
  pandas
2
+ scikit-learn
3
+ joblib
4
+ streamlit
5
+ huggingface-hub