SabarnaDeb commited on
Commit
a9df0bd
·
verified ·
1 Parent(s): d9f5d55

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +17 -0
  2. app.py +77 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # System dependencies
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ git \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ COPY requirements.txt .
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ COPY app.py .
14
+
15
+ EXPOSE 7860
16
+
17
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import joblib
4
+ import pandas as pd
5
+ import gradio as gr
6
+ from huggingface_hub import hf_hub_download
7
+
8
+ # 1) SET YOUR MODEL REPO HERE (Model Hub repo, not dataset repo)
9
+ MODEL_REPO = os.getenv("MODEL_REPO", "SabarnaDeb/Capstone_PredictiveMaintenance_Model")
10
+ MODEL_FILE = os.getenv("MODEL_FILE", "model.joblib")
11
+
12
+ # 2) Download model file from Hugging Face Model Hub
13
+ model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, repo_type="model")
14
+ model = joblib.load(model_path)
15
+
16
+ # 3) Feature list must match your training columns
17
+ FEATURES = [
18
+ "engine_rpm",
19
+ "lub_oil_pressure",
20
+ "fuel_pressure",
21
+ "coolant_pressure",
22
+ "lub_oil_temperature",
23
+ "coolant_temperature"
24
+ ]
25
+
26
+ def predict(engine_rpm, lub_oil_pressure, fuel_pressure, coolant_pressure,
27
+ lub_oil_temperature, coolant_temperature):
28
+
29
+ # 4) Save inputs into a DataFrame
30
+ data = {
31
+ "engine_rpm": [engine_rpm],
32
+ "lub_oil_pressure": [lub_oil_pressure],
33
+ "fuel_pressure": [fuel_pressure],
34
+ "coolant_pressure": [coolant_pressure],
35
+ "lub_oil_temperature": [lub_oil_temperature],
36
+ "coolant_temperature": [coolant_temperature],
37
+ }
38
+ input_df = pd.DataFrame(data)
39
+
40
+ # 5) Predict
41
+ pred = model.predict(input_df[FEATURES])[0]
42
+
43
+ prob = None
44
+ if hasattr(model, "predict_proba"):
45
+ prob = float(model.predict_proba(input_df[FEATURES])[:, 1][0])
46
+
47
+ # 6) Business-friendly output
48
+ if int(pred) == 1:
49
+ msg = "⚠️ Maintenance Needed"
50
+ else:
51
+ msg = "✅ Normal Operation"
52
+
53
+ if prob is not None:
54
+ msg += f"\nConfidence (maintenance probability): {prob:.2f}"
55
+
56
+ return msg, input_df
57
+
58
+ demo = gr.Interface(
59
+ fn=predict,
60
+ inputs=[
61
+ gr.Number(label="Engine RPM"),
62
+ gr.Number(label="Lub Oil Pressure"),
63
+ gr.Number(label="Fuel Pressure"),
64
+ gr.Number(label="Coolant Pressure"),
65
+ gr.Number(label="Lub Oil Temperature"),
66
+ gr.Number(label="Coolant Temperature"),
67
+ ],
68
+ outputs=[
69
+ gr.Textbox(label="Prediction Result"),
70
+ gr.Dataframe(label="Input Data (saved as DataFrame)")
71
+ ],
72
+ title="Predictive Maintenance – Engine Health",
73
+ description="Enter engine sensor readings to predict whether maintenance is needed."
74
+ )
75
+
76
+ if __name__ == "__main__":
77
+ demo.launch(server_name="0.0.0.0", server_port=7860)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ scikit-learn
4
+ joblib
5
+ huggingface_hub