ShanRaja commited on
Commit
ae5b70e
·
verified ·
1 Parent(s): 346a9e6

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. Dockerfile +15 -0
  2. README.md +31 -7
  3. app.py +61 -0
  4. push_to_hf.py +32 -0
  5. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a minimal base image with Python 3.9 installed
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory inside the container to /app
5
+ WORKDIR /app
6
+
7
+ # Copy all files from the current directory on the host to the container's /app directory
8
+ COPY . .
9
+
10
+ # Install Python dependencies listed in requirements.txt
11
+ RUN pip3 install -r requirements.txt
12
+
13
+ # Define the command to run the Streamlit app on port 8501 and make it accessible externally
14
+ # CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
15
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
README.md CHANGED
@@ -1,11 +1,35 @@
1
  ---
2
- title: Engine Condition Prediction Space
3
- emoji: 📊
4
- colorFrom: gray
5
- colorTo: yellow
6
  sdk: docker
7
- pinned: false
8
- short_description: Engine-Condition-Prediction-Space
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Engine Condition Prediction
 
 
 
3
  sdk: docker
 
 
4
  ---
5
 
6
+ # Engine Condition Prediction
7
+
8
+ This Streamlit application predicts the **engine condition (Normal or Faulty)** using an **XGBoost machine learning model**.
9
+
10
+ ## Model Details
11
+ - **Algorithm**: XGBoost Classifier
12
+ - **Model Source**: Hugging Face Model Hub
13
+ - **Input Features**:
14
+ - Engine rpm
15
+ - Lub oil pressure
16
+ - Fuel pressure
17
+ - Coolant pressure
18
+ - lub oil temp
19
+ - Coolant temp
20
+
21
+ ## How It Works
22
+ 1. User enters real-time engine sensor values.
23
+ 2. The app loads a pre-trained XGBoost model from Hugging Face.
24
+ 3. The model predicts the engine condition.
25
+ 4. Inputs and predictions are stored in a CSV file for logging.
26
+
27
+ ## Deployment
28
+ - **Framework**: Streamlit
29
+ - **Containerized with**: Docker
30
+ - **Hosted on**: Hugging Face Spaces
31
+
32
+ ## Dependencies
33
+ All dependencies are defined in `requirements.txt` and installed during Docker build.
34
+
35
+ ---
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ st.set_page_config(page_title="Engine Condition Prediction")
7
+
8
+ @st.cache_resource
9
+ def load_model():
10
+ model_path = hf_hub_download(
11
+ repo_id="ShanRaja/engine-fault-xgboost",
12
+ filename="best_model.joblib"
13
+ )
14
+ return joblib.load(model_path)
15
+
16
+ model = load_model()
17
+
18
+ st.title("Engine Condition Prediction")
19
+
20
+ engine_rpm = st.number_input("Engine rpm", min_value=0, step=100)
21
+ lub_oil_pressure = st.number_input("Lub oil pressure", format="%.3f")
22
+ fuel_pressure = st.number_input("Fuel pressure", format="%.3f")
23
+ coolant_pressure = st.number_input("Coolant pressure", format="%.3f")
24
+ lub_oil_temp = st.number_input("lub oil temp", format="%.2f")
25
+ coolant_temp = st.number_input("Coolant temp", format="%.2f")
26
+
27
+ if st.button("Predict"):
28
+ input_df = pd.DataFrame(
29
+ [[
30
+ int(engine_rpm),
31
+ lub_oil_pressure,
32
+ fuel_pressure,
33
+ coolant_pressure,
34
+ lub_oil_temp,
35
+ coolant_temp
36
+ ]],
37
+ columns=[
38
+ "Engine rpm",
39
+ "Lub oil pressure",
40
+ "Fuel pressure",
41
+ "Coolant pressure",
42
+ "lub oil temp",
43
+ "Coolant temp"
44
+ ]
45
+ )
46
+
47
+ prediction = model.predict(input_df)[0]
48
+
49
+ label = "NORMAL" if prediction == 1 else "FAULTY"
50
+
51
+ st.success(f"Engine Condition: {label}")
52
+
53
+ # Save input + prediction
54
+ input_df["Engine Condition"] = prediction
55
+ input_df.to_csv(
56
+ "inputs.csv",
57
+ mode="a",
58
+ header=not st.session_state.get("logged", False),
59
+ index=False
60
+ )
61
+ st.session_state["logged"] = True
push_to_hf.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi, upload_folder
2
+
3
+ # HUGGING FACE CONFIGURATION
4
+ HF_USERNAME = "ShanRaja"
5
+ SPACE_NAME = "Engine-Condition-Prediction-Space" # Name of the HF Space
6
+
7
+ REPO_ID = f"{HF_USERNAME}/{SPACE_NAME}"
8
+
9
+ # CREATE OR UPDATE THE HF SPACE
10
+ api = HfApi()
11
+
12
+ print("Creating or updating Hugging Face Space...")
13
+
14
+ api.create_repo(
15
+ repo_id=REPO_ID,
16
+ repo_type="space",
17
+ space_sdk="docker",
18
+ exist_ok=True
19
+ )
20
+
21
+ # UPLOAD DEPLOYMENT FILES
22
+ print("Uploading deployment files...")
23
+
24
+ upload_folder(
25
+ folder_path="deployment_files",
26
+ repo_id=REPO_ID,
27
+ repo_type="space",
28
+ #ignore_patterns=["__pycache__", "*.ipynb"]
29
+ )
30
+
31
+ print("Deployment completed successfully!")
32
+ print(f" The Application is live at: https://huggingface.co/spaces/{REPO_ID}")
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ pandas==2.2.2
2
+ numpy==2.0.2
3
+ scikit-learn==1.6.1
4
+ xgboost==2.1.4
5
+ joblib==1.5.3
6
+ streamlit==1.53.0
7
+ huggingface_hub==0.27.1