Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,29 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
import pickle
|
| 4 |
import numpy as np
|
| 5 |
from sklearn.preprocessing import StandardScaler
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def predict(feature1, feature2, feature3, feature4, feature5):
|
| 14 |
-
model = load_model()
|
| 15 |
-
raw = np.array([[feature1, feature2, feature3, feature4, feature5]])
|
| 16 |
-
# Standardize features (must match training preprocessing)
|
| 17 |
-
scaler = StandardScaler()
|
| 18 |
-
scaled = scaler.fit_transform(raw)
|
| 19 |
-
return int(model.predict(scaled)[0])
|
| 20 |
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
-
gr.Markdown("## 🐨
|
| 23 |
with gr.Row():
|
| 24 |
-
f1 = gr.Slider(0, 10, value=5, label="Feature
|
| 25 |
-
f2 = gr.Slider(0, 10, value=3, label="Feature
|
| 26 |
with gr.Row():
|
| 27 |
-
f3 = gr.Slider(0, 10, value=7, label="Feature
|
| 28 |
-
f4 = gr.Slider(0, 10, value=6, label="Feature
|
| 29 |
-
f5 = gr.Slider(0, 10, value=4, label="Feature
|
| 30 |
btn = gr.Button("Predict")
|
| 31 |
out = gr.Textbox(label="Prediction")
|
| 32 |
-
|
| 33 |
btn.click(fn=predict, inputs=[f1, f2, f3, f4, f5], outputs=out)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pickle
|
| 3 |
import numpy as np
|
| 4 |
from sklearn.preprocessing import StandardScaler
|
| 5 |
|
| 6 |
+
# Load model once at startup
|
| 7 |
+
with open("rf_model.pkl", "rb") as f:
|
| 8 |
+
MODEL = pickle.load(f)
|
| 9 |
|
| 10 |
+
def predict(f1, f2, f3, f4, f5):
|
| 11 |
+
arr = np.array([[f1, f2, f3, f4, f5]])
|
| 12 |
+
scaled = StandardScaler().fit_transform(arr)
|
| 13 |
+
return str(MODEL.predict(scaled)[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
+
gr.Markdown("## 🐨 TaskMaster Job Scheduler")
|
| 17 |
with gr.Row():
|
| 18 |
+
f1 = gr.Slider(0, 10, value=5, label="Feature 1")
|
| 19 |
+
f2 = gr.Slider(0, 10, value=3, label="Feature 2")
|
| 20 |
with gr.Row():
|
| 21 |
+
f3 = gr.Slider(0, 10, value=7, label="Feature 3")
|
| 22 |
+
f4 = gr.Slider(0, 10, value=6, label="Feature 4")
|
| 23 |
+
f5 = gr.Slider(0, 10, value=4, label="Feature 5")
|
| 24 |
btn = gr.Button("Predict")
|
| 25 |
out = gr.Textbox(label="Prediction")
|
|
|
|
| 26 |
btn.click(fn=predict, inputs=[f1, f2, f3, f4, f5], outputs=out)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
+
demo.launch() # no server_name/port flags needed on Spaces
|