File size: 1,399 Bytes
9ce3905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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()