Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import pandas as pd
|
|
| 3 |
from prophet import Prophet
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
|
| 7 |
# Prepare data for Prophet
|
| 8 |
def prepare_prophet_data(usage_series):
|
|
@@ -13,7 +14,7 @@ def prepare_prophet_data(usage_series):
|
|
| 13 |
'ds': dates,
|
| 14 |
'y': usage_series
|
| 15 |
})
|
| 16 |
-
prophet_df['cap'] = 60
|
| 17 |
prophet_df['floor'] = 0
|
| 18 |
return prophet_df
|
| 19 |
|
|
@@ -103,6 +104,57 @@ def main():
|
|
| 103 |
st.write(f"**For 7 Days**: Order {order_7} additional units.")
|
| 104 |
st.write(f"**For 14 Days**: Order {order_14} additional units.")
|
| 105 |
st.write(f"**For 30 Days**: Order {order_30} additional units.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
main()
|
|
|
|
| 3 |
from prophet import Prophet
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
import numpy as np
|
| 6 |
+
import plotly.graph_objects as go
|
| 7 |
|
| 8 |
# Prepare data for Prophet
|
| 9 |
def prepare_prophet_data(usage_series):
|
|
|
|
| 14 |
'ds': dates,
|
| 15 |
'y': usage_series
|
| 16 |
})
|
| 17 |
+
prophet_df['cap'] = 60
|
| 18 |
prophet_df['floor'] = 0
|
| 19 |
return prophet_df
|
| 20 |
|
|
|
|
| 104 |
st.write(f"**For 7 Days**: Order {order_7} additional units.")
|
| 105 |
st.write(f"**For 14 Days**: Order {order_14} additional units.")
|
| 106 |
st.write(f"**For 30 Days**: Order {order_30} additional units.")
|
| 107 |
+
|
| 108 |
+
# Forecast visualization
|
| 109 |
+
st.header("Forecast Visualization")
|
| 110 |
+
forecast_data = pd.DataFrame({
|
| 111 |
+
'Period': ['7 Days', '14 Days', '30 Days'],
|
| 112 |
+
'Units': [forecast_7, forecast_14, forecast_30]
|
| 113 |
+
})
|
| 114 |
+
fig_forecast = go.Figure()
|
| 115 |
+
fig_forecast.add_trace(go.Scatter(
|
| 116 |
+
x=forecast_data['Period'],
|
| 117 |
+
y=forecast_data['Units'],
|
| 118 |
+
mode='lines+markers',
|
| 119 |
+
name='Forecasted Units',
|
| 120 |
+
line=dict(color='blue'),
|
| 121 |
+
marker=dict(size=10)
|
| 122 |
+
))
|
| 123 |
+
fig_forecast.update_layout(
|
| 124 |
+
title='Consumable Usage Forecast',
|
| 125 |
+
xaxis_title='Time Period',
|
| 126 |
+
yaxis_title='Units',
|
| 127 |
+
template='plotly_white'
|
| 128 |
+
)
|
| 129 |
+
st.plotly_chart(fig_forecast)
|
| 130 |
+
|
| 131 |
+
# Threshold alerts bar chart
|
| 132 |
+
st.header("Threshold Alerts Visualization")
|
| 133 |
+
alert_data = pd.DataFrame({
|
| 134 |
+
'Category': ['Current Stock', '7-Day Forecast', '14-Day Forecast', '30-Day Forecast'],
|
| 135 |
+
'Units': [current_stock, forecast_7, forecast_14, forecast_30],
|
| 136 |
+
'Alert': [
|
| 137 |
+
False,
|
| 138 |
+
current_stock < forecast_7,
|
| 139 |
+
current_stock < forecast_14,
|
| 140 |
+
current_stock < forecast_30
|
| 141 |
+
]
|
| 142 |
+
})
|
| 143 |
+
fig_alerts = go.Figure()
|
| 144 |
+
fig_alerts.add_trace(go.Bar(
|
| 145 |
+
x=alert_data['Category'],
|
| 146 |
+
y=alert_data['Units'],
|
| 147 |
+
marker_color=['green'] + ['red' if alert else 'blue' for alert in alert_data['Alert'][1:]],
|
| 148 |
+
text=[f"🚩" if alert else "" for alert in alert_data['Alert']],
|
| 149 |
+
textposition='auto'
|
| 150 |
+
))
|
| 151 |
+
fig_alerts.update_layout(
|
| 152 |
+
title='Stock vs Forecast with Alerts (🚩 indicates low stock)',
|
| 153 |
+
xaxis_title='Category',
|
| 154 |
+
yaxis_title='Units',
|
| 155 |
+
template='plotly_white'
|
| 156 |
+
)
|
| 157 |
+
st.plotly_chart(fig_alerts)
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
| 160 |
main()
|