Commit
ยท
558f9a2
1
Parent(s):
e2c152c
Guardar mis cambios locales
Browse files
app.py
CHANGED
|
@@ -98,4 +98,58 @@ def upload_and_forecast(uploaded_file, period):
|
|
| 98 |
|
| 99 |
future_n_periods = forecast_period
|
| 100 |
future_fitted, confint = train_test_model.predict(X=df.iloc[-future_n_periods:, 1:], n_periods=future_n_periods, return_conf_int=True, freq='3D')
|
| 101 |
-
future_index_of_fc = pd.date_range(df['Sales'].index[-1], periods=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
future_n_periods = forecast_period
|
| 100 |
future_fitted, confint = train_test_model.predict(X=df.iloc[-future_n_periods:, 1:], n_periods=future_n_periods, return_conf_int=True, freq='3D')
|
| 101 |
+
future_index_of_fc = pd.date_range(df['Sales'].index[-1], periods=future_n_periods, freq='3D')
|
| 102 |
+
future_fitted_series = pd.Series(future_fitted)
|
| 103 |
+
future_fitted_series.index = future_index_of_fc
|
| 104 |
+
|
| 105 |
+
# Calculate sales growth
|
| 106 |
+
future_sales_growth = sales_growth(df, future_fitted_series)
|
| 107 |
+
|
| 108 |
+
# Prepare merged data for chart plotting
|
| 109 |
+
merged_data = merge_forecast_data(df['Sales'], fitted_series, future_fitted_series)
|
| 110 |
+
|
| 111 |
+
# Plot the charts
|
| 112 |
+
fig_compare = go.Figure()
|
| 113 |
+
fig_compare.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Actual Sales'], mode='lines', name='Actual Sales'))
|
| 114 |
+
fig_compare.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Predicted Sales'], mode='lines', name='Predicted Sales', line=dict(color='#006400')))
|
| 115 |
+
fig_compare.update_layout(title='๐ Historical Sales Data', xaxis_title='Date', yaxis_title='Sales')
|
| 116 |
+
|
| 117 |
+
fig_forecast = go.Figure()
|
| 118 |
+
fig_forecast.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Actual Sales'], mode='lines', name='Actual Sales'))
|
| 119 |
+
fig_forecast.add_trace(go.Scatter(x=merged_data[merged_data.columns[0]], y=merged_data['Forecasted Future Sales'], mode='lines', name='Future Forecasted Sales'))
|
| 120 |
+
fig_forecast.update_layout(title='๐ฎ Forecasted Sales Data', xaxis_title='Date', yaxis_title='Sales')
|
| 121 |
+
|
| 122 |
+
# Return the figures and growth data
|
| 123 |
+
return fig_compare, fig_forecast, future_sales_growth
|
| 124 |
+
|
| 125 |
+
# Create the sidebar (inputs) and main interface for outputs
|
| 126 |
+
def create_sidebar():
|
| 127 |
+
with gr.Column():
|
| 128 |
+
gr.Markdown("### ๐ Upload your sales data (CSV)")
|
| 129 |
+
uploaded_file = gr.File(label="Choose your file", elem_id="file-uploader")
|
| 130 |
+
gr.Markdown("### โณ Forecast Period (Days)")
|
| 131 |
+
period = gr.Slider(minimum=30, maximum=90, step=1, label="Forecast period (in days)")
|
| 132 |
+
return uploaded_file, period
|
| 133 |
+
|
| 134 |
+
# Create the sidebar and main interface
|
| 135 |
+
uploaded_file, period = create_sidebar()
|
| 136 |
+
|
| 137 |
+
# Gradio interface for output display (results shown below)
|
| 138 |
+
output_plots = [
|
| 139 |
+
gr.Plot(label="๐ Historical vs Predicted Sales"),
|
| 140 |
+
gr.Plot(label="๐ฎ Forecasted Sales Data"),
|
| 141 |
+
gr.DataFrame(label="๐ Sales Growth")
|
| 142 |
+
]
|
| 143 |
+
|
| 144 |
+
# Create and launch the gradio interface
|
| 145 |
+
iface = gr.Interface(
|
| 146 |
+
fn=upload_and_forecast,
|
| 147 |
+
inputs=[uploaded_file, period],
|
| 148 |
+
outputs=output_plots,
|
| 149 |
+
live=True,
|
| 150 |
+
title="Sales Forecasting System โจ",
|
| 151 |
+
description="Upload your sales data to start forecasting ๐",
|
| 152 |
+
css=open("styles.css", "r").read() # Load the external CSS file here
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
iface.launch()
|