File size: 1,920 Bytes
5954406
828ac93
 
 
 
 
 
 
 
f43c1fe
828ac93
 
 
f43c1fe
 
 
 
 
 
 
 
5954406
 
 
 
 
 
 
 
 
 
 
f43c1fe
 
 
 
5954406
 
 
 
 
 
 
 
f43c1fe
 
 
5954406
828ac93
 
 
f43c1fe
 
 
 
828ac93
 
 
 
927e6bd
828ac93
 
 
f43c1fe
927e6bd
 
 
828ac93
f43c1fe
 
37c8519
f43c1fe
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
import math
import spaces
import gradio as gr
import joblib
import pandas as pd

model = joblib.load("Machine_Failure_Model.pkl")


def health_check() -> dict:
    return {"status": "online", "message": "nihal is here"}


def predict_failure(

    machine_type: str,

    air_temp: float,

    process_temp: float,

    rpm: int,

    torque: float,

    tool_wear: int,

) -> dict:
    air_temp = float(air_temp)
    process_temp = float(process_temp)
    rpm = int(rpm)
    torque = float(torque)
    tool_wear = int(tool_wear)

    # Compute the 3 engineered features expected by the trained pipeline
    temp_diff = process_temp - air_temp
    power_w = torque * (rpm * 2 * math.pi / 60)
    overstrain = tool_wear * torque

    input_row = pd.DataFrame(
        [
            {
                "Type": machine_type,
                "Air temperature [K]": air_temp,
                "Process temperature [K]": process_temp,
                "Rotational speed [rpm]": rpm,
                "Torque [Nm]": torque,
                "Tool wear [min]": tool_wear,
                "Temp_diff": temp_diff,
                "Power_W": power_w,
                "Overstrain": overstrain,
            }
        ]
    )

    prediction = int(model.predict(input_row)[0])
    probability = round(float(model.predict_proba(input_row)[0][1]), 2)

    return {
        "machine_failure_prediction": prediction,
        "failure_probability": probability,
    }


@spaces.GPU
def warmup():
    return "ZeroGPU Hook Active"


with gr.Blocks() as demo:
    gr.Markdown("### Aegis CNC Predictive Maintenance API")
    btn = gr.Button("Check ZeroGPU Hook")
    out = gr.Textbox(label="Status")
    btn.click(fn=warmup, outputs=out)

    gr.api(health_check, api_name="health")
    gr.api(predict_failure, api_name="predict")

demo.launch(server_name="0.0.0.0", server_port=7860)