antcar0929 commited on
Commit
f4f7cd3
·
verified ·
1 Parent(s): e4b324d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -17
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
- # --- FIX: Download and Load Manually ---
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
- iface = gr.Interface(
48
- fn=predict_eta,
49
- inputs=[
50
- gr.Number(label="Distance (meters)", value=5000),
51
- gr.Number(label="Number of Stops", value=10),
52
- gr.Slider(minimum=0, maximum=23, step=1, label="Hour of Day (0-23)", value=9),
53
- gr.Dropdown(choices=list(DAY_MAP.keys()), label="Day of Week", value="Monday"),
54
- gr.Textbox(label="Route ID", placeholder="968+1+...", value="UNKNOWN")
55
- ],
56
- outputs="text",
57
- title="HK-TransitFlow-Net Demo",
58
- description="Live inference for HK Bus ETA prediction.",
59
- theme="soft"
60
- )
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- iface.launch()
 
 
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()