ESMATUGBA commited on
Commit
094b146
·
verified ·
1 Parent(s): 6dbfdcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -90
app.py CHANGED
@@ -3,31 +3,37 @@ import pandas as pd
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
- import os
7
 
8
- # 1. TİTREME KİLİDİ
9
- os.environ["STREAMLIT_SERVER_FILE_WATCHER_TYPE"] = "none"
10
-
11
- # 2. SAYFA AYARI
12
  st.set_page_config(page_title="Fast Food Nutrition Guide", layout="wide")
13
 
14
- # 3. VERİ YÜKLEME (CACHE)
15
- @st.cache_data(show_spinner=False)
16
- def load_data_final():
17
- path = "Nutrition_Value_Dataset.csv"
18
- try:
19
- data = pd.read_csv(path).replace([np.inf, -np.inf], np.nan).dropna()
20
- return data
21
- except:
22
- return None
 
 
 
 
23
 
24
- df = load_data_final()
25
 
26
- if df is None:
 
 
27
  st.error("CSV file not found! / Veri seti dosyası bulunamadı!")
28
  st.stop()
29
 
30
- # --- SIDEBAR (SOL PANEL - TÜM METİNLER GÜNCELLENDİ) ---
 
 
31
  st.sidebar.title("🏥 Health & Calorie Guide / Sağlık ve Kalori Rehberi")
32
 
33
  st.sidebar.subheader("⚖️ Daily Calorie Needs / Günlük Kalori İhtiyacı")
@@ -36,97 +42,86 @@ st.sidebar.write("""
36
  - **Men / Erkekler:** 2,500 kcal
37
  """)
38
 
39
- # İstediğin Sağlık Öğüdü
40
  st.sidebar.warning("""
41
- ⚠️ **Health Advice / Sağlık Öğüdü:** Fast food meals are high in sodium and low in nutrients.
42
- *Fast food öğünleri sodyum bakımından yüksek, besin değeri bakımından düşüktür.*
43
  """)
44
 
45
- # İstediğin Pratik Bilgi
46
  st.sidebar.info("""
47
- 💡 **Quick Tip / Pratik Bilgi:** Choosing water over soda can reduce your meal's sugar content by 40-60g.
48
- *Asitli içecek yerine su seçmek, öğününüzdeki şeker miktarını 40-60 gr azaltabilir.*
49
  """)
50
 
51
- # --- ANA SAYFA BAŞLIK ---
52
- st.title("🍔 Global Fast Food Nutrition Analysis / Küresel Fast Food Besin Analizi")
 
 
53
 
54
- # --- TÜKETİCİYE KRİTİK NOT (YAN YANA) ---
55
- st.error("### 📢 Important Notice for Consumers / Tüketiciler İçin Önemli Not")
 
 
56
 
57
  col_note_tr, col_note_en = st.columns(2)
58
 
59
  with col_note_tr:
60
- st.markdown("""
61
- **Aşağıdaki verilere istinaden, bu şirketlerden yemek tüketilmemesi sağlığınız için şu nedenlerle yararlı olacaktır:**
62
-
63
- 1. **Kalp Sağlığı:** Yüksek trans yağ ve sodyum içeriği tansiyona neden olur.
64
- 2. **Kan Şekeri Dengesi:** Aşırı şeker diyabet riskini tetikler.
65
- 3. **Besin Değeri Eksikliği:** Bu ürünler "boş kalori" kaynağıdır.
66
- 4. **Obezite Riski:** **Pizza Hut, Burger King, KFC, McDonald’s ve Starbucks** şirketlerinden yüksek kalori yoğunluğu olacağından kısa sürede kontrolsüz kilo alımına yol açar.
67
-
68
- * **🥤 Su İçin:** Sağlığınız için su tüketin.
69
- """)
70
 
71
  with col_note_en:
72
- st.markdown("""
73
- **Based on the data below, avoiding these companies' meals will benefit your health:**
74
-
75
- 1. **Heart Health:** High trans fat and sodium cause high blood pressure.
76
- 2. **Blood Sugar:** Excessive sugar triggers diabetes risk.
77
- 3. **Lack of Nutrients:** These products are sources of "empty calories".
78
- 4. **Obesity Risk:** Foods from **Pizza Hut, Burger King, KFC, McDonald’s, and Starbucks** lead to rapid weight gain.
79
-
80
- * **🥤 Drink Water:** Choosing water is critical for your health.
81
- """)
82
 
83
  st.write("---")
84
 
85
- # --- ÖDEV METNİ (BÜYÜTÜLMÜŞ) ---
86
- st.markdown("""
87
- <div style="text-align: center; border: 1px solid #ddd; padding: 15px; border-radius: 10px; background-color: #f9f9f9;">
88
- <h3 style="color: #1E1E1E; font-weight: bold; margin: 0;">
89
- 🔍 Bu çalışma, fast food ürünlerinin kalori ve şeker içeriklerini görselleştirerek genel bir sağlık tablosu sunmaktadır.
90
- </h3>
91
- <h4 style="color: #555555; margin: 10px 0 0 0;">
92
- This study provides a general health overview by visualizing the calorie and sugar content of fast food products.
93
- </h4>
94
- </div>
95
- """, unsafe_allow_html=True)
96
 
97
- st.write("---")
98
 
