VeerendraManikonda's picture
Upload folder using huggingface_hub
04bef9b verified
import streamlit as st
import requests
# --- Streamlit App Configuration ---
st.set_page_config(
page_title="Predictive Maintenance for Engine Health",
page_icon="⚙️",
layout="centered",
initial_sidebar_state="expanded",
)
st.title("⚙️ Predictive Maintenance for Engine Health")
st.markdown("### Predict if an engine is Normal or Faulty based on sensor readings")
# --- Input Fields for Sensor Data ---
st.subheader("Engine Sensor Readings")
# Using st.number_input for numerical inputs with appropriate ranges and step
engine_rpm = st.number_input(
"Engine RPM", min_value=0.0, max_value=3000.0, value=700.0, step=10.0,
help="Revolutions per minute of the engine (RPM)"
)
lub_oil_pressure = st.number_input(
"Lub Oil Pressure (bar/kPa)", min_value=0.0, max_value=10.0, value=2.5, step=0.1,
help="Pressure of the lubricating oil"
)
fuel_pressure = st.number_input(
"Fuel Pressure (bar/kPa)", min_value=0.0, max_value=30.0, value=12.0, step=0.1,
help="Pressure at which fuel is supplied to the engine"
)
coolant_pressure = st.number_input(
"Coolant Pressure (bar/kPa)", min_value=0.0, max_value=10.0, value=3.0, step=0.1,
help="Pressure of the engine coolant"
)
lub_oil_temperature = st.number_input(
"Lub Oil Temperature (°C)", min_value=0.0, max_value=150.0, value=85.0, step=0.5,
help="Temperature of the lubricating oil"
)
coolant_temperature = st.number_input(
"Coolant Temperature (°C)", min_value=0.0, max_value=150.0, value=80.0, step=0.5,
help="Temperature of the engine coolant"
)
# --- Prediction Button and Logic ---
# Replace with the actual URL of your deployed backend API
# For local testing, it might be something like "http://localhost:5000"
# For Hugging Face Spaces, it will be the URL of your Docker Space
BACKEND_API_URL = "https://veerendramanikonda-predictivemaintenancebackend.hf.space/v1/engine_condition_prediction"
if st.button("Predict Engine Condition", type="primary"):
# Prepare the data payload for the API request
engine_data = {
"Engine_RPM": engine_rpm,
"Lub_Oil_Pressure": lub_oil_pressure,
"Fuel_Pressure": fuel_pressure,
"Coolant_Pressure": coolant_pressure,
"Lub_Oil_Temperature": lub_oil_temperature,
"Coolant_Temperature": coolant_temperature
}
try:
# Make the POST request to the backend API
response = requests.post(BACKEND_API_URL, json=engine_data)
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
prediction = response.json()
st.subheader("Prediction Results:")
predicted_label = prediction['predicted_engine_condition_label']
probability_faulty = prediction['probability_faulty']
probability_normal = prediction['probability_normal']
if predicted_label == "Faulty":
st.error(f"The engine is predicted to be: **{predicted_label}**")
st.write(f"Probability of Faulty: {probability_faulty:.2f}")
st.write(f"Probability of Normal: {probability_normal:.2f}")
st.warning("Immediate maintenance recommended!")
else:
st.success(f"The engine is predicted to be: **{predicted_label}**")
st.write(f"Probability of Normal: {probability_normal:.2f}")
st.write(f"Probability of Faulty: {probability_faulty:.2f}")
st.info("Engine is operating normally.")
except requests.exceptions.ConnectionError:
st.error("Connection Error: Could not connect to the backend API. Please ensure the backend is running and the URL is correct.")
except requests.exceptions.Timeout:
st.error("Timeout Error: The request to the backend API timed out.")
except requests.exceptions.RequestException as e:
st.error(f"An error occurred during the API request: {e}")
except Exception as e:
st.error(f"An unexpected error occurred: {e}")