Spaces:
Sleeping
Sleeping
File size: 3,096 Bytes
36c25df 1fd3f8d 36c25df 1fd3f8d 36c25df 1fd3f8d 11741b6 1fd3f8d 36c25df 1fd3f8d e019a29 1fd3f8d 36c25df 1fd3f8d 36c25df 1fd3f8d c2ab6dd 1fd3f8d 36c25df 1fd3f8d c2ab6dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import streamlit as st
import pandas as pd
import plotly.express as px
# 1. Page Configuration
st.set_page_config(page_title="Store Sales Forecast", page_icon="🛒", layout="wide")
# 2. Title and Description
st.title("🛒 Store Sales Forecasting")
st.markdown("""
This application visualizes the 16-day future sales predictions for retail stores in Ecuador.
The forecasts are generated using an **XGBoost** machine learning model trained on historical data,
incorporating features like seasonality, oil prices, and holidays.
""")
# 3. Load Data Function (Cached for performance)
@st.cache_data
def load_data():
# Load the CSV file we prepared earlier
df = pd.read_csv("src/dashboard_data.csv")
# Ensure date column is in datetime format
if 'date' in df.columns:
df['date'] = pd.to_datetime(df['date'])
return df
try:
df = load_data()
# --- SIDEBAR (FILTERS) ---
st.sidebar.header("Filter Options")
# Store Selector
if 'store_nbr' in df.columns:
store_list = sorted(df['store_nbr'].unique())
selected_store = st.sidebar.selectbox("Select Store Number", store_list)
else:
st.error("Column 'store_nbr' not found in dataset.")
st.stop()
# Family Selector
if 'family' in df.columns:
family_list = sorted(df['family'].unique())
selected_family = st.sidebar.selectbox("Select Product Category (Family)", family_list)
# --- MAIN CONTENT ---
# Filter data based on user selection
filtered_data = df[(df['store_nbr'] == selected_store) & (df['family'] == selected_family)]
# Sort by date for proper plotting
if 'date' in filtered_data.columns:
filtered_data = filtered_data.sort_values('date')
# Plot Chart using Plotly
st.subheader(f"📅 Forecast for Store #{selected_store} - Category: {selected_family}")
fig = px.line(filtered_data, x='date', y='Predicted_Sales',
title='16-Day Sales Prediction Trend',
labels={'Predicted_Sales': 'Predicted Sales Volume', 'date': 'Date'},
markers=True)
# --- DÜZELTİLEN KISIM (FIXED PART) ---
# Renk ayarını 'update_traces' içine aldık (Layout hatasını çözer)
fig.update_traces(line_color='#00CC96')
# Layout ayarları sadece hover (üzerine gelince çıkan bilgi) için kaldı
fig.update_layout(hovermode="x unified")
# -------------------------------------
st.plotly_chart(fig, use_container_width=True)
# Show Data Table
with st.expander("View Detailed Forecast Data"):
st.dataframe(filtered_data[['id', 'date', 'store_nbr', 'family', 'Predicted_Sales']])
else:
st.warning("Date column is missing. Cannot plot the graph.")
except FileNotFoundError:
st.error("Error: 'dashboard_data.csv' not found. Please upload the file to Hugging Face Files.")
except Exception as e:
st.error(f"An unexpected error occurred: {e}") |