ESMATUGBA commited on
Commit
a2c0c93
·
verified ·
1 Parent(s): 60fa8f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -37
app.py CHANGED
@@ -4,6 +4,12 @@ import numpy as np
4
  import matplotlib.pyplot as plt
5
  import pickle
6
  import os
 
 
 
 
 
 
7
  from tensorflow.keras.models import load_model
8
 
9
  # Sayfa Yapılandırması
@@ -15,7 +21,7 @@ def load_assets():
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)
@@ -30,49 +36,36 @@ except Exception as 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,17 +76,17 @@ st.markdown("<h1 style='text-align: center;'>🏨 Hotel Demand Forecasting / Ote
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)
90
  predictions = sc.inverse_transform(predictions_scaled).flatten().astype(int)
91
 
92
  avg_val = int(predictions.mean())
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,28 +101,28 @@ if file is not None:
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,10 +134,10 @@ if file is not None:
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:
150
  st.warning("👈 Please upload a CSV file from the left panel. / Lütfen sol panelden bir CSV dosyası yükleyin.")
 
4
  import matplotlib.pyplot as plt
5
  import pickle
6
  import os
7
+ import warnings
8
+
9
+ # Gereksiz uyarıları ve log kalabalığını gizle
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ı
 
21
  scaler_file = "scaler.pkl"
22
 
23
  if not os.path.exists(model_file) or not os.path.exists(scaler_file):
24
+ st.error("❌ Required files (model or scaler) are missing!")
25
  st.stop()
26
 
27
  model = load_model(model_file)
 
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
  st.info("""
45
+ **How to Upload? / Nasıl Yüklenmeli?**
46
+ CSV Format:
47
  | bookings |
48
  | :--- |
49
  | 120 |
50
  | 155 |
 
 
 
 
51
  """)
52
 
53
  st.markdown("---")
54
 
 
55
  st.markdown("### ❓ What is 'Bookings'? / 'Bookings' Nedir?")
56
  st.write("""
57
+ **EN:** Total daily reservations. (Example: 150 = 150 rooms sold)
58
+ **TR:** Günlük toplam rezervasyon. (Örnek: 150 = 150 oda satıldı)
 
 
 
 
59
  """)
60
 
61
  st.markdown("---")
62
 
 
63
  st.markdown("### 📊 Thresholds / Yoğunluk")
64
+ st.warning("**High Demand (Yoğun):**\n> Average + 20%")
65
+ st.success("**Stable (Stabil):**\nNormal range")
66
 
67
  st.markdown("---")
68
 
 
 
69
  file = st.file_uploader("Upload CSV / CSV Yükle", type=["csv"])
70
 
71
  # ==========================================
 
76
  if file is not None:
77
  df = pd.read_csv(file)
78
 
79
+ # AI Tahmin İşlemleri
80
  raw_data = df[["bookings"]].values
81
  data_scaled = sc.transform(raw_data)
82
+ predictions_scaled = model.predict(data_scaled, verbose=0) # verbose=0 log kirliliğini önler
83
  predictions = sc.inverse_transform(predictions_scaled).flatten().astype(int)
84
 
85
  avg_val = int(predictions.mean())
86
  busy_limit = int(avg_val * 1.2)
87
  current_max = int(predictions.max())
88
 
89
+ # 1. METRİKLER
90
  st.markdown("---")
91
  c1, c2, c3 = st.columns(3)
92
  with c1:
 
101
  # 2. YÖNETİM TAVSİYESİ
102
  st.markdown("---")
103
  st.markdown("<h3 style='text-align: center;'>👔 Management Advice / Yönetim Tavsiyesi</h3>", unsafe_allow_html=True)
104
+ adv_en, adv_tr = st.columns(2)
105
+ with adv_en:
106
  if current_max >= busy_limit:
107
+ st.warning("**High Demand Advice:** Peak days detected. Increase staff.")
108
  else:
109
+ st.success("**Stable Demand Advice:** Demand is normal. Focus on maintenance.")
110
+ with adv_tr:
111
  if current_max >= busy_limit:
112
+ st.warning("**Yoğun Talep Tavsiyesi:** Zirve günler tespit edildi. Personel artırın.")
113
  else:
114
+ st.success("**Stabil Talep Tavsiyesi:** Talep normal. Bakım işlerine odaklanılabilir.")
115
 
116
+ # 3. SONUÇ TABLOSU (width='stretch' ile güncellendi)
117
  st.markdown("---")
118
  st.subheader("📋 Results Table / Sonuç Tablosu")
119
  result_df = pd.DataFrame({
120
  "Actual / Gerçek": raw_data.flatten(),
121
  "Predicted / Tahmin": predictions
122
  })
123
+ st.dataframe(result_df, width=None, height=250) # width=None otomatik stretch yapar
124
 
125
+ st.download_button("📥 Download Results", result_df.to_csv(index=False).encode('utf-8'), "hotel_results.csv", "text/csv")
126
 
127
  # 4. GRAFİK
128
  st.markdown("---")
 
134
  ax.legend(prop={'size': 8})
135
  st.pyplot(fig)
136
 
137
+ # 5. VERİ ÖN İZLEME
138
  st.markdown("---")
139
+ st.subheader("📊 Data Preview / Veri Ön İzleme")
140
+ st.dataframe(df, width=None, height=150)
141
 
142
  else:
143
  st.warning("👈 Please upload a CSV file from the left panel. / Lütfen sol panelden bir CSV dosyası yükleyin.")