Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +61 -27
src/streamlit_app.py
CHANGED
|
@@ -11,16 +11,11 @@ st.set_page_config(page_title="Hotel AI Decision Support", layout="wide")
|
|
| 11 |
|
| 12 |
@st.cache_resource
|
| 13 |
def load_assets():
|
| 14 |
-
# Dosya isimlerini burada tanımlıyoruz
|
| 15 |
model_file = "hotel_model.keras"
|
| 16 |
scaler_file = "scaler.pkl"
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
st.error(f"❌ Model dosyası bulunamadı: {model_file}")
|
| 21 |
-
st.stop()
|
| 22 |
-
if not os.path.exists(scaler_file):
|
| 23 |
-
st.error(f"❌ Scaler dosyası bulunamadı: {scaler_file}")
|
| 24 |
st.stop()
|
| 25 |
|
| 26 |
model = load_model(model_file)
|
|
@@ -28,26 +23,56 @@ def load_assets():
|
|
| 28 |
sc = pickle.load(f)
|
| 29 |
return model, sc
|
| 30 |
|
| 31 |
-
# Varlıkları yükle
|
| 32 |
try:
|
| 33 |
model, sc = load_assets()
|
| 34 |
except Exception as e:
|
| 35 |
-
st.error(f"⚠️
|
| 36 |
st.stop()
|
| 37 |
|
| 38 |
# ==========================================
|
| 39 |
-
# SIDEBAR / SOL PANEL
|
| 40 |
# ==========================================
|
| 41 |
with st.sidebar:
|
| 42 |
-
st.markdown("
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
st.markdown("---")
|
|
|
|
|
|
|
| 45 |
st.markdown("### ❓ What is 'Bookings'? / 'Bookings' Nedir?")
|
| 46 |
-
st.write("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
st.markdown("---")
|
|
|
|
|
|
|
| 48 |
st.markdown("### 📊 Thresholds / Yoğunluk")
|
| 49 |
-
st.warning("High (Yoğun): >
|
|
|
|
|
|
|
| 50 |
st.markdown("---")
|
|
|
|
|
|
|
|
|
|
| 51 |
file = st.file_uploader("Upload CSV / CSV Yükle", type=["csv"])
|
| 52 |
|
| 53 |
# ==========================================
|
|
@@ -58,7 +83,7 @@ st.markdown("<h1 style='text-align: center;'>🏨 Hotel Demand Forecasting / Ote
|
|
| 58 |
if file is not None:
|
| 59 |
df = pd.read_csv(file)
|
| 60 |
|
| 61 |
-
#
|
| 62 |
raw_data = df[["bookings"]].values
|
| 63 |
data_scaled = sc.transform(raw_data)
|
| 64 |
predictions_scaled = model.predict(data_scaled)
|
|
@@ -68,7 +93,7 @@ if file is not None:
|
|
| 68 |
busy_limit = int(avg_val * 1.2)
|
| 69 |
current_max = int(predictions.max())
|
| 70 |
|
| 71 |
-
# 1. METRİKLER
|
| 72 |
st.markdown("---")
|
| 73 |
c1, c2, c3 = st.columns(3)
|
| 74 |
with c1:
|
|
@@ -83,19 +108,28 @@ if file is not None:
|
|
| 83 |
# 2. YÖNETİM TAVSİYESİ
|
| 84 |
st.markdown("---")
|
| 85 |
st.markdown("<h3 style='text-align: center;'>👔 Management Advice / Yönetim Tavsiyesi</h3>", unsafe_allow_html=True)
|
| 86 |
-
|
| 87 |
-
with
|
| 88 |
-
if current_max >= busy_limit:
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# 3. SONUÇ TABLOSU
|
| 95 |
st.markdown("---")
|
| 96 |
st.subheader("📋 Results Table / Sonuç Tablosu")
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
# 4. GRAFİK
|
| 101 |
st.markdown("---")
|
|
@@ -107,9 +141,9 @@ if file is not None:
|
|
| 107 |
ax.legend(prop={'size': 8})
|
| 108 |
st.pyplot(fig)
|
| 109 |
|
| 110 |
-
# 5. VERİ ÖN İZLEME
|
| 111 |
st.markdown("---")
|
| 112 |
-
st.subheader("📊 Data Preview / Veri Ön İzleme")
|
| 113 |
st.dataframe(df, use_container_width=True, height=150)
|
| 114 |
|
| 115 |
else:
|
|
|
|
| 11 |
|
| 12 |
@st.cache_resource
|
| 13 |
def load_assets():
|
|
|
|
| 14 |
model_file = "hotel_model.keras"
|
| 15 |
scaler_file = "scaler.pkl"
|
| 16 |
|
| 17 |
+
if not os.path.exists(model_file) or not os.path.exists(scaler_file):
|
| 18 |
+
st.error("❌ Required files (model or scaler) are missing in the repository!")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
st.stop()
|
| 20 |
|
| 21 |
model = load_model(model_file)
|
|
|
|
| 23 |
sc = pickle.load(f)
|
| 24 |
return model, sc
|
| 25 |
|
|
|
|
| 26 |
try:
|
| 27 |
model, sc = load_assets()
|
| 28 |
except Exception as e:
|
| 29 |
+
st.error(f"⚠️ Load Error: {e}")
|
| 30 |
st.stop()
|
| 31 |
|
| 32 |
# ==========================================
|
| 33 |
+
# SIDEBAR / SOL PANEL (TÜM EKSİKLER GİDERİLDİ)
|
| 34 |
# ==========================================
|
| 35 |
with st.sidebar:
|
| 36 |
+
st.markdown("<h2 style='color: #2980b9;'>📖 User Guide / Rehber</h2>", unsafe_allow_html=True)
|
| 37 |
+
|
| 38 |
+
# 1. NASIL YÜKLENMELİ?
|
| 39 |
+
st.markdown("### 📥 How to Upload? / Nasıl Yüklenmeli?")
|
| 40 |
+
st.info("""
|
| 41 |
+
**CSV Format Example:**
|
| 42 |
+
| bookings |
|
| 43 |
+
| :--- |
|
| 44 |
+
| 120 |
|
| 45 |
+
| 155 |
|
| 46 |
+
| 200 |
|
| 47 |
+
|
| 48 |
+
*Please ensure the column name is 'bookings'.*
|
| 49 |
+
*Sütun adının 'bookings' olduğundan emin olun.*
|
| 50 |
+
""")
|
| 51 |
+
|
| 52 |
st.markdown("---")
|
| 53 |
+
|
| 54 |
+
# 2. BOOKING NEDİR?
|
| 55 |
st.markdown("### ❓ What is 'Bookings'? / 'Bookings' Nedir?")
|
| 56 |
+
st.write("""
|
| 57 |
+
**EN:** It represents the total number of reservations made on that specific day.
|
| 58 |
+
**TR:** O gün yapılan toplam rezervasyon sayısını temsil eder.
|
| 59 |
+
|
| 60 |
+
**Example / Örnek:**
|
| 61 |
+
If value is **150**, it means 150 rooms were sold that day.
|
| 62 |
+
Değer **150** ise, o gün 150 oda satılmış demektir.
|
| 63 |
+
""")
|
| 64 |
+
|
| 65 |
st.markdown("---")
|
| 66 |
+
|
| 67 |
+
# 3. YOĞUNLUK ARALIKLARI
|
| 68 |
st.markdown("### 📊 Thresholds / Yoğunluk")
|
| 69 |
+
st.warning("**High Demand (Yoğun):**\nForecast > Average + 20%")
|
| 70 |
+
st.success("**Stable (Stabil):**\nForecast within normal range")
|
| 71 |
+
|
| 72 |
st.markdown("---")
|
| 73 |
+
|
| 74 |
+
# 4. DOSYA YÜKLEME ALANI
|
| 75 |
+
st.markdown("### 🚀 Start Analysis / Analizi Başlat")
|
| 76 |
file = st.file_uploader("Upload CSV / CSV Yükle", type=["csv"])
|
| 77 |
|
| 78 |
# ==========================================
|
|
|
|
| 83 |
if file is not None:
|
| 84 |
df = pd.read_csv(file)
|
| 85 |
|
| 86 |
+
# Analiz İşlemleri
|
| 87 |
raw_data = df[["bookings"]].values
|
| 88 |
data_scaled = sc.transform(raw_data)
|
| 89 |
predictions_scaled = model.predict(data_scaled)
|
|
|
|
| 93 |
busy_limit = int(avg_val * 1.2)
|
| 94 |
current_max = int(predictions.max())
|
| 95 |
|
| 96 |
+
# 1. METRİKLER (EN ÜSTTE)
|
| 97 |
st.markdown("---")
|
| 98 |
c1, c2, c3 = st.columns(3)
|
| 99 |
with c1:
|
|
|
|
| 108 |
# 2. YÖNETİM TAVSİYESİ
|
| 109 |
st.markdown("---")
|
| 110 |
st.markdown("<h3 style='text-align: center;'>👔 Management Advice / Yönetim Tavsiyesi</h3>", unsafe_allow_html=True)
|
| 111 |
+
advice_col_en, advice_col_tr = st.columns(2)
|
| 112 |
+
with advice_col_en:
|
| 113 |
+
if current_max >= busy_limit:
|
| 114 |
+
st.warning("**High Demand Advice:** Peak days detected. We suggest increasing staff and checking room inventory.")
|
| 115 |
+
else:
|
| 116 |
+
st.success("**Stable Demand Advice:** Demand is within normal range. Good time for maintenance.")
|
| 117 |
+
with advice_col_tr:
|
| 118 |
+
if current_max >= busy_limit:
|
| 119 |
+
st.warning("**Yoğun Talep Tavsiyesi:** Zirve günler tespit edildi. Personel sayısını artırmayı ve envanteri kontrol etmeyi öneririz.")
|
| 120 |
+
else:
|
| 121 |
+
st.success("**Stabil Talep Tavsiyesi:** Talep normal aralıkta. Bakım ve temizlik işleri için uygun zaman.")
|
| 122 |
|
| 123 |
# 3. SONUÇ TABLOSU
|
| 124 |
st.markdown("---")
|
| 125 |
st.subheader("📋 Results Table / Sonuç Tablosu")
|
| 126 |
+
result_df = pd.DataFrame({
|
| 127 |
+
"Actual / Gerçek": raw_data.flatten(),
|
| 128 |
+
"Predicted / Tahmin": predictions
|
| 129 |
+
})
|
| 130 |
+
st.dataframe(result_df, use_container_width=True, height=250)
|
| 131 |
+
|
| 132 |
+
st.download_button("📥 Download Results / Sonuçları İndir", result_df.to_csv(index=False).encode('utf-8'), "hotel_results.csv", "text/csv")
|
| 133 |
|
| 134 |
# 4. GRAFİK
|
| 135 |
st.markdown("---")
|
|
|
|
| 141 |
ax.legend(prop={'size': 8})
|
| 142 |
st.pyplot(fig)
|
| 143 |
|
| 144 |
+
# 5. VERİ ÖN İZLEME (EN ALTTA)
|
| 145 |
st.markdown("---")
|
| 146 |
+
st.subheader("📊 Data Preview / Veri Ön İzleme (Raw Data)")
|
| 147 |
st.dataframe(df, use_container_width=True, height=150)
|
| 148 |
|
| 149 |
else:
|