Spaces:
Sleeping
Sleeping
Jompatron
commited on
Commit
·
1dff66c
1
Parent(s):
3a46c58
sliders
Browse files
app.py
CHANGED
|
@@ -43,9 +43,9 @@ model, feature_view, weather_fg, project = load_resources()
|
|
| 43 |
# -------------------------
|
| 44 |
# FORECAST LOGIC (NEXT 7 DAYS)
|
| 45 |
# -------------------------
|
| 46 |
-
def generate_forecast():
|
| 47 |
today = datetime.utcnow().date()
|
| 48 |
-
future_dates = [(today + timedelta(days=i)).strftime("%Y-%m-%d") for i in range(1,
|
| 49 |
|
| 50 |
df_future = weather_fg.read()
|
| 51 |
df_future["date"] = pd.to_datetime(df_future["date"]).dt.date
|
|
@@ -78,10 +78,10 @@ def generate_forecast():
|
|
| 78 |
# -------------------------
|
| 79 |
# HINDCAST LOGIC (LAST 7 DAYS)
|
| 80 |
# -------------------------
|
| 81 |
-
def generate_hindcast():
|
| 82 |
# Read actual + predicted from Feature View
|
| 83 |
features_df, labels_df = feature_view.training_data(
|
| 84 |
-
start_time=datetime.utcnow().date() - timedelta(days=
|
| 85 |
end_time=datetime.utcnow().date(),
|
| 86 |
statistics_config=False
|
| 87 |
)
|
|
@@ -110,22 +110,23 @@ def generate_hindcast():
|
|
| 110 |
# -------------------------
|
| 111 |
# GRADIO UI
|
| 112 |
# -------------------------
|
| 113 |
-
def run_dashboard(
|
| 114 |
-
forecast_plot = generate_forecast()
|
| 115 |
-
hindcast_plot = generate_hindcast()
|
| 116 |
-
|
| 117 |
return forecast_plot, hindcast_plot
|
| 118 |
|
| 119 |
|
| 120 |
iface = gr.Interface(
|
| 121 |
fn=run_dashboard,
|
| 122 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
outputs=[
|
| 124 |
-
gr.Image(label="PM2.5 Forecast
|
| 125 |
-
gr.Image(label="PM2.5 Hindcast
|
| 126 |
],
|
| 127 |
title="Air Quality Forecast Dashboard",
|
| 128 |
-
description="Forecast and
|
| 129 |
)
|
| 130 |
-
|
| 131 |
-
iface.launch()
|
|
|
|
| 43 |
# -------------------------
|
| 44 |
# FORECAST LOGIC (NEXT 7 DAYS)
|
| 45 |
# -------------------------
|
| 46 |
+
def generate_forecast(days):
|
| 47 |
today = datetime.utcnow().date()
|
| 48 |
+
future_dates = [(today + timedelta(days=i)).strftime("%Y-%m-%d") for i in range(1, days + 1)]
|
| 49 |
|
| 50 |
df_future = weather_fg.read()
|
| 51 |
df_future["date"] = pd.to_datetime(df_future["date"]).dt.date
|
|
|
|
| 78 |
# -------------------------
|
| 79 |
# HINDCAST LOGIC (LAST 7 DAYS)
|
| 80 |
# -------------------------
|
| 81 |
+
def generate_hindcast(days):
|
| 82 |
# Read actual + predicted from Feature View
|
| 83 |
features_df, labels_df = feature_view.training_data(
|
| 84 |
+
start_time=datetime.utcnow().date() - timedelta(days=days)
|
| 85 |
end_time=datetime.utcnow().date(),
|
| 86 |
statistics_config=False
|
| 87 |
)
|
|
|
|
| 110 |
# -------------------------
|
| 111 |
# GRADIO UI
|
| 112 |
# -------------------------
|
| 113 |
+
def run_dashboard(forecast_days, hindcast_days):
|
| 114 |
+
forecast_plot = generate_forecast(forecast_days)
|
| 115 |
+
hindcast_plot = generate_hindcast(hindcast_days)
|
|
|
|
| 116 |
return forecast_plot, hindcast_plot
|
| 117 |
|
| 118 |
|
| 119 |
iface = gr.Interface(
|
| 120 |
fn=run_dashboard,
|
| 121 |
+
inputs=[
|
| 122 |
+
gr.Slider(3, 10, value=7, step=1, label="Forecast Days (future)"),
|
| 123 |
+
gr.Slider(3, 10, value=7, step=1, label="Hindcast Days (past)"),
|
| 124 |
+
gr.Button("Generate")
|
| 125 |
+
],
|
| 126 |
outputs=[
|
| 127 |
+
gr.Image(label="PM2.5 Forecast"),
|
| 128 |
+
gr.Image(label="PM2.5 Hindcast")
|
| 129 |
],
|
| 130 |
title="Air Quality Forecast Dashboard",
|
| 131 |
+
description="Forecast and hindcast PM2.5 for Linköping using XGBoost + Hopsworks"
|
| 132 |
)
|
|
|
|
|
|