ESMATUGBA commited on
Commit
f2b55bf
·
verified ·
1 Parent(s): 78ff1a7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +34 -22
src/streamlit_app.py CHANGED
@@ -1,7 +1,7 @@
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')
@@ -21,7 +21,7 @@ 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:
@@ -35,30 +35,42 @@ except Exception as 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,7 +80,7 @@ st.markdown("<h1 style='text-align: center;'>🏨 Hotel Demand Forecasting / Ote
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)
@@ -78,35 +90,35 @@ if file is not None:
78
  busy_limit = int(avg_val * 1.2)
79
  current_max = int(predictions.max())
80
 
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("---")
93
  st.markdown("<h3 style='text-align: center;'>👔 Management Advice / Yönetim Tavsiyesi</h3>", unsafe_allow_html=True)
94
- ce, ct = st.columns(2)
95
- with ce:
96
  if current_max >= busy_limit: st.warning("**High Demand Advice:** Peak days detected. Increase staff.")
97
  else: st.success("**Stable Demand Advice:** Demand is normal. Focus on maintenance.")
98
- with ct:
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()
@@ -117,7 +129,7 @@ if file is not None:
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)
 
1
  import os
2
  import warnings
3
 
4
+ # --- TİTREMEYİ VE GEREKSİZ LOGLARI ENGELLE ---
5
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
6
  os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
7
  warnings.filterwarnings('ignore')
 
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ı! Lütfen Hugging Face klasörünüzü kontrol edin.")
25
  st.stop()
26
  model = load_model(model_file)
27
  with open(scaler_file, "rb") as f:
 
35
  st.stop()
36
 
37
  # ==========================================
38
+ # SIDEBAR / SOL PANEL (TÜM BİLGİLER BURADA)
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("""
46
+ **Format:** Sütun adı **'bookings'** olan bir CSV yükleyin.
47
 
48
+ | bookings |
49
+ | :--- |
50
+ | 120 |
51
+ | 155 |
52
+ """)
53
+
54
+ # 2. ANALİZİ BAŞLAT (İstediğin yer: Rehberin hemen altı)
55
  st.markdown("### 🚀 Start Analysis / Analizi Başlat")
56
+ file = st.file_uploader("Upload CSV / CSV Yükle", type=["csv"])
57
 
58
  st.markdown("---")
59
 
60
+ # 3. BOOKINGS NEDİR?
61
  st.markdown("### ❓ What is 'Bookings'? / 'Bookings' Nedir?")
62
+ st.write("""
63
+ **EN:** Total daily reservations. (Example: 150 means 150 rooms sold)
64
+
65
+ **TR:** Günlük toplam rezervasyon. (Örn: 150 değeri o gün 150 oda satıldığını gösterir)
66
+ """)
67
 
68
  st.markdown("---")
69
 
70
+ # 4. YOĞUNLUK MANTIĞI
71
  st.markdown("### 📊 Thresholds / Yoğunluk")
72
+ st.warning("**High (Yoğun):** > Ortalamadan %20 fazla")
73
+ st.success("**Stable (Stabil):** Normal aralıkta")
74
 
75
  # ==========================================
76
  # MAIN CONTENT / ANA SAYFA
 
80
  if file is not None:
81
  df = pd.read_csv(file)
82
 
83
+ # AI TAHMİN SÜRECİ
84
  raw_data = df[["bookings"]].values
85
  data_scaled = sc.transform(raw_data)
86
  predictions_scaled = model.predict(data_scaled, verbose=0)
 
90
  busy_limit = int(avg_val * 1.2)
91
  current_max = int(predictions.max())
92
 
93
+ # 1. METRİKLER (EN ÜSTTE)
94
  st.markdown("---")
95
  c1, c2, c3 = st.columns(3)
96
  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)
97
  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)
98
  with c3:
99
+ status_color = "#e67e22" if current_max >= busy_limit else "#27ae60"
100
+ status_text = "HIGH / YOĞUN" if current_max >= busy_limit else "STABLE / STABİL"
101
+ st.markdown(f"<div style='text-align: center;'><strong>Status / Durum</strong><br><span style='font-size: 40px; color: {status_color}; font-weight: bold;'>{status_text}</span></div>", unsafe_allow_html=True)
102
 
103
+ # 2. YÖNETİM TAVSİYESİ (ÜSTTE)
104
  st.markdown("---")
105
  st.markdown("<h3 style='text-align: center;'>👔 Management Advice / Yönetim Tavsiyesi</h3>", unsafe_allow_html=True)
106
+ adv_en, adv_tr = st.columns(2)
107
+ with adv_en:
108
  if current_max >= busy_limit: st.warning("**High Demand Advice:** Peak days detected. Increase staff.")
109
  else: st.success("**Stable Demand Advice:** Demand is normal. Focus on maintenance.")
110
+ with adv_tr:
111
  if current_max >= busy_limit: st.warning("**Yoğun Talep Tavsiyesi:** Zirve günler tespit edildi. Personel artırın.")
112
  else: st.success("**Stabil Talep Tavsiyesi:** Talep normal. Bakım işlerine odaklanılabilir.")
113
 
114
+ # 3. SONUÇ TABLOSU (GRAFİK ÜSTÜNDE)
115
  st.markdown("---")
116
  st.subheader("📋 Results Table / Sonuç Tablosu")
117
  res_df = pd.DataFrame({"Actual / Gerçek": raw_data.flatten(), "Predicted / Tahmin": predictions})
118
  st.dataframe(res_df, width=1200, height=250)
119
  st.download_button("📥 Download Results", res_df.to_csv(index=False).encode('utf-8'), "hotel_results.csv", "text/csv")
120
 
121
+ # 4. GRAFİK
122
  st.markdown("---")
123
  st.subheader("📈 Prediction Graph / Tahmin Grafiği")
124
  plt.clf()
 
129
  ax.legend(prop={'size': 8})
130
  st.pyplot(fig, clear_figure=True)
131
 
132
+ # 5. VERİ ÖN İZLEME (EN ALTTA)
133
  st.markdown("---")
134
  st.subheader("📊 Data Preview / Veri Ön İzleme")
135
  st.dataframe(df, width=1200, height=150)