Spaces:
Running
Running
Rehman1603
commited on
Commit
•
351ad2c
1
Parent(s):
29df1ee
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import plotly.graph_objs as go
|
|
5 |
|
6 |
# Function to train the model and generate forecast
|
7 |
def predict_sales(time_frame):
|
8 |
-
all_sales_data = pd.read_csv('All sales - House of Pizza.csv')
|
9 |
|
10 |
# Clean up the 'Total paid' column
|
11 |
amount = all_sales_data['Total paid'].str.replace('₨', '', regex=False)
|
@@ -30,10 +30,9 @@ def predict_sales(time_frame):
|
|
30 |
df['ds'] = df['Date']
|
31 |
df['y'] = df['Total paid']
|
32 |
model.fit(df[['ds', 'y']])
|
33 |
-
|
34 |
# Future forecast based on the time frame
|
35 |
future_periods = {
|
36 |
-
'24 hours': 1 * 24 * 60,
|
37 |
'7 days': 7 * 24 * 60,
|
38 |
'10 days': 10 * 24 * 60,
|
39 |
'15 days': 15 * 24 * 60,
|
@@ -42,7 +41,14 @@ def predict_sales(time_frame):
|
|
42 |
|
43 |
# Get the future time based on the selected time frame
|
44 |
future_time = model.make_future_dataframe(periods=future_periods[time_frame], freq='T')
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# Display the forecasted data
|
48 |
forecast_table = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(future_periods[time_frame])
|
@@ -71,7 +77,7 @@ def predict_sales(time_frame):
|
|
71 |
# Gradio interface
|
72 |
def run_gradio():
|
73 |
# Create the Gradio Interface
|
74 |
-
time_options = ['
|
75 |
gr.Interface(
|
76 |
fn=predict_sales, # Function to be called
|
77 |
inputs=gr.components.Dropdown(time_options, label="Select Forecast Time Range"), # User input
|
|
|
5 |
|
6 |
# Function to train the model and generate forecast
|
7 |
def predict_sales(time_frame):
|
8 |
+
all_sales_data = pd.read_csv('/content/All sales - House of Pizza.csv')
|
9 |
|
10 |
# Clean up the 'Total paid' column
|
11 |
amount = all_sales_data['Total paid'].str.replace('₨', '', regex=False)
|
|
|
30 |
df['ds'] = df['Date']
|
31 |
df['y'] = df['Total paid']
|
32 |
model.fit(df[['ds', 'y']])
|
33 |
+
last_date_value = df['Date'].iloc[-2]
|
34 |
# Future forecast based on the time frame
|
35 |
future_periods = {
|
|
|
36 |
'7 days': 7 * 24 * 60,
|
37 |
'10 days': 10 * 24 * 60,
|
38 |
'15 days': 15 * 24 * 60,
|
|
|
41 |
|
42 |
# Get the future time based on the selected time frame
|
43 |
future_time = model.make_future_dataframe(periods=future_periods[time_frame], freq='T')
|
44 |
+
current_time = pd.Timestamp.now()
|
45 |
+
|
46 |
+
# Set the last historical date in the format 'MM/DD/YYYY HH:MM'
|
47 |
+
last_historical_date = pd.to_datetime(last_date_value, format='%m/%d/%Y %H:%M')
|
48 |
+
|
49 |
+
# Filter future_time to include rows from the current time and onwards, including future hours and minutes
|
50 |
+
future_only = future_time[(future_time['ds'] >= current_time) & (future_time['ds'] > last_historical_date)]
|
51 |
+
forecast = model.predict(future_only)
|
52 |
|
53 |
# Display the forecasted data
|
54 |
forecast_table = forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail(future_periods[time_frame])
|
|
|
77 |
# Gradio interface
|
78 |
def run_gradio():
|
79 |
# Create the Gradio Interface
|
80 |
+
time_options = ['7 days', '10 days', '15 days', '1 month']
|
81 |
gr.Interface(
|
82 |
fn=predict_sales, # Function to be called
|
83 |
inputs=gr.components.Dropdown(time_options, label="Select Forecast Time Range"), # User input
|