antcar0929 commited on
Commit
37b478d
Β·
verified Β·
1 Parent(s): 3807a67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -3
app.py CHANGED
@@ -1,9 +1,28 @@
1
  import gradio as gr
2
  import tensorflow as tf
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,7 +62,7 @@ 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
- # 2. Build the UI using Blocks (Standard Theme)
47
  with gr.Blocks() as demo:
48
  gr.Markdown("# HK-TransitFlow-Net Demo 🚌")
49
  gr.Markdown("Live inference for HK Bus ETA prediction.")
@@ -55,7 +74,15 @@ with gr.Blocks() as demo:
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
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
4
+ import requests
5
  from huggingface_hub import hf_hub_download
6
 
7
+ # --- 1. Fetch Route Options for Dropdown ---
8
+ print("Fetching route list for dropdown...")
9
+ try:
10
+ resp = requests.get("https://hkbus.github.io/hk-bus-crawling/routeFareList.min.json")
11
+ if resp.status_code == 200:
12
+ data = resp.json()
13
+ # Get all keys (e.g. "968+1+Yuen Long+Tin Hau")
14
+ # We sort them so they are easy to find
15
+ all_routes = sorted(list(data['routeList'].keys()))
16
+ else:
17
+ all_routes = []
18
+ except Exception as e:
19
+ print(f"Error fetching routes: {e}")
20
+ all_routes = []
21
+
22
+ # Add "UNKNOWN" as the first/default option
23
+ route_choices = ["UNKNOWN"] + all_routes
24
+
25
+ # --- 2. Download and Load Model ---
26
  print("Downloading model...")
27
  model_path = hf_hub_download(repo_id="WheelsTransit/HK-TransitFlow-Net", filename="hk_transit_flow_net.keras")
28
 
 
62
  except Exception as e:
63
  return f"Error: {str(e)}"
64
 
65
+ # --- 3. Build the UI ---
66
  with gr.Blocks() as demo:
67
  gr.Markdown("# HK-TransitFlow-Net Demo 🚌")
68
  gr.Markdown("Live inference for HK Bus ETA prediction.")
 
74
  stops_input = gr.Number(label="Number of Stops", value=10)
75
  hour_input = gr.Slider(minimum=0, maximum=23, step=1, label="Hour of Day (0-23)", value=9)
76
  day_input = gr.Dropdown(choices=list(DAY_MAP.keys()), label="Day of Week", value="Monday")
77
+
78
+ # UPDATED: Dropdown with search capabilities
79
+ route_input = gr.Dropdown(
80
+ choices=route_choices,
81
+ label="Route ID",
82
+ value="UNKNOWN",
83
+ filterable=True, # Allows typing to search
84
+ interactive=True
85
+ )
86
 
87
  predict_btn = gr.Button("Predict ETA", variant="primary")
88