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)