karthick2613 commited on
Commit
c2ecada
·
verified ·
1 Parent(s): 27b5fc4

Deploy Docker-based Streamlit app

Browse files
Files changed (4) hide show
  1. Dockerfile +12 -0
  2. app.py +46 -0
  3. push_to_hf_space.py +28 -0
  4. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY app.py .
9
+
10
+ EXPOSE 8501
11
+
12
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import streamlit as st
3
+ import joblib
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ MODEL_REPO = "karthick2613/capstone_predictive_maintenance_model"
7
+
8
+ st.set_page_config(page_title="Predictive Maintenance", layout="centered")
9
+
10
+ st.title("🚗 Predictive Maintenance - Engine Failure Detection")
11
+ st.write("Enter sensor readings to predict whether maintenance is required.")
12
+
13
+ @st.cache_resource
14
+ def load_model():
15
+ model_path = hf_hub_download(
16
+ repo_id=MODEL_REPO,
17
+ filename="best_model.joblib",
18
+ repo_type="model"
19
+ )
20
+ return joblib.load(model_path)
21
+
22
+ model = load_model()
23
+
24
+ engine_rpm = st.number_input("Engine RPM", value=750.0)
25
+ lub_oil_pressure = st.number_input("Lub Oil Pressure", value=3.0)
26
+ fuel_pressure = st.number_input("Fuel Pressure", value=6.0)
27
+ coolant_pressure = st.number_input("Coolant Pressure", value=2.0)
28
+ lub_oil_temp = st.number_input("Lub Oil Temperature", value=77.0)
29
+ coolant_temp = st.number_input("Coolant Temperature", value=78.0)
30
+
31
+ if st.button("Predict Engine Condition"):
32
+ input_df = pd.DataFrame([{
33
+ "Engine rpm": engine_rpm,
34
+ "Lub oil pressure": lub_oil_pressure,
35
+ "Fuel pressure": fuel_pressure,
36
+ "Coolant pressure": coolant_pressure,
37
+ "lub oil temp": lub_oil_temp,
38
+ "Coolant temp": coolant_temp
39
+ }])
40
+
41
+ pred = model.predict(input_df)[0]
42
+
43
+ if pred == 1:
44
+ st.error("⚠️ Faulty Engine Detected — Maintenance Required")
45
+ else:
46
+ st.success("✅ Engine Operating Normally")
push_to_hf_space.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import HfApi
3
+
4
+ HF_SPACE_REPO = os.getenv("HF_SPACE_REPO")
5
+
6
+ def main():
7
+ api = HfApi(token=os.getenv("HF_TOKEN"))
8
+
9
+ # Create Hugging Face Space as DOCKER (not streamlit)
10
+ api.create_repo(
11
+ repo_id=HF_SPACE_REPO,
12
+ repo_type="space",
13
+ space_sdk="docker",
14
+ exist_ok=True
15
+ )
16
+
17
+ # Upload deployment folder (Dockerfile + app + requirements)
18
+ api.upload_folder(
19
+ folder_path="deployment",
20
+ repo_id=HF_SPACE_REPO,
21
+ repo_type="space",
22
+ commit_message="Deploy Docker-based Streamlit app"
23
+ )
24
+
25
+ print("✅ Hugging Face Space deployment complete.")
26
+
27
+ if __name__ == "__main__":
28
+ main()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ scikit-learn
4
+ joblib
5
+ huggingface_hub
6
+ xgboost
7
+ datasets