import pickle import pandas as pd import gradio as gr path = "/content/drive/MyDrive/KSA/data/" data = pd.read_csv("Schedules_Train.csv") model = pickle.load(open("rf.pkl", "rb")) features = model[0].get_feature_names() features_cat = [m['col'] for m in model[0].mapping] def estimate_duration(*args): print(args) return model.predict(pd.DataFrame([args], columns=features)).round(2) with gr.Blocks(title="Remaining Duration Estimator", css="footer {visibility: hidden}") as demo: inputs = [] for f in features: if f in features_cat: uniques = data[f].unique().tolist() input = gr.Dropdown(uniques, value=uniques[0], label=f) else: input = gr.Slider(data[f].min(), data[f].max(), label=f) inputs.append(input) btn = gr.Button("Estimate Remaining Duration") output = gr.Number(label="Estimated Remaining Duration") btn.click(fn=estimate_duration, inputs=inputs, outputs=output) gr.Examples(data[features].sample(n = 10).values.tolist(), fn=estimate_duration, inputs=inputs, outputs=output, cache_examples=True) demo.launch(debug=False, show_api=False)