99
- # --- GRAFİKLER ---
100
- if df is not None:
101
- st.subheader("📊 General Visual Analysis / Genel Görsel Analiz")
102
- gc1, gc2 = st.columns(2)
103
-
104
- with gc1:
105
- st.write("🍭 **Average Sugar / Ort. Şeker**")
106
- sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
107
- fig1, ax1 = plt.subplots(figsize=(6, 4))
108
- sugar_means.plot(kind="bar", color="crimson", ax=ax1)
109
- plt.xticks(rotation=45, fontsize=8)
110
- st.pyplot(fig1)
111
-
112
- with gc2:
113
- st.write("🔥 **Calorie Distribution / Dağılım**")
114
- fig2, ax2 = plt.subplots(figsize=(6, 4))
115
- sns.histplot(df["Energy (kCal)"], bins=20, kde=True, ax=ax2, color="darkorange")
116
- st.pyplot(fig2)
117
-
118
- # --- VERİ TABLOSU (TABLO BURADA VE GÖRÜNÜR) ---
119
- st.write("---")
120
- st.subheader("📋 High-Calorie Products List / Yüksek Kalorili Ürün Listesi")
121
 
122
- if df is not None:
123
- top_20 = df.sort_values(by="Energy (kCal)", ascending=False).head(20)
124
- # Loglardaki hatayı kesmek için width ayarını güncelledik
125
- st.dataframe(
126
- top_20[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)"]],
127
- use_container_width=True
128
- )
129
 
130
- # --- DOWNLOAD ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  st.write("---")
132
- st.download_button("📥 Download Full Dataset / Tüm Veriyi İndir", df.to_csv(index=False), "data.csv", "text/csv")
 
 
 
 
 
 
 
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
 
6
 
7
+ # =========================
8
+ # SAYFA AYARLARI
9
+ # =========================
 
10
  st.set_page_config(page_title="Fast Food Nutrition Guide", layout="wide")
11
 
12
+ # =========================
13
+ # DATA LOAD (CACHE EKLENDİ)
14
+ # =========================
15
+ @st.cache_data
16
+ def load_data():
17
+ path = "Nutrition_Value_Dataset.csv"
18
+ df = pd.read_csv(path)
19
+
20
+ df = df.replace([np.inf, -np.inf], np.nan)
21
+
22
+ # ❗ DROPNA KALDIRILDI
23
+ numeric_cols = df.select_dtypes(include=[np.number]).columns
24
+ df[numeric_cols] = df[numeric_cols].fillna(df[numeric_cols].median())
25
 
26
+ return df
27
 
28
+ try:
29
+ df = load_data()
30
+ except:
31
  st.error("CSV file not found! / Veri seti dosyası bulunamadı!")
32
  st.stop()
33
 
34
+ # =========================
35
+ # SIDEBAR
36
+ # =========================
37
  st.sidebar.title("🏥 Health & Calorie Guide / Sağlık ve Kalori Rehberi")
38
 
39
  st.sidebar.subheader("⚖️ Daily Calorie Needs / Günlük Kalori İhtiyacı")
 
42
  - **Men / Erkekler:** 2,500 kcal
43
  """)
44
 
 
45
  st.sidebar.warning("""
46
+ ⚠️ Health Advice:
47
+ Fast food meals are high in sodium.
48
  """)
49
 
 
50
  st.sidebar.info("""
51
+ 💡 Drink water instead of soda
 
52
  """)
53
 
54
+ # =========================
55
+ # TITLE
56
+ # =========================
57
+ st.title("🍔 Global Fast Food Nutrition Analysis")
58
 
59
+ # =========================
60
+ # TEXT
61
+ # =========================
62
+ st.error("### 📢 Important Notice")
63
 
64
  col_note_tr, col_note_en = st.columns(2)
65
 
66
  with col_note_tr:
67
+ st.markdown("Fast food sağlığa zararlıdır")
 
 
 
 
 
 
 
 
 
68
 
69
  with col_note_en:
70
+ st.markdown("Fast food is unhealthy")
 
 
 
 
 
 
 
 
 
71
 
72
  st.write("---")
73
 
74
+ # =========================
75
+ # GRAFİKLER (TİTREME FIX)
76
+ # =========================
77
+ st.subheader("📊 General Visual Analysis")
 
 
 
 
 
 
 
78
 
79
+ c1, c2 = st.columns(2)
80
 
81
+ with c1:
82
+ st.write("🍭 Sugar by Company")
83
+
84
+ sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
85
+
86
+ fig, ax = plt.subplots(figsize=(6, 4))
87
+ sugar_means.plot(kind="bar", color="crimson", ax=ax)
88
+
89
+ ax.tick_params(axis='x', rotation=45)
90
+
91
+ st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
 
92
 
93
+ plt.close(fig) # 🔥 KRİTİK
 
 
 
 
 
 
94
 
95
+ with c2:
96
+ st.write("🔥 Calorie Distribution")
97
+
98
+ fig2, ax2 = plt.subplots(figsize=(6, 4))
99
+ sns.histplot(df["Energy (kCal)"], bins=20, kde=True, ax=ax2)
100
+
101
+ st.pyplot(fig2)
102
+
103
+ plt.close(fig2) # 🔥 KRİTİK
104
+
105
+ # =========================
106
+ # TABLE (YENİ WIDTH PARAM)
107
+ # =========================
108
+ st.subheader("📋 High-Calorie Products")
109
+
110
+ top_20 = df.sort_values(by="Energy (kCal)", ascending=False).head(20)
111
+
112
+ st.dataframe(
113
+ top_20[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)", "Total Fat (g)"]],
114
+ width="stretch" # 🔥 YENİ PARAM
115
+ )
116
+
117
+ # =========================
118
+ # DOWNLOAD
119
+ # =========================
120
  st.write("---")
121
+
122
+ st.download_button(
123
+ "📥 Download Dataset",
124
+ df.to_csv(index=False),
125
+ "fastfood.csv",
126
+ "text/csv"
127
+ )