Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import tensorflow as tf
|
|
| 3 |
import numpy as np
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
-
#
|
| 7 |
print("Downloading model...")
|
| 8 |
model_path = hf_hub_download(repo_id="WheelsTransit/HK-TransitFlow-Net", filename="hk_transit_flow_net.keras")
|
| 9 |
|
|
@@ -43,20 +43,32 @@ def predict_eta(distance_meters, num_stops, hour, day_name, route_id):
|
|
| 43 |
except Exception as e:
|
| 44 |
return f"Error: {str(e)}"
|
| 45 |
|
| 46 |
-
# Build the Interface
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
gr.
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
+
# 1. Download and Load Model
|
| 7 |
print("Downloading model...")
|
| 8 |
model_path = hf_hub_download(repo_id="WheelsTransit/HK-TransitFlow-Net", filename="hk_transit_flow_net.keras")
|
| 9 |
|
|
|
|
| 43 |
except Exception as e:
|
| 44 |
return f"Error: {str(e)}"
|
| 45 |
|
| 46 |
+
# 2. Build the UI using Blocks (More stable than Interface)
|
| 47 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 48 |
+
gr.Markdown("# HK-TransitFlow-Net Demo 🚌")
|
| 49 |
+
gr.Markdown("Live inference for HK Bus ETA prediction.")
|
| 50 |
+
|
| 51 |
+
with gr.Row():
|
| 52 |
+
with gr.Column():
|
| 53 |
+
# Inputs
|
| 54 |
+
dist_input = gr.Number(label="Distance (meters)", value=5000)
|
| 55 |
+
stops_input = gr.Number(label="Number of Stops", value=10)
|
| 56 |
+
hour_input = gr.Slider(minimum=0, maximum=23, step=1, label="Hour of Day (0-23)", value=9)
|
| 57 |
+
day_input = gr.Dropdown(choices=list(DAY_MAP.keys()), label="Day of Week", value="Monday")
|
| 58 |
+
route_input = gr.Textbox(label="Route ID (Optional)", placeholder="968+1+...", value="UNKNOWN")
|
| 59 |
+
|
| 60 |
+
predict_btn = gr.Button("Predict ETA", variant="primary")
|
| 61 |
+
|
| 62 |
+
with gr.Column():
|
| 63 |
+
# Output
|
| 64 |
+
output_text = gr.Textbox(label="Estimated Travel Time", lines=1)
|
| 65 |
+
|
| 66 |
+
# Event Listener
|
| 67 |
+
predict_btn.click(
|
| 68 |
+
fn=predict_eta,
|
| 69 |
+
inputs=[dist_input, stops_input, hour_input, day_input, route_input],
|
| 70 |
+
outputs=output_text
|
| 71 |
+
)
|
| 72 |
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
demo.launch()
|