Spaces:
Sleeping
Sleeping
| import os | |
| import streamlit as st | |
| st.title("Inventory Dashboard") | |
| st.write("Welcome to your inventory tracking system!") | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def load_data(): | |
| cwd = os.getcwd() | |
| print(f"Current Directory: {cwd}") | |
| print(f"Files in Directory: {os.listdir(cwd)}") | |
| lead_time_path = os.path.join(os.getcwd(), "final_cleaned_lead_time_data.csv") | |
| inventory_path = os.path.join(os.getcwd(), "inventory.csv") | |
| optimization_path = os.path.join(os.getcwd(), "inventory_optimization_results.csv") | |
| lead_time_data = pd.read_csv(lead_time_path) | |
| inventory_data = pd.read_csv(inventory_path) | |
| optimization_data=pd.read_csv(optimization_path) | |
| return lead_time_data, inventory_data, optimization_data | |
| lead_time_data, inventory_data, optimization_data = load_data() | |
| st.header("📊 Inventory Optimization Insights") | |
| st.write("### Optimization Results Dataset(sample)") | |
| st.dataframe(optimization_data.head(500)) | |
| st.write("### Optimization Trend") | |
| if 'Optimization_Score' in optimization_data.columns: | |
| fig, ax = plt.subplots() | |
| ax.plot(optimization_data.index, optimization_data['Optimization_Score'], marker='o', linestyle='-') | |
| ax.set_title("Optimization Score Over Time") | |
| ax.set_xlabel("Iteration") | |
| ax.set_ylabel("Score") | |
| st.pyplot(fig) | |
| def calculate_safety_stock(demand_std, lead_time_mean, z_score=1.645): | |
| return z_score * demand_std * np.sqrt(lead_time_mean) | |
| def calculate_reorder_point(avg_demand, lead_time_mean, safety_stock): | |
| return (avg_demand * lead_time_mean) + safety_stock | |
| def simulate_real_time_data(data, interval=5): | |
| for i in range(interval): | |
| new_demand = np.random.randint(50, 100) | |
| new_row = pd.DataFrame([{'Product Name': f'Product {i+1}', 'Demand': new_demand}]) | |
| data = pd.concat([data, new_row], ignore_index=True) | |
| return data | |
| st.sidebar.header("Inventory Parameters") | |
| z_score = st.sidebar.slider("Z-Score (Service Level)", 1.0, 3.0, 1.645) | |
| interval = st.sidebar.slider("Real-Time Update Interval", 1, 10, 5) | |
| demand_std = lead_time_data['Lead Time (Days)'].std() | |
| lead_time_mean = lead_time_data['Lead Time (Days)'].mean() | |
| avg_demand = inventory_data[' Warehouse Inventory '].mean() | |
| safety_stock = calculate_safety_stock(demand_std, lead_time_mean, z_score) | |
| reorder_point = calculate_reorder_point(avg_demand, lead_time_mean, safety_stock) | |
| st.title("Inventory Management Dashboard") | |
| st.write("This dashboard dynamically visualizes inventory levels, reorder points, and safety stock.") | |
| st.subheader("Key Metrics") | |
| st.metric("Safety Stock", f"{safety_stock:.2f} units") | |
| st.metric("Reorder Point", f"{reorder_point:.2f} units") | |
| st.metric("Average Demand", f"{avg_demand:.2f} units/day") | |
| st.subheader("Real-Time Inventory Updates") | |
| real_time_data = simulate_real_time_data(inventory_data, interval) | |
| st.write(real_time_data) | |
| st.subheader("Inventory Levels") | |
| fig, ax = plt.subplots() | |
| ax.plot(inventory_data['Product Name'], inventory_data[' Warehouse Inventory '], label='Inventory Levels', color='blue') | |
| ax.axhline(y=reorder_point, color='red', linestyle='--', label='Reorder Point') | |
| ax.axhline(y=safety_stock, color='green', linestyle='--', label='Safety Stock') | |
| ax.set_title("Inventory Levels and Reorder Point") | |
| ax.set_xlabel("Product Name") | |
| ax.set_ylabel("Inventory") | |
| ax.legend() | |
| st.pyplot(fig) | |
| st.subheader("Inventory Data") | |
| st.dataframe(inventory_data) | |
| if st.button("Save Results"): | |
| inventory_data.to_csv("updated_inventory_data.csv", index=False) | |
| st.success("Results saved to 'updated_inventory_data.csv'") | |
| if __name__ == "__main__": | |
| import streamlit as st | |
| st.write("Streamlit app is running!") | |