madhavkarthi commited on
Commit
1687d11
·
verified ·
1 Parent(s): fdb5dbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -7,9 +7,9 @@ import zipfile
7
  import pathlib
8
  import shutil
9
 
10
- # -------------------------------------------------------
11
- # 1) Load the AutoGluon predictor (pickled .pkl file)
12
- # -------------------------------------------------------
13
  pkl_path = hf_hub_download(
14
  repo_id="cassieli226/hw2-airline-automl",
15
  filename="autogluon_predictor.pkl",
@@ -19,9 +19,9 @@ pkl_path = hf_hub_download(
19
  with open(pkl_path, "rb") as f:
20
  predictor = cloudpickle.load(f)
21
 
22
- # -------------------------------------------------------
23
- # 2) load predictor from zipped directory for leaderboard
24
- # -------------------------------------------------------
25
  zip_path = hf_hub_download(
26
  repo_id="cassieli226/hw2-airline-automl",
27
  filename="autogluon_predictor_dir.zip",
@@ -35,12 +35,11 @@ if extract_dir.exists():
35
  with zipfile.ZipFile(zip_path, "r") as zf:
36
  zf.extractall(str(extract_dir))
37
 
38
- # Load predictor directory (if needed)
39
  predictor_dir = ag.TabularPredictor.load(str(extract_dir))
40
 
41
- # -------------------------------------------------------
42
- # 3) Define Gradio interface
43
- # -------------------------------------------------------
44
  def predict_flight(stops, days_from_departure, flight_time, price, day_of_week, destination):
45
  X = pd.DataFrame({
46
  "Stops": [stops],
@@ -52,9 +51,12 @@ def predict_flight(stops, days_from_departure, flight_time, price, day_of_week,
52
  })
53
  return predictor.predict(X)[0]
54
 
 
 
 
55
  with gr.Blocks() as demo:
56
  gr.Markdown("# Flight Duration Predictor")
57
-
58
  with gr.Row():
59
  with gr.Column():
60
  stops_in = gr.Slider("Stops", 0, 3, 1)
@@ -74,7 +76,7 @@ with gr.Blocks() as demo:
74
  outputs=[output]
75
  )
76
 
77
- # -------------------------------------------------------
78
- # 4) Launch app
79
- # -------------------------------------------------------
80
  demo.launch()
 
7
  import pathlib
8
  import shutil
9
 
10
+ # -----------------------------
11
+ # 1) Load pickled AutoGluon predictor
12
+ # -----------------------------
13
  pkl_path = hf_hub_download(
14
  repo_id="cassieli226/hw2-airline-automl",
15
  filename="autogluon_predictor.pkl",
 
19
  with open(pkl_path, "rb") as f:
20
  predictor = cloudpickle.load(f)
21
 
22
+ # -----------------------------
23
+ # 2) load predictor directory for leaderboard
24
+ # -----------------------------
25
  zip_path = hf_hub_download(
26
  repo_id="cassieli226/hw2-airline-automl",
27
  filename="autogluon_predictor_dir.zip",
 
35
  with zipfile.ZipFile(zip_path, "r") as zf:
36
  zf.extractall(str(extract_dir))
37
 
 
38
  predictor_dir = ag.TabularPredictor.load(str(extract_dir))
39
 
40
+ # -----------------------------
41
+ # 3) Gradio interface function
42
+ # -----------------------------
43
  def predict_flight(stops, days_from_departure, flight_time, price, day_of_week, destination):
44
  X = pd.DataFrame({
45
  "Stops": [stops],
 
51
  })
52
  return predictor.predict(X)[0]
53
 
54
+ # -----------------------------
55
+ # 4) Gradio UI
56
+ # -----------------------------
57
  with gr.Blocks() as demo:
58
  gr.Markdown("# Flight Duration Predictor")
59
+
60
  with gr.Row():
61
  with gr.Column():
62
  stops_in = gr.Slider("Stops", 0, 3, 1)
 
76
  outputs=[output]
77
  )
78
 
79
+ # -----------------------------
80
+ # 5) Launch
81
+ # -----------------------------
82
  demo.launch()