Update app.py
Browse files
app.py
CHANGED
@@ -233,7 +233,45 @@ def forecast_chronos_data(df_state, date_column, target_column, select_period, f
|
|
233 |
line=dict(color="royalblue", width=2),
|
234 |
selector=dict(name="y") # Updates only the historical data line
|
235 |
)
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
# plt.figure(figsize=(30, 10))
|
239 |
# plt.plot(monthly_sales["y"], color="royalblue", label="Historical Data", linewidth=2)
|
@@ -347,14 +385,21 @@ with gr.Blocks(theme=gr.themes.Default()) as demo:
|
|
347 |
select_period = gr.Slider(2, 60, value=12, label="Select Period", info="Check Selected Forecast Type", interactive =True, step=1)
|
348 |
forecast_btn = gr.Button("Forecast")
|
349 |
|
350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
with gr.Row():
|
352 |
plot_forecast_output = gr.Plot(label="Chronos Forecasting Visualization")
|
353 |
|
354 |
forecast_btn.click(
|
355 |
forecast_chronos_data,
|
356 |
inputs=[df_state, date_column, target_column, select_period],
|
357 |
-
outputs=[plot_forecast_output]
|
358 |
)
|
359 |
|
360 |
|
|
|
233 |
line=dict(color="royalblue", width=2),
|
234 |
selector=dict(name="y") # Updates only the historical data line
|
235 |
)
|
236 |
+
|
237 |
+
|
238 |
+
# Bar Chart
|
239 |
+
bar_chart = go.Figure()
|
240 |
+
|
241 |
+
bar_chart.add_trace(
|
242 |
+
go.Bar(
|
243 |
+
x=monthly_sales.index,
|
244 |
+
y=monthly_sales["y"],
|
245 |
+
name="Historical Sales",
|
246 |
+
marker_color='rgba(50, 150, 250, 0.6)', # Light blue color
|
247 |
+
opacity=0.8
|
248 |
+
)
|
249 |
+
)
|
250 |
+
|
251 |
+
bar_chart.add_trace(
|
252 |
+
go.Bar(
|
253 |
+
x=forecast_index,
|
254 |
+
y=median,
|
255 |
+
name="Median Forecast",
|
256 |
+
marker_color='rgba(255, 99, 71, 0.9)',
|
257 |
+
opacity=0.8
|
258 |
+
)
|
259 |
+
)
|
260 |
+
|
261 |
+
bar_chart.update_layout(
|
262 |
+
title="Sales Forecasting Visualization (Bar Chart)",
|
263 |
+
xaxis_title="Months",
|
264 |
+
yaxis_title=f"{target_column}",
|
265 |
+
title_font_size=20,
|
266 |
+
xaxis_title_font_size=16,
|
267 |
+
yaxis_title_font_size=16,
|
268 |
+
legend_font_size=16,
|
269 |
+
width=1800,
|
270 |
+
height=600,
|
271 |
+
plot_bgcolor='white'
|
272 |
+
)
|
273 |
+
|
274 |
+
return fig, bar_chart
|
275 |
|
276 |
# plt.figure(figsize=(30, 10))
|
277 |
# plt.plot(monthly_sales["y"], color="royalblue", label="Historical Data", linewidth=2)
|
|
|
385 |
select_period = gr.Slider(2, 60, value=12, label="Select Period", info="Check Selected Forecast Type", interactive =True, step=1)
|
386 |
forecast_btn = gr.Button("Forecast")
|
387 |
|
388 |
+
with gr.Tabs():
|
389 |
+
with gr.TabItem("Line Chart"):
|
390 |
+
with gr.Row():
|
391 |
+
plot_forecast_output = gr.Plot(label="Chronos Forecasting Visualization")
|
392 |
+
with gr.TabItem("Bar Chart"):
|
393 |
+
with gr.Row():
|
394 |
+
bar_plot_forecast_output = gr.Plot(label="Chronos Forecasting Visualization (Bar)")
|
395 |
+
|
396 |
with gr.Row():
|
397 |
plot_forecast_output = gr.Plot(label="Chronos Forecasting Visualization")
|
398 |
|
399 |
forecast_btn.click(
|
400 |
forecast_chronos_data,
|
401 |
inputs=[df_state, date_column, target_column, select_period],
|
402 |
+
outputs=[plot_forecast_output, bar_plot_forecast_output]
|
403 |
)
|
404 |
|
405 |
|