Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
import joblib
|
|
@@ -18,18 +19,33 @@ def predict_failure(
|
|
| 18 |
torque: float,
|
| 19 |
tool_wear: int,
|
| 20 |
) -> dict:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
input_row = pd.DataFrame(
|
| 22 |
[
|
| 23 |
{
|
| 24 |
"Type": machine_type,
|
| 25 |
-
"Air temperature [K]":
|
| 26 |
-
"Process temperature [K]":
|
| 27 |
-
"Rotational speed [rpm]":
|
| 28 |
-
"Torque [Nm]":
|
| 29 |
-
"Tool wear [min]":
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
]
|
| 32 |
)
|
|
|
|
| 33 |
prediction = int(model.predict(input_row)[0])
|
| 34 |
probability = round(float(model.predict_proba(input_row)[0][1]), 2)
|
| 35 |
|
|
@@ -50,7 +66,6 @@ with gr.Blocks() as demo:
|
|
| 50 |
out = gr.Textbox(label="Status")
|
| 51 |
btn.click(fn=warmup, outputs=out)
|
| 52 |
|
| 53 |
-
# Native Gradio REST API endpoints
|
| 54 |
gr.api(health_check, api_name="health")
|
| 55 |
gr.api(predict_failure, api_name="predict")
|
| 56 |
|
|
|
|
| 1 |
+
import math
|
| 2 |
import spaces
|
| 3 |
import gradio as gr
|
| 4 |
import joblib
|
|
|
|
| 19 |
torque: float,
|
| 20 |
tool_wear: int,
|
| 21 |
) -> dict:
|
| 22 |
+
air_temp = float(air_temp)
|
| 23 |
+
process_temp = float(process_temp)
|
| 24 |
+
rpm = int(rpm)
|
| 25 |
+
torque = float(torque)
|
| 26 |
+
tool_wear = int(tool_wear)
|
| 27 |
+
|
| 28 |
+
# Compute the 3 engineered features expected by the trained pipeline
|
| 29 |
+
temp_diff = process_temp - air_temp
|
| 30 |
+
power_w = torque * (rpm * 2 * math.pi / 60)
|
| 31 |
+
overstrain = tool_wear * torque
|
| 32 |
+
|
| 33 |
input_row = pd.DataFrame(
|
| 34 |
[
|
| 35 |
{
|
| 36 |
"Type": machine_type,
|
| 37 |
+
"Air temperature [K]": air_temp,
|
| 38 |
+
"Process temperature [K]": process_temp,
|
| 39 |
+
"Rotational speed [rpm]": rpm,
|
| 40 |
+
"Torque [Nm]": torque,
|
| 41 |
+
"Tool wear [min]": tool_wear,
|
| 42 |
+
"Temp_diff": temp_diff,
|
| 43 |
+
"Power_W": power_w,
|
| 44 |
+
"Overstrain": overstrain,
|
| 45 |
}
|
| 46 |
]
|
| 47 |
)
|
| 48 |
+
|
| 49 |
prediction = int(model.predict(input_row)[0])
|
| 50 |
probability = round(float(model.predict_proba(input_row)[0][1]), 2)
|
| 51 |
|
|
|
|
| 66 |
out = gr.Textbox(label="Status")
|
| 67 |
btn.click(fn=warmup, outputs=out)
|
| 68 |
|
|
|
|
| 69 |
gr.api(health_check, api_name="health")
|
| 70 |
gr.api(predict_failure, api_name="predict")
|
| 71 |
|