manjuprasads's picture
Add Gradio inference app
9ce3905 verified
import gradio as gr
import joblib
import pandas as pd
from huggingface_hub import hf_hub_download
# Download model from Hugging Face Model Hub
model_path = hf_hub_download(
repo_id="manjuprasads/predictive-maintenance-random-forest",
filename="tuned_random_forest_model.pkl"
)
model = joblib.load(model_path)
def predict_engine_condition(
engine_rpm,
lub_oil_pressure,
fuel_pressure,
coolant_pressure,
lub_oil_temp,
coolant_temp
):
data = pd.DataFrame([{
"engine_rpm": engine_rpm,
"lub_oil_pressure": lub_oil_pressure,
"fuel_pressure": fuel_pressure,
"coolant_pressure": coolant_pressure,
"lub_oil_temp": lub_oil_temp,
"coolant_temp": coolant_temp
}])
prediction = model.predict(data)[0]
return "Maintenance Required" if prediction == 1 else "Normal Operation"
demo = gr.Interface(
fn=predict_engine_condition,
inputs=[
gr.Number(label="Engine RPM"),
gr.Number(label="Lubricating Oil Pressure"),
gr.Number(label="Fuel Pressure"),
gr.Number(label="Coolant Pressure"),
gr.Number(label="Lubricating Oil Temperature"),
gr.Number(label="Coolant Temperature"),
],
outputs="text",
title="Predictive Maintenance – Engine Health",
description="Enter engine sensor values to predict whether maintenance is required."
)
demo.launch()