File size: 3,756 Bytes
6315bd7
 
 
 
39a46ae
1a089b7
 
6315bd7
1a089b7
 
6315bd7
39a46ae
51b3680
39a46ae
6315bd7
 
 
 
 
 
 
1a089b7
 
 
6315bd7
1a089b7
 
6315bd7
1a089b7
 
6315bd7
 
 
1a089b7
39a46ae
1a089b7
 
 
39a46ae
1a089b7
39a46ae
1a089b7
39a46ae
6315bd7
 
39a46ae
 
6315bd7
39a46ae
1a089b7
39a46ae
6315bd7
 
39a46ae
6315bd7
1a089b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39a46ae
1a089b7
 
 
 
 
 
 
 
 
 
 
39a46ae
 
 
 
 
1a089b7
 
 
 
 
 
6315bd7
 
39a46ae
 
 
1a089b7
 
39a46ae
1a089b7
 
 
 
39a46ae
1a089b7
 
 
 
 
 
39a46ae
1a089b7
 
39a46ae
1a089b7
39a46ae
1a089b7
 
 
 
 
39a46ae
1a089b7
39a46ae
6315bd7
39a46ae
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import gradio as gr
import pandas as pd
import pickle

# ------------------ Load Model ------------------
with open("logistic_regression_model.pkl", "rb") as f:
    model = pickle.load(f)

with open("feature_columns.pkl", "rb") as f:
    feature_columns = pickle.load(f)

# ------------------ Prediction Function ------------------
def predict_status(air_temp, proc_temp, speed, torque, tool_wear):

    sample_input = {
        "Air temperature [K]": air_temp,
        "Process temperature [K]": proc_temp,
        "Rotational speed [rpm]": speed,
        "Torque [Nm]": torque,
        "Tool wear [min]": tool_wear
    }

    df = pd.DataFrame([sample_input])

    for col in feature_columns:
        if col not in df.columns:
            df[col] = 0

    df = df[feature_columns]
    prediction = model.predict(df)[0]

    reasons = []

    if air_temp < 150 or air_temp > 500:
        reasons.append("Air temperature outside optimal range (150–500 K).")
    if proc_temp < 150 or proc_temp > 500:
        reasons.append("Process temperature not within safe limits.")
    if speed < 500 or speed > 1500:
        reasons.append("Rotational speed is outside recommended range.")
    if torque < 100 or torque > 800:
        reasons.append("Torque level may damage machine components.")
    if tool_wear > 300:
        reasons.append("Tool wear is high — maintenance required.")

    if prediction == 0:
        message = "❌ **Machine Status: NOT OPERATIONAL**\n\n"
        message += "\n".join([f"- {r}" for r in reasons]) if reasons else "- No clear fault detected."
    else:
        message = "✅ **Machine Status: OPERATING NORMALLY**\n\nAll parameters are within acceptable ranges."

    return message


# ------------------ Professional CSS ------------------
custom_css = """
body {
    background-color: #0f172a;
}

.gradio-container {
    max-width: 1100px;
    margin: auto;
    padding: 32px;
    background: #020617;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

h1 {
    text-align: center;
    font-size: 32px;
    color: #e5e7eb;
}

.subtitle {
    text-align: center;
    color: #94a3b8;
    margin-bottom: 32px;
}

.panel {
    background: #020617;
    border: 1px solid #1e293b;
    border-radius: 14px;
    padding: 24px;
}

label {
    color: #cbd5f5 !important;
    font-weight: 600;
}

.output-box {
    min-height: 240px;
    font-size: 16px;
}

footer {
    text-align: center;
    color: #64748b;
    font-size: 13px;
    margin-top: 24px;
}
"""

# ------------------ Gradio Layout ------------------
with gr.Blocks(css=custom_css) as app:

    gr.Markdown(
        "<h1>Smart Machine Health Predictor</h1>"
        "<div class='subtitle'>Industrial Machine Failure Prediction System</div>"
    )

    with gr.Row():
        with gr.Column(scale=1):
            with gr.Group(elem_classes="panel"):
                air = gr.Slider(0, 1000, value=300, label="Air Temperature (K)")
                proc = gr.Slider(0, 1000, value=300, label="Process Temperature (K)")
                speed = gr.Slider(0, 2000, value=1000, label="Rotational Speed (rpm)")
                torque = gr.Slider(0, 1000, value=500, label="Torque (Nm)")
                wear = gr.Slider(0, 1000, value=100, label="Tool Wear (min)")

                predict_btn = gr.Button("Run Prediction", variant="primary")

        with gr.Column(scale=1):
            output = gr.Markdown(elem_classes="panel output-box")

    predict_btn.click(
        predict_status,
        inputs=[air, proc, speed, torque, wear],
        outputs=output
    )

    gr.Markdown("<footer>Built with Gradio • Predictive Maintenance Dashboard</footer>")

# ------------------ Launch ------------------
if __name__ == "__main__":
    app.launch()