VeerendraManikonda commited on
Commit
04bef9b
·
verified ·
1 Parent(s): 6ee44ed

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. Dockerfile +9 -13
  2. app.py +92 -0
Dockerfile CHANGED
@@ -1,20 +1,16 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
13
 
 
14
  RUN pip3 install -r requirements.txt
15
 
16
- EXPOSE 8501
17
-
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
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
 
16
+ # NOTE: Disable XSRF protection for easier external access in order to make batch predictions
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ # --- Streamlit App Configuration ---
5
+ st.set_page_config(
6
+ page_title="Predictive Maintenance for Engine Health",
7
+ page_icon="⚙️",
8
+ layout="centered",
9
+ initial_sidebar_state="expanded",
10
+ )
11
+
12
+ st.title("⚙️ Predictive Maintenance for Engine Health")
13
+ st.markdown("### Predict if an engine is Normal or Faulty based on sensor readings")
14
+
15
+ # --- Input Fields for Sensor Data ---
16
+ st.subheader("Engine Sensor Readings")
17
+
18
+ # Using st.number_input for numerical inputs with appropriate ranges and step
19
+ engine_rpm = st.number_input(
20
+ "Engine RPM", min_value=0.0, max_value=3000.0, value=700.0, step=10.0,
21
+ help="Revolutions per minute of the engine (RPM)"
22
+ )
23
+ lub_oil_pressure = st.number_input(
24
+ "Lub Oil Pressure (bar/kPa)", min_value=0.0, max_value=10.0, value=2.5, step=0.1,
25
+ help="Pressure of the lubricating oil"
26
+ )
27
+ fuel_pressure = st.number_input(
28
+ "Fuel Pressure (bar/kPa)", min_value=0.0, max_value=30.0, value=12.0, step=0.1,
29
+ help="Pressure at which fuel is supplied to the engine"
30
+ )
31
+ coolant_pressure = st.number_input(
32
+ "Coolant Pressure (bar/kPa)", min_value=0.0, max_value=10.0, value=3.0, step=0.1,
33
+ help="Pressure of the engine coolant"
34
+ )
35
+ lub_oil_temperature = st.number_input(
36
+ "Lub Oil Temperature (°C)", min_value=0.0, max_value=150.0, value=85.0, step=0.5,
37
+ help="Temperature of the lubricating oil"
38
+ )
39
+ coolant_temperature = st.number_input(
40
+ "Coolant Temperature (°C)", min_value=0.0, max_value=150.0, value=80.0, step=0.5,
41
+ help="Temperature of the engine coolant"
42
+ )
43
+
44
+ # --- Prediction Button and Logic ---
45
+
46
+ # Replace with the actual URL of your deployed backend API
47
+ # For local testing, it might be something like "http://localhost:5000"
48
+ # For Hugging Face Spaces, it will be the URL of your Docker Space
49
+ BACKEND_API_URL = "https://veerendramanikonda-predictivemaintenancebackend.hf.space/v1/engine_condition_prediction"
50
+
51
+ if st.button("Predict Engine Condition", type="primary"):
52
+ # Prepare the data payload for the API request
53
+ engine_data = {
54
+ "Engine_RPM": engine_rpm,
55
+ "Lub_Oil_Pressure": lub_oil_pressure,
56
+ "Fuel_Pressure": fuel_pressure,
57
+ "Coolant_Pressure": coolant_pressure,
58
+ "Lub_Oil_Temperature": lub_oil_temperature,
59
+ "Coolant_Temperature": coolant_temperature
60
+ }
61
+
62
+ try:
63
+ # Make the POST request to the backend API
64
+ response = requests.post(BACKEND_API_URL, json=engine_data)
65
+ response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
66
+ prediction = response.json()
67
+
68
+ st.subheader("Prediction Results:")
69
+ predicted_label = prediction['predicted_engine_condition_label']
70
+ probability_faulty = prediction['probability_faulty']
71
+ probability_normal = prediction['probability_normal']
72
+
73
+ if predicted_label == "Faulty":
74
+ st.error(f"The engine is predicted to be: **{predicted_label}**")
75
+ st.write(f"Probability of Faulty: {probability_faulty:.2f}")
76
+ st.write(f"Probability of Normal: {probability_normal:.2f}")
77
+ st.warning("Immediate maintenance recommended!")
78
+ else:
79
+ st.success(f"The engine is predicted to be: **{predicted_label}**")
80
+ st.write(f"Probability of Normal: {probability_normal:.2f}")
81
+ st.write(f"Probability of Faulty: {probability_faulty:.2f}")
82
+ st.info("Engine is operating normally.")
83
+
84
+ except requests.exceptions.ConnectionError:
85
+ st.error("Connection Error: Could not connect to the backend API. Please ensure the backend is running and the URL is correct.")
86
+ except requests.exceptions.Timeout:
87
+ st.error("Timeout Error: The request to the backend API timed out.")
88
+ except requests.exceptions.RequestException as e:
89
+ st.error(f"An error occurred during the API request: {e}")
90
+ except Exception as e:
91
+ st.error(f"An unexpected error occurred: {e}")
92
+