| import streamlit as st
|
| import numpy as np
|
| import pandas as pd
|
| import plotly.graph_objects as go
|
| import pickle
|
| from keras.models import load_model
|
|
|
|
|
|
|
|
|
| st.set_page_config(page_title="Workforce AI Optimizer", layout="wide")
|
|
|
|
|
| st.markdown(
|
| """
|
| <style>
|
| [data-testid="stSidebar"][aria-expanded="true"]{
|
| min-width: 360px;
|
| max-width: 360px;
|
| }
|
| </style>
|
| """,
|
| unsafe_allow_html=True,
|
| )
|
|
|
| @st.cache_resource
|
| def load_assets():
|
| model = load_model("lstm_traffic_model.keras")
|
| sc = pickle.load(open("scaler.pkl", "rb"))
|
| return model, sc
|
|
|
| try:
|
| model, sc = load_assets()
|
| except Exception as e:
|
| st.error(f"Error: Model files not found! -> {e}")
|
| st.stop()
|
|
|
|
|
|
|
|
|
| st.sidebar.title("🛠️ Setup & Guide / Rehber")
|
|
|
| st.sidebar.markdown("""
|
| **Data Format / Veri Formatı:**
|
| The CSV should contain historical call data. / CSV geçmiş çağrı verilerini içermelidir.
|
| """)
|
|
|
|
|
| st.sidebar.info("""
|
| **Slot Logic / Slot Mantığı:**
|
| - **Slot 0:** 08:00-09:00 (100 cals)
|
| - **Slot 1:** 09:00-10:00 (150 cals)
|
| - **Slot 2:** 10:00-11:00 (120 cals)
|
| - **Slot 3:** 11:00-12:00 (180 cals)
|
| - **Slot 4:** 12:00-13:00 (200 cals)
|
| - **Slot 5:** 13:00-14:00 (160 cals)
|
| - **...**
|
| - **Slot 81:** Midnight (5 cals)
|
| """)
|
|
|
| st.sidebar.subheader("Sample CSV / Örnek Yapı")
|
| example_df = pd.DataFrame({"calls": [105, 140, 88, 120, 200, 160]})
|
| st.sidebar.dataframe(example_df, use_container_width=True)
|
|
|
| st.sidebar.warning("⚠️ **Column Name:** 'calls' or 'Incoming Calls'")
|
|
|
| st.sidebar.markdown("---")
|
| st.sidebar.subheader("💰 Cost Settings / Maliyet")
|
| wage = st.sidebar.number_input("Hourly Wage / Saatlik Ücret ($)", value=20)
|
| capacity = st.sidebar.number_input("Calls per Staff / Kapasite", value=15)
|
|
|
|
|
|
|
|
|
| st.title("📞 Workforce Optimization AI / İş Gücü Optimizasyonu")
|
| st.write("Ensuring the right number of people at the right time.")
|
| st.markdown("---")
|
|
|
| file = st.file_uploader("Upload CSV / CSV Yükle", type=["csv"])
|
|
|
| if file is not None:
|
| df = pd.read_csv(file)
|
| target_col = "calls" if "calls" in df.columns else ("Incoming Calls" if "Incoming Calls" in df.columns else None)
|
|
|
| if target_col is None:
|
| st.error("❌ Column not found!")
|
| st.stop()
|
|
|
| raw_data = df[[target_col]].values
|
|
|
|
|
| scaled_data = sc.transform(raw_data)
|
| pred_scaled = model.predict(scaled_data)
|
| predictions = sc.inverse_transform(pred_scaled)
|
| needed_staff = np.ceil(predictions / capacity).flatten().astype(int)
|
|
|
|
|
| st.header("🎯 Decision Logic / Karar Mantığı")
|
| logic_col1, logic_col2 = st.columns(2)
|
|
|
| with logic_col1:
|
| st.error("### 🔥 High Intensity (Yüksek Yoğunluk)")
|
| st.write("**Advice:** INCREASE STAFF to protect quality.")
|
| st.write("**Öneri:** Kalite için PERSONEL ARTIRIN.")
|
|
|
| with logic_col2:
|
| st.success("### 💰 Saving Area (Tasarruf Alanı)")
|
| st.write("**Advice:** REDUCE STAFF to maximize profit.")
|
| st.write("**Öneri:** Kâr için PERSONELİ AZALTIN.")
|
|
|
|
|
| st.markdown("---")
|
| st.subheader("📈 Capacity Analysis / Kapasite Analizi")
|
| fig = go.Figure()
|
| fig.add_trace(go.Scatter(y=raw_data.flatten(), name="Past", line=dict(color="gray")))
|
| fig.add_trace(go.Scatter(y=predictions.flatten(), name="AI Forecast", line=dict(color="#1C83E1", width=3)))
|
| fig.add_trace(go.Bar(y=needed_staff * capacity, name="Capacity", opacity=0.2, marker_color="green"))
|
| fig.update_layout(hovermode="x unified", template="plotly_white", height=400)
|
| st.plotly_chart(fig, use_container_width=True)
|
|
|
|
|
| st.header("🧠 AI Strategic Recommendations")
|
| mean_val = np.mean(needed_staff)
|
| peak_indices = np.where(needed_staff > mean_val * 1.25)[0].tolist()
|
| low_indices = np.where(needed_staff < mean_val * 0.75)[0].tolist()
|
|
|
| c1, c2 = st.columns(2)
|
| with c1:
|
| st.error(f"### 🚨 High Intensity")
|
| if peak_indices:
|
| st.write(f"**At:** {', '.join([f'Slot {i}' for i in peak_indices[:5]])}...")
|
| st.write("Increase staff. / Personel artırın.")
|
| else:
|
| st.write("No major peaks.")
|
|
|
| with c2:
|
| st.success(f"### 📉 Saving Area")
|
| if low_indices:
|
| st.write(f"**At:** {', '.join([f'Slot {i}' for i in low_indices[:5]])}...")
|
| st.write("Reduce staff. / Personeli azaltın.")
|
| else:
|
| st.write("No saving opportunity.")
|
|
|
|
|
| with st.expander("📊 Detailed Schedule Table"):
|
| res_df = pd.DataFrame({
|
| "Time Slot": [f"Slot {i}" for i in range(len(predictions))],
|
| "Predicted Demand": predictions.flatten().astype(int),
|
| "Suggested Staff": needed_staff
|
| })
|
| st.dataframe(res_df, use_container_width=True)
|
|
|
| else:
|
| st.info("👋 Please upload your CSV file to begin. / Başlamak için CSV yükleyin.") |