Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,16 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import numpy as np
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
-
import pickle
|
| 6 |
import os
|
| 7 |
import warnings
|
| 8 |
|
| 9 |
-
#
|
|
|
|
|
|
|
| 10 |
warnings.filterwarnings('ignore')
|
| 11 |
-
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from tensorflow.keras.models import load_model
|
| 14 |
|
| 15 |
# Sayfa Yapılandırması
|
|
@@ -19,11 +20,9 @@ st.set_page_config(page_title="Hotel AI Decision Support", layout="wide")
|
|
| 19 |
def load_assets():
|
| 20 |
model_file = "hotel_model.keras"
|
| 21 |
scaler_file = "scaler.pkl"
|
| 22 |
-
|
| 23 |
if not os.path.exists(model_file) or not os.path.exists(scaler_file):
|
| 24 |
-
st.error("❌
|
| 25 |
st.stop()
|
| 26 |
-
|
| 27 |
model = load_model(model_file)
|
| 28 |
with open(scaler_file, "rb") as f:
|
| 29 |
sc = pickle.load(f)
|
|
@@ -32,55 +31,34 @@ def load_assets():
|
|
| 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("<h2 style='color: #2980b9;'>📖 User Guide / Rehber</h2>", unsafe_allow_html=True)
|
| 43 |
|
| 44 |
# 1. NASIL YÜKLENMELİ?
|
| 45 |
st.markdown("### 📥 How to Upload? / Nasıl Yüklenmeli?")
|
| 46 |
-
st.info(""
|
| 47 |
-
**CSV Format Example:**
|
| 48 |
-
| bookings |
|
| 49 |
-
| :--- |
|
| 50 |
-
| 120 |
|
| 51 |
-
| 155 |
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
""")
|
| 56 |
|
| 57 |
st.markdown("---")
|
| 58 |
|
| 59 |
-
#
|
| 60 |
st.markdown("### ❓ What is 'Bookings'? / 'Bookings' Nedir?")
|
| 61 |
-
st.
|
| 62 |
-
**EN:** It represents the total number of reservations made on that day.
|
| 63 |
-
|
| 64 |
-
**TR:** O gün yapılan toplam rezervasyon sayısıdır.
|
| 65 |
-
|
| 66 |
-
**Example / Örnek:**
|
| 67 |
-
If value is **150**, it means 150 rooms were booked/sold that day for the hotel.
|
| 68 |
-
Eğer değer **150** ise, bu o gün o otel için 150 tane oda ayrıldığı anlamına gelir.
|
| 69 |
-
""")
|
| 70 |
-
|
| 71 |
-
st.markdown("---")
|
| 72 |
-
|
| 73 |
-
# 3. YOĞUNLUK VE STABİLİTE MANTIĞI
|
| 74 |
-
st.markdown("### 📊 Thresholds / Yoğunluk & Stabilite")
|
| 75 |
-
st.write("**How does AI decide? / YZ nasıl karar verir?**")
|
| 76 |
-
st.warning("**High Demand (Yoğun):** Forecast is 20% above the average. / Tahmin ortalamanın %20 üzerindeyse.")
|
| 77 |
-
st.success("**Stable (Stabil):** Forecast is within normal limits. / Tahmin normal sınırlar içerisindeyse.")
|
| 78 |
|
| 79 |
st.markdown("---")
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
st.
|
| 83 |
-
|
| 84 |
|
| 85 |
# ==========================================
|
| 86 |
# MAIN CONTENT / ANA SAYFA
|
|
@@ -90,10 +68,10 @@ st.markdown("<h1 style='text-align: center;'>🏨 Hotel Demand Forecasting / Ote
|
|
| 90 |
if file is not None:
|
| 91 |
df = pd.read_csv(file)
|
| 92 |
|
| 93 |
-
#
|
| 94 |
raw_data = df[["bookings"]].values
|
| 95 |
data_scaled = sc.transform(raw_data)
|
| 96 |
-
predictions_scaled = model.predict(data_scaled, verbose=0)
|
| 97 |
predictions = sc.inverse_transform(predictions_scaled).flatten().astype(int)
|
| 98 |
|
| 99 |
avg_val = int(predictions.mean())
|
|
@@ -103,14 +81,12 @@ if file is not None:
|
|
| 103 |
# 1. METRİKLER
|
| 104 |
st.markdown("---")
|
| 105 |
c1, c2, c3 = st.columns(3)
|
| 106 |
-
with c1:
|
| 107 |
-
|
| 108 |
-
with c2:
|
| 109 |
-
st.markdown(f"<div style='text-align: center;'><strong>Busy Threshold / Yoğunluk Sınırı</strong><br><span style='font-size: 45px; color: #e74c3c;'>{busy_limit}</span></div>", unsafe_allow_html=True)
|
| 110 |
with c3:
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
st.markdown(f"<div style='text-align: center;'><strong>Status / Durum</strong><br><span style='font-size: 40px; color: {
|
| 114 |
|
| 115 |
# 2. YÖNETİM TAVSİYESİ
|
| 116 |
st.markdown("---")
|
|
@@ -123,28 +99,28 @@ if file is not None:
|
|
| 123 |
if current_max >= busy_limit: st.warning("**Yoğun Talep Tavsiyesi:** Zirve günler tespit edildi. Personel artırın.")
|
| 124 |
else: st.success("**Stabil Talep Tavsiyesi:** Talep normal. Bakım işlerine odaklanılabilir.")
|
| 125 |
|
| 126 |
-
# 3. SONUÇ TABLOSU
|
| 127 |
st.markdown("---")
|
| 128 |
st.subheader("📋 Results Table / Sonuç Tablosu")
|
| 129 |
res_df = pd.DataFrame({"Actual / Gerçek": raw_data.flatten(), "Predicted / Tahmin": predictions})
|
| 130 |
-
st.dataframe(res_df, width=
|
| 131 |
-
|
| 132 |
st.download_button("📥 Download Results", res_df.to_csv(index=False).encode('utf-8'), "hotel_results.csv", "text/csv")
|
| 133 |
|
| 134 |
-
# 4. GRAFİK
|
| 135 |
st.markdown("---")
|
| 136 |
st.subheader("📈 Prediction Graph / Tahmin Grafiği")
|
|
|
|
| 137 |
fig, ax = plt.subplots(figsize=(10, 3.5))
|
| 138 |
ax.plot(raw_data, label="Actual / Gerçek", color="#bdc3c7", alpha=0.6, linestyle='--')
|
| 139 |
ax.plot(predictions, label="AI Forecast / YZ Tahmini", color="#2980b9", linewidth=2)
|
| 140 |
ax.axhline(y=busy_limit, color='#e74c3c', linestyle=':', label="Limit")
|
| 141 |
ax.legend(prop={'size': 8})
|
| 142 |
-
st.pyplot(fig)
|
| 143 |
|
| 144 |
# 5. VERİ ÖN İZLEME
|
| 145 |
st.markdown("---")
|
| 146 |
st.subheader("📊 Data Preview / Veri Ön İzleme")
|
| 147 |
-
st.dataframe(df, width=
|
| 148 |
|
| 149 |
else:
|
| 150 |
st.warning("👈 Please upload a CSV file from the left panel. / Lütfen sol panelden bir CSV dosyası yükleyin.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import warnings
|
| 3 |
|
| 4 |
+
# --- TİTREMEYİ ENGELLEYEN AYARLAR ---
|
| 5 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
| 6 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 7 |
warnings.filterwarnings('ignore')
|
|
|
|
| 8 |
|
| 9 |
+
import streamlit as st
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import numpy as np
|
| 12 |
+
import matplotlib.pyplot as plt
|
| 13 |
+
import pickle
|
| 14 |
from tensorflow.keras.models import load_model
|
| 15 |
|
| 16 |
# Sayfa Yapılandırması
|
|
|
|
| 20 |
def load_assets():
|
| 21 |
model_file = "hotel_model.keras"
|
| 22 |
scaler_file = "scaler.pkl"
|
|
|
|
| 23 |
if not os.path.exists(model_file) or not os.path.exists(scaler_file):
|
| 24 |
+
st.error("❌ Dosyalar bulunamadı!")
|
| 25 |
st.stop()
|
|
|
|
| 26 |
model = load_model(model_file)
|
| 27 |
with open(scaler_file, "rb") as f:
|
| 28 |
sc = pickle.load(f)
|
|
|
|
| 31 |
try:
|
| 32 |
model, sc = load_assets()
|
| 33 |
except Exception as e:
|
| 34 |
+
st.error(f"⚠️ Yükleme Hatası: {e}")
|
| 35 |
st.stop()
|
| 36 |
|
| 37 |
# ==========================================
|
| 38 |
+
# SIDEBAR / SOL PANEL (YENİ DÜZEN)
|
| 39 |
# ==========================================
|
| 40 |
with st.sidebar:
|
| 41 |
st.markdown("<h2 style='color: #2980b9;'>📖 User Guide / Rehber</h2>", unsafe_allow_html=True)
|
| 42 |
|
| 43 |
# 1. NASIL YÜKLENMELİ?
|
| 44 |
st.markdown("### 📥 How to Upload? / Nasıl Yüklenmeli?")
|
| 45 |
+
st.info("**Format:** Sütun adı 'bookings' olan bir CSV yükleyin.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
# 2. ANALİZİ BAŞLAT (İSTEDİĞİN YERE TAŞINDI)
|
| 48 |
+
st.markdown("### 🚀 Start Analysis / Analizi Başlat")
|
| 49 |
+
file = st.sidebar.file_uploader("Upload CSV / CSV Yükle", type=["csv"])
|
| 50 |
|
| 51 |
st.markdown("---")
|
| 52 |
|
| 53 |
+
# 3. DİĞER BİLGİLER (ALT KISIMDA KORUNDU)
|
| 54 |
st.markdown("### ❓ What is 'Bookings'? / 'Bookings' Nedir?")
|
| 55 |
+
st.write("O gün yapılan toplam rezervasyon sayısıdır. Örn: 150 oda satıldı.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
st.markdown("---")
|
| 58 |
|
| 59 |
+
st.markdown("### 📊 Thresholds / Yoğunluk")
|
| 60 |
+
st.warning("**High (Yoğun):** Ortalama + %20")
|
| 61 |
+
st.success("**Stable (Stabil):** Normal aralık")
|
| 62 |
|
| 63 |
# ==========================================
|
| 64 |
# MAIN CONTENT / ANA SAYFA
|
|
|
|
| 68 |
if file is not None:
|
| 69 |
df = pd.read_csv(file)
|
| 70 |
|
| 71 |
+
# TAHMİN (Sessiz Mod)
|
| 72 |
raw_data = df[["bookings"]].values
|
| 73 |
data_scaled = sc.transform(raw_data)
|
| 74 |
+
predictions_scaled = model.predict(data_scaled, verbose=0)
|
| 75 |
predictions = sc.inverse_transform(predictions_scaled).flatten().astype(int)
|
| 76 |
|
| 77 |
avg_val = int(predictions.mean())
|
|
|
|
| 81 |
# 1. METRİKLER
|
| 82 |
st.markdown("---")
|
| 83 |
c1, c2, c3 = st.columns(3)
|
| 84 |
+
with c1: st.markdown(f"<div style='text-align: center;'><strong>Avg Forecast / Ort. Tahmin</strong><br><span style='font-size: 45px; color: #2980b9;'>{avg_val}</span></div>", unsafe_allow_html=True)
|
| 85 |
+
with c2: st.markdown(f"<div style='text-align: center;'><strong>Busy Threshold / Yoğunluk Sınırı</strong><br><span style='font-size: 45px; color: #e74c3c;'>{busy_limit}</span></div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
| 86 |
with c3:
|
| 87 |
+
color = "#e67e22" if current_max >= busy_limit else "#27ae60"
|
| 88 |
+
text = "HIGH / YOĞUN" if current_max >= busy_limit else "STABLE / STABİL"
|
| 89 |
+
st.markdown(f"<div style='text-align: center;'><strong>Status / Durum</strong><br><span style='font-size: 40px; color: {color}; font-weight: bold;'>{text}</span></div>", unsafe_allow_html=True)
|
| 90 |
|
| 91 |
# 2. YÖNETİM TAVSİYESİ
|
| 92 |
st.markdown("---")
|
|
|
|
| 99 |
if current_max >= busy_limit: st.warning("**Yoğun Talep Tavsiyesi:** Zirve günler tespit edildi. Personel artırın.")
|
| 100 |
else: st.success("**Stabil Talep Tavsiyesi:** Talep normal. Bakım işlerine odaklanılabilir.")
|
| 101 |
|
| 102 |
+
# 3. SONUÇ TABLOSU
|
| 103 |
st.markdown("---")
|
| 104 |
st.subheader("📋 Results Table / Sonuç Tablosu")
|
| 105 |
res_df = pd.DataFrame({"Actual / Gerçek": raw_data.flatten(), "Predicted / Tahmin": predictions})
|
| 106 |
+
st.dataframe(res_df, width=1200, height=250)
|
|
|
|
| 107 |
st.download_button("📥 Download Results", res_df.to_csv(index=False).encode('utf-8'), "hotel_results.csv", "text/csv")
|
| 108 |
|
| 109 |
+
# 4. GRAFİK (Sabitlenmiş)
|
| 110 |
st.markdown("---")
|
| 111 |
st.subheader("📈 Prediction Graph / Tahmin Grafiği")
|
| 112 |
+
plt.clf()
|
| 113 |
fig, ax = plt.subplots(figsize=(10, 3.5))
|
| 114 |
ax.plot(raw_data, label="Actual / Gerçek", color="#bdc3c7", alpha=0.6, linestyle='--')
|
| 115 |
ax.plot(predictions, label="AI Forecast / YZ Tahmini", color="#2980b9", linewidth=2)
|
| 116 |
ax.axhline(y=busy_limit, color='#e74c3c', linestyle=':', label="Limit")
|
| 117 |
ax.legend(prop={'size': 8})
|
| 118 |
+
st.pyplot(fig, clear_figure=True)
|
| 119 |
|
| 120 |
# 5. VERİ ÖN İZLEME
|
| 121 |
st.markdown("---")
|
| 122 |
st.subheader("📊 Data Preview / Veri Ön İzleme")
|
| 123 |
+
st.dataframe(df, width=1200, height=150)
|
| 124 |
|
| 125 |
else:
|
| 126 |
st.warning("👈 Please upload a CSV file from the left panel. / Lütfen sol panelden bir CSV dosyası yükleyin.")
|