ESMATUGBA commited on
Commit
8ef4521
·
verified ·
1 Parent(s): a5c28dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +118 -71
app.py CHANGED
@@ -4,89 +4,136 @@ import numpy as np
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
 
7
- # 1. AYAR: Sayfa Yapılandırması (Sabit)
8
- st.set_page_config(
9
- page_title="Fast Food Nutrition Guide",
10
- layout="wide",
11
- initial_sidebar_state="expanded"
12
- )
13
 
14
- # 2. AYAR: Veri Yükleme (Cache ile donduruldu - Titremeyi önler)
15
  @st.cache_data
16
- def get_data():
17
- try:
18
- data = pd.read_csv("Nutrition_Value_Dataset.csv")
19
- return data.replace([np.inf, -np.inf], np.nan).dropna()
20
- except:
21
- return None
22
-
23
- df = get_data()
24
-
25
- # --- SIDEBAR (SOL PANEL GERİ GELDİ) ---
26
- with st.sidebar:
27
- st.title("🏥 Health & Calorie Guide")
28
- st.subheader("⚖️ Daily Needs / Günlük İhtiyaç")
29
- st.write("- **Women / Kadınlar:** 2,000 kcal\n- **Men / Erkekler:** 2,500 kcal")
30
-
31
- st.warning("⚠️ **Health Advice:** Fast food is high in sodium and low in nutrients.")
32
-
33
- st.info("💡 **Quick Tip:** Choose water over soda to save 40-60g of sugar.")
34
-
35
- st.markdown("---")
36
- st.caption("© 2026 Nutrition Analysis Project")
 
 
 
 
 
 
37
 
38
- # --- ANA SAYFA ---
39
- st.title("🍔 Global Fast Food Nutrition Analysis")
 
 
 
40
 
41
- # KRİTİK NOT
 
 
 
42
  st.error("### 📢 Important Notice for Consumers / Tüketiciler İçin Önemli Not")
43
- c_tr, c_en = st.columns(2)
44
- with c_tr:
 
 
45
  st.markdown("""
46
- **Aşağıdaki verilere istinaden şu nedenlerle yemek tüketilmemelidir:**
47
- 1. **Kalp Sağlığı:** Tansiyon ve damar sertliği riski.
48
- 2. **Kan Şekeri:** Diyabet tetikleyici.
49
- 3. **Besin Değeri:** Vitamin ve mineral eksikliği.
50
- 4. **Obezite Riski:** **Pizza Hut, Burger King, KFC, McDonald’s ve Starbucks** ürünleri kontrolsüz kilo alımına yol açar.
 
 
 
 
51
  """)
52
- with c_en:
 
53
  st.markdown("""
54
- **Based on data, avoiding these meals is better for health because:**
55
- 1. **Heart Health:** Risk of high blood pressure.
56
- 2. **Blood Sugar:** Triggers diabetes risk.
57
- 3. **Lack of Nutrients:** Empty calorie sources.
58
- 4. **Obesity Risk:** High calorie products from **Pizza Hut, Burger King, KFC, McDonald’s, and Starbucks** lead to rapid weight gain.
 
 
 
 
59
  """)
60
 
61
  st.write("---")
62
 
