File size: 1,039 Bytes
69fa4c1 48e2b49 744a605 ca73ae5 20f37db ca73ae5 744a605 8485fd5 744a605 f1af5bc 744a605 |
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 |
import gradio as gr
import pickle
import numpy as np
from sklearn.preprocessing import StandardScaler
# Load the pre-trained model at startup
with open("rf_model.pkl", "rb") as f:
MODEL = pickle.load(f)
def predict(f1, f2, f3, f4, f5):
data = np.array([[f1, f2, f3, f4, f5]])
scaled = StandardScaler().fit_transform(data)
return int(MODEL.predict(scaled)[0])
if __name__ == "__main__":
demo = gr.Interface(
fn=predict,
inputs=[
gr.Slider(0, 10, value=5, label="Feature 1"),
gr.Slider(0, 10, value=3, label="Feature 2"),
gr.Slider(0, 10, value=7, label="Feature 3"),
gr.Slider(0, 10, value=6, label="Feature 4"),
gr.Slider(0, 10, value=4, label="Feature 5"),
],
outputs=gr.Textbox(label="Prediction"),
title="🐨 TaskMaster Job Scheduler",
description="Enter five features and get a RandomForest prediction.",
)
demo.launch() # on Spaces, this binds to 0.0.0.0:7860 and blocks the process
|