Spaces:
Runtime error
Runtime error
AhmedAttia
commited on
Commit
•
e07bd64
1
Parent(s):
52f97a8
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import pandas as pd
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
path = "/content/drive/MyDrive/KSA/data/"
|
6 |
+
|
7 |
+
data = pd.read_csv("Schedules_Train.csv")
|
8 |
+
model = pickle.load(open("rf.pkl", "rb"))
|
9 |
+
|
10 |
+
features = model[0].get_feature_names()
|
11 |
+
features_cat = [m['col'] for m in model[0].mapping]
|
12 |
+
|
13 |
+
def estimate_duration(*args):
|
14 |
+
print(args)
|
15 |
+
return model.predict(pd.DataFrame([args], columns=features)).round(2)
|
16 |
+
|
17 |
+
with gr.Blocks(title="Remaining Duration Estimator", css="footer {visibility: hidden}") as demo:
|
18 |
+
inputs = []
|
19 |
+
for f in features:
|
20 |
+
if f in features_cat:
|
21 |
+
uniques = data[f].unique().tolist()
|
22 |
+
input = gr.Dropdown(uniques, value=uniques[0], label=f)
|
23 |
+
else:
|
24 |
+
input = gr.Slider(data[f].min(), data[f].max(), label=f)
|
25 |
+
inputs.append(input)
|
26 |
+
|
27 |
+
btn = gr.Button("Estimate Remaining Duration")
|
28 |
+
output = gr.Number(label="Estimated Remaining Duration")
|
29 |
+
btn.click(fn=estimate_duration, inputs=inputs, outputs=output)
|
30 |
+
gr.Examples(data[features].sample(n = 10).values.tolist(), fn=estimate_duration,
|
31 |
+
inputs=inputs, outputs=output, cache_examples=True)
|
32 |
+
|
33 |
+
demo.launch(debug=False, show_api=False)
|