63
- # PROJE ÖZETİ (Sabitlendi)
64
- st.markdown("<h2 style='text-align: center; color: #1E1E1E; font-weight: bold;'>🔍 Bu çalışma, fast food ürünlerinin kalori ve şeker içeriklerini görselleştirerek genel bir sağlık tablosu sunmaktadır.</h2>", unsafe_allow_html=True)
65
- st.markdown("<p style='text-align: center;'>This study provides a general health overview by visualizing nutritional content.</p>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
 
67
  st.write("---")
68
 
69
- # 3. AYAR: Grafikleri Kapsül İçine Al (Fragment ile sadece burası işlenir)
70
- @st.fragment
71
- def render_visuals(data):
72
- col1, col2 = st.columns(2)
73
- with col1:
74
- st.write("🍭 **Average Sugar / Ort. Şeker**")
75
- fig, ax = plt.subplots(figsize=(6, 4))
76
- data.groupby("Company")["Sugar (g)"].mean().sort_values().plot(kind="bar", color="crimson", ax=ax)
77
- plt.xticks(rotation=45)
78
- st.pyplot(fig)
79
- with col2:
80
- st.write("🔥 **Calorie Distribution / Kalori Dağılımı**")
81
- fig2, ax2 = plt.subplots(figsize=(6, 4))
82
- sns.histplot(data["Energy (kCal)"], bins=20, kde=True, ax=ax2, color="darkorange")
83
- st.pyplot(fig2)
84
-
85
- if df is not None:
86
- render_visuals(df)
87
-
88
- # TABLO
89
- st.subheader("📋 High-Calorie Products / Yüksek Kalorili Ürünler")
90
- if df is not None:
91
- top_20 = df.sort_values(by="Energy (kCal)", ascending=False).head(20)
92
- st.dataframe(top_20[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)"]], use_container_width=True)
 
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
 
7
+ # Sayfa Ayarları
8
+ st.set_page_config(page_title="Fast Food Nutrition Guide", layout="wide")
 
 
 
 
9
 
10
+ # DATA LOAD (CACHE EKLENDİ - TITREME FIX)
11
  @st.cache_data
12
+ def load_data():
13
+ path = "Nutrition_Value_Dataset.csv"
14
+ df = pd.read_csv(path)
15
+ df = df.replace([np.inf, -np.inf], np.nan)
16
+ df = df.dropna()
17
+ return df
18
+
19
+ try:
20
+ df = load_data()
21
+ except:
22
+ st.error("CSV file not found! / Veri seti dosyası bulunamadı!")
23
+ st.stop()
24
+
25
+ # --- SIDEBAR (SAĞLIK REHBERİ) ---
26
+ st.sidebar.title("🏥 Health & Calorie Guide / Sağlık ve Kalori Rehberi")
27
+
28
+ st.sidebar.subheader("⚖️ Daily Calorie Needs / Günlük Kalori İhtiyacı")
29
+ st.sidebar.write("""
30
+ - **Women / Kadınlar:** 2,000kcal
31
+ - **Men / Erkekler:** 2,500 kcal
32
+ """)
33
+
34
+ st.sidebar.warning("""
35
+ ⚠️ **Health Advice / Sağlık Öğüdü:**
36
+ Fast food meals are high in sodium and low in nutrients.
37
+ *Fast food öğünleri sodyum bakımından yüksek, besin değeri bakımından düşüktür.*
38
+ """)
39
 
40
+ st.sidebar.info("""
41
+ 💡 **Quick Tip / Pratik Bilgi:**
42
+ Choosing water over soda can reduce your meal's sugar content by 40-60g.
43
+ *Asitli içecek yerine su seçmek, öğününüzdeki şeker miktarını 40-60 gr azaltabilir.*
44
+ """)
45
 
46
+ # --- ANA SAYFA BAŞLIK ---
47
+ st.title("🍔 Global Fast Food Nutrition Analysis / Küresel Fast Food Besin Analizi")
48
+
49
+ # --- TÜKETİCİYE KRİTİK NOT ---
50
  st.error("### 📢 Important Notice for Consumers / Tüketiciler İçin Önemli Not")
51
+
52
+ col_note_tr, col_note_en = st.columns(2)
53
+
54
+ with col_note_tr:
55
  st.markdown("""
56
+ **Aşağıdaki verilere istinaden, bu şirketlerden yemek tüketilmemesi sağlığınız için şu nedenlerle yararlı olacaktır:**
57
+
58
+ 1. **Kalp Sağlığı:** Yüksek trans yağ ve sodyum içeriği damar sertliği ve tansiyona neden olur.
59
+ 2. **Kan Şekeri Dengesi:** Aşırı şeker ve işlenmiş karbonhidratlar ani insülin direnci ve diyabet riskini tetikler.
60
+ 3. **Besin Değeri Eksikliği:** Bu ürünler "boş kalori" kaynağıdır; vitamin, mineral ve lif açısından son derece fakirdir.
61
+ 4. **Obezite Riski:** Pizza Hut- Burger King -KFC -Mcdonalds -Starbucks şirketlerinden yüksek kalori yoğunluğu olacağından kısa sürede kontrolsüz kilo alımına yol açar.
62
+
63
+ * **🥤 Su İçin:** Asitli içecekler yerine su tüketmek sağlığınız için kritiktir.
64
+ * **🥩 Protein Vurgusu:** Kas sağlığı ve metabolizma için **protein ağırlıklı** beslenmeye özen gösterilmelidir.
65
  """)
66
+
67
+ with col_note_en:
68
  st.markdown("""
69
+ **Based on the data below, avoiding these companies' meals will benefit your health for the following reasons:**
70
+
71
+ 1. **Heart Health:** High trans fat and sodium content cause arteriosclerosis and high blood pressure.
72
+ 2. **Blood Sugar Balance:** Excessive sugar and processed carbs trigger insulin resistance and diabetes risk.
73
+ 3. **Lack of Nutrients:** These products are sources of "empty calories"; they are extremely poor in vitamins and minerals.
74
+ 4. **Obesity Risk:** High calorie density in foods from companies like Pizza Hut, Burger King, KFC, McDonald’s, and Starbucks can lead to rapid, uncontrolled weight gain.
75
+
76
+ * **🥤 Drink Water:** Choosing water instead of sugary drinks is critical for your health.
77
+ * **🥩 Focus on Protein:** Prioritize **protein-rich** nutrition for muscle health and metabolism.
78
  """)
79
 
80
  st.write("---")
81
 
82
+ # --- ÖDEV METNİ (BÜYÜTÜLMÜŞ VE KOYULTULMUŞ) ---
83
+ st.markdown("""
84
+ <div style="text-align: center;">
85
+ <h3 style="color: #1E1E1E; font-weight: bold;">
86
+ 🔍 Bu çalışma, fast food ürünlerinin kalori ve şeker içeriklerini görselleştirerek genel bir sağlık tablosu sunmaktadır.
87
+ </h3>
88
+ <h4 style="color: #555555;">
89
+ This study provides a general health overview by visualizing the calorie and sugar content of fast food products.
90
+ </h4>
91
+ </div>
92
+ """, unsafe_allow_html=True)
93
+
94
+ st.write("---")
95
+
96
+ # --- GRAFİKLER ---
97
+ st.subheader("📊 General Visual Analysis / Genel Görsel Analiz")
98
+
99
+ c1, c2 = st.columns(2)
100
+
101
+ with c1:
102
+ st.write("🍭 **Average Sugar by Company / Şirketlere Göre Ort. Şeker**")
103
+ sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
104
+
105
+ fig, ax = plt.subplots(figsize=(6, 4))
106
+ sugar_means.plot(kind="bar", color="crimson", ax=ax)
107
+ plt.xticks(rotation=45, fontsize=8)
108
+
109
+ st.pyplot(fig)
110
+ plt.close(fig) # 🔥 TITREME FIX
111
+
112
+ with c2:
113
+ st.write("🔥 **Overall Calorie Distribution / Genel Kalori Dağılımı**")
114
+
115
+ fig2, ax2 = plt.subplots(figsize=(6, 4))
116
+ sns.histplot(df["Energy (kCal)"], bins=20, kde=True, ax=ax2, color="darkorange")
117
+
118
+ st.pyplot(fig2)
119
+ plt.close(fig2) # 🔥 TITREME FIX
120
+
121
+ # --- VERİ TABLOSU ---
122
+ st.subheader("📋 High-Calorie Products List / Yüksek Kalorili Ürün Listesi")
123
+
124
+ top_20 = df.sort_values(by="Energy (kCal)", ascending=False).head(20)
125
+
126
+ st.dataframe(
127
+ top_20[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)", "Total Fat (g)"]],
128
+ use_container_width=True
129
+ )
130
 
131
+ # --- DOWNLOAD ---
132
  st.write("---")
133
 
134
+ st.download_button(
135
+ "📥 Download Full Dataset / Tüm Veriyi İndir",
136
+ df.to_csv(index=False),
137
+ "fastfood_nutrition_final.csv",
138
+ "text/csv"
139
+ )