curiouscurrent commited on
Commit
ceb7230
·
verified ·
1 Parent(s): 5e04fd1

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import pandas as pd
4
+
5
+ # Load trained XGBoost model
6
+ with open("xgboost_trip_delay_model.pkl", "rb") as f:
7
+ model = pickle.load(f)
8
+
9
+ # Define the prediction function for Gradio
10
+ def predict_bus_delay(route_id, trip_direction, speed, trip_delay_y, hour, minute, last_stop_arrival_seconds):
11
+ data = pd.DataFrame({
12
+ "route_id": [route_id],
13
+ "trip_direction": [1 if trip_direction == "UP" else 0],
14
+ "speed": [float(speed)],
15
+ "trip_delay_y": [float(trip_delay_y)],
16
+ "hour": [int(hour)],
17
+ "minute": [int(minute)],
18
+ "last_stop_arrival_seconds": [int(last_stop_arrival_seconds)]
19
+ })
20
+
21
+ data["route_id"] = data["route_id"].astype("category")
22
+
23
+ # Make prediction
24
+ prediction = model.predict(data)[0]
25
+ return f"Predicted Bus Delay Between Stops: {prediction:.2f} seconds"
26
+
27
+ # Create Gradio interface
28
+ interface = gr.Interface(
29
+ fn=predict_bus_delay,
30
+ inputs=[
31
+ gr.Textbox(label="Route ID"),
32
+ gr.Dropdown(label="Direction", choices=["UP", "DN"]),
33
+ gr.Number(label="Speed"),
34
+ gr.Number(label="Previous Stop Delay"),
35
+ gr.Number(label="Hour"),
36
+ gr.Number(label="Minute"),
37
+ gr.Number(label="Last Stop Arrival (s)")
38
+ ],
39
+ outputs="text"
40
+ )
41
+
42
+ # Launch the Gradio interface
43
+ interface.launch()