ESMATUGBA commited on
Commit
700edf6
·
verified ·
1 Parent(s): a014156

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +61 -71
src/streamlit_app.py CHANGED
@@ -5,17 +5,17 @@ import matplotlib.pyplot as plt
5
  import seaborn as sns
6
  import os
7
 
8
- # 1. DOSYA İZLEYİCİSİNİ SUSTUR (Hugging Face titremesini önlemek için en üstte)
9
  os.environ["STREAMLIT_SERVER_FILE_WATCHER_TYPE"] = "none"
10
 
11
- # 2. LAYOUT'U SABİTLE (Genişlik ölçüm titremesini bitirmek için 'centered')
12
  st.set_page_config(
13
  page_title="Fast Food Nutrition Guide",
14
  layout="centered",
15
  initial_sidebar_state="expanded"
16
  )
17
 
18
- # 3. VERİYİ HAFIZAYA ÇAK (Sürekli okuma yapıp ekranı yenilemesin)
19
  @st.cache_data(show_spinner=False)
20
  def load_data_final():
21
  path = "Nutrition_Value_Dataset.csv"
@@ -31,96 +31,86 @@ if df is None:
31
  st.error("CSV file not found! / Veri seti dosyası bulunamadı!")
32
  st.stop()
33
 
34
- # --- SIDEBAR (SOL PANEL - TÜM İÇERİK GERİ GELDİ) ---
35
  st.sidebar.title("🏥 Health & Calorie Guide / Sağlık ve Kalori Rehberi")
36
-
37
  st.sidebar.subheader("⚖️ Daily Calorie Needs / Günlük Kalori İhtiyacı")
38
- st.sidebar.write("""
39
- - **Women / Kadınlar:** 2,000kcal
40
- - **Men / Erkekler:** 2,500 kcal
41
- """)
42
-
43
- st.sidebar.warning("""
44
- ⚠️ **Health Advice / Sağlık Öğüdü:**
45
- Fast food meals are high in sodium and low in nutrients.
46
- *Fast food öğünleri sodyum bakımından yüksek, besin değeri bakımından düşüktür.*
47
- """)
48
-
49
- st.sidebar.info("""
50
- 💡 **Quick Tip / Pratik Bilgi:**
51
- Choosing water over soda can reduce your meal's sugar content by 40-60g.
52
- *Asitli içecek yerine su seçmek, öğününüzdeki şeker miktarını 40-60 gr azaltabilir.*
53
- """)
54
 
55
  # --- ANA SAYFA BAŞLIK ---
56
- st.title("🍔 Global Fast Food Nutrition Analysis")
57
 
58
- # --- TÜKETİCİYE KRİTİK NOT ---
59
  st.error("### 📢 Important Notice for Consumers / Tüketiciler İçin Önemli Not")
60
 
61
- # Titremeyi önlemek için bu kutuları yan yana (columns) yerine alt alta veya güvenli markdown ile veriyoruz
62
- st.markdown("""
63
- **Aşağıdaki verilere istinaden, bu şirketlerden yemek tüketilmemesi sağlığınız için şu nedenlerle yararlı olacaktır:**
64
-
65
- 1. **Kalp Sağlığı:** Yüksek trans yağ ve sodyum içeriği damar sertliği ve tansiyona neden olur.
66
- 2. **Kan Şekeri Dengesi:** Aşırı şeker ve işlenmiş karbonhidratlar ani insülin direnci ve diyabet riskini tetikler.
67
- 3. **Besin Değeri Eksikliği:** Bu ürünler "boş kalori" kaynağıdır; vitamin, mineral ve lif açısından son derece fakirdir.
68
- 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.
69
-
70
- * **🥤 Su İçin:** Asitli içecekler yerine su tüketmek sağlığınız için kritiktir.
71
- * **🥩 Protein Vurgusu:** Kas sağlığı ve metabolizma için **protein ağırlıklı** beslenmeye özen gösterilmelidir.
72
- """)
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  st.write("---")
75
 
76
- # --- ÖDEV METNİ (BÜYÜTÜLMÜŞ VE KOYULTULMUŞ) ---
77
  st.markdown("""
78
- <div style="text-align: center; border: 1px solid #ddd; padding: 10px; border-radius: 5px;">
79
  <h3 style="color: #1E1E1E; font-weight: bold; margin: 0;">
80
  🔍 Bu çalışma, fast food ürünlerinin kalori ve şeker içeriklerini görselleştirerek genel bir sağlık tablosu sunmaktadır.
81
  </h3>
82
- <p style="color: #555555; margin: 5px 0 0 0;">
83
  This study provides a general health overview by visualizing the calorie and sugar content of fast food products.
84
- </p>
85
  </div>
86
  """, unsafe_allow_html=True)
87
 
88
  st.write("---")
89
 
90
- # --- GRAFİKLER (ALT ALTA - GENİŞLİK TİTREMESİNİ ÖNLER) ---
91
- st.subheader("📊 General Visual Analysis / Genel Görsel Analiz")
92
-
93
- # Grafik 1
94
- st.write("🍭 **Average Sugar by Company / Şirketlere Göre Ort. Şeker**")
95
- sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
96
- fig1, ax1 = plt.subplots(figsize=(10, 5))
97
- sugar_means.plot(kind="bar", color="crimson", ax=ax1)
98
- plt.xticks(rotation=45)
99
- plt.tight_layout()
100
- st.pyplot(fig1)
101
-
102
- st.write("---")
103
-
104
- # Grafik 2
105
- st.write("🔥 **Overall Calorie Distribution / Genel Kalori Dağılımı**")
106
- fig2, ax2 = plt.subplots(figsize=(10, 5))
107
- sns.histplot(df["Energy (kCal)"], bins=20, kde=True, ax=ax2, color="darkorange")
108
- plt.tight_layout()
109
- st.pyplot(fig2)
110
-
111
- # --- VERİ TABLOSU (STATİK TABLO - TİTREMEYİ %100 BİTİRİR) ---
112
  st.write("---")
113
  st.subheader("📋 High-Calorie Products List / Yüksek Kalorili Ürün Listesi")
114
- top_10 = df.sort_values(by="Energy (kCal)", ascending=False).head(10)
115
-
116
- # Dinamik dataframe yerine sabit table kullanarak loglardaki genişlik hatasını bitirdik
117
- st.table(top_10[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)"]])
118
 
119
  # --- DOWNLOAD ---
120
  st.write("---")
121
- st.download_button(
122
- "📥 Download Full Dataset / Tüm Veriyi İndir",
123
- df.to_csv(index=False),
124
- "fastfood_nutrition_final.csv",
125
- "text/csv"
126
- )
 
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 (Sabit modda devam ediyoruz)
12
  st.set_page_config(
13
  page_title="Fast Food Nutrition Guide",
14
  layout="centered",
15
  initial_sidebar_state="expanded"
16
  )
17
 
18
+ # 3. VERİ KİLİDİ
19
  @st.cache_data(show_spinner=False)
20
  def load_data_final():
21
  path = "Nutrition_Value_Dataset.csv"
 
31
  st.error("CSV file not found! / Veri seti dosyası bulunamadı!")
32
  st.stop()
33
 
34
+ # --- SIDEBAR (SOL PANEL) ---
35
  st.sidebar.title("🏥 Health & Calorie Guide / Sağlık ve Kalori Rehberi")
 
36
  st.sidebar.subheader("⚖️ Daily Calorie Needs / Günlük Kalori İhtiyacı")
37
+ st.sidebar.write("- **Women / Kadınlar:** 2,000kcal\n- **Men / Erkekler:** 2,500 kcal")
38
+ st.sidebar.warning("⚠️ **Health Advice:** Fast food is high in sodium.\n*Fast food sodyum bakımından yüksektir.*")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # --- ANA SAYFA BAŞLIK ---
41
+ st.title("🍔 Global Fast Food Nutrition Analysis / Küresel Fast Food Besin Analizi")
42
 
43
+ # --- TÜKETİCİYE KRİTİK NOT (YAN YANA) ---
44
  st.error("### 📢 Important Notice for Consumers / Tüketiciler İçin Önemli Not")
45
 
46
+ # Yazıları yan yana getiren sütunlar
47
+ col_tr, col_en = st.columns(2)
48
+
49
+ with col_tr:
50
+ st.markdown("""
51
+ **Aşağıdaki nedenlerle yemek tüketilmemelidir:**
52
+ 1. **Kalp Sağlığı:** Damar sertliği ve tansiyon riski.
53
+ 2. **Kan Şekeri:** Diyabet riskini tetikler.
54
+ 3. **Besin Değeri:** Vitamin ve mineralden fakir "boş kalori".
55
+ 4. **Obezite Riski:** **Pizza Hut, Burger King, KFC, McDonald’s ve Starbucks** ürünleri kontrolsüz kilo aldırır.
56
+
57
+ * **🥤 Su İçin:** Asitli içeceklerden kaçının.
58
+ """)
59
+
60
+ with col_en:
61
+ st.markdown("""
62
+ **Avoid these meals for the following reasons:**
63
+ 1. **Heart Health:** Risk of arteriosclerosis and high BP.
64
+ 2. **Blood Sugar:** Triggers diabetes risk.
65
+ 3. **Nutrients:** Empty calories, lack of minerals.
66
+ 4. **Obesity Risk:** Products from **Major Chains** lead to rapid weight gain.
67
+
68
+ * **🥤 Drink Water:** Avoid sugary drinks.
69
+ """)
70
 
71
  st.write("---")
72
 
73
+ # --- ÖDEV METNİ (SABİT) ---
74
  st.markdown("""
75
+ <div style="text-align: center; border: 1px solid #ddd; padding: 15px; border-radius: 10px; background-color: #f9f9f9;">
76
  <h3 style="color: #1E1E1E; font-weight: bold; margin: 0;">
77
  🔍 Bu çalışma, fast food ürünlerinin kalori ve şeker içeriklerini görselleştirerek genel bir sağlık tablosu sunmaktadır.
78
  </h3>
79
+ <h4 style="color: #555555; margin: 10px 0 0 0;">
80
  This study provides a general health overview by visualizing the calorie and sugar content of fast food products.
81
+ </h4>
82
  </div>
83
  """, unsafe_allow_html=True)
84
 
85
  st.write("---")
86
 
87
+ # --- GRAFİKLER (ALT ALTA - DOKUNULMADI) ---
88
+ if df is not None:
89
+ st.subheader("📊 General Visual Analysis / Genel Görsel Analiz")
90
+
91
+ st.write("🍭 **Average Sugar by Company / Şirketlere Göre Ort. Şeker**")
92
+ sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
93
+ fig1, ax1 = plt.subplots(figsize=(10, 5))
94
+ sugar_means.plot(kind="bar", color="crimson", ax=ax1)
95
+ plt.xticks(rotation=45)
96
+ plt.tight_layout()
97
+ st.pyplot(fig1)
98
+
99
+ st.write("---")
100
+
101
+ st.write("🔥 **Overall Calorie Distribution / Genel Kalori Dağılımı**")
102
+ fig2, ax2 = plt.subplots(figsize=(10, 5))
103
+ sns.histplot(df["Energy (kCal)"], bins=20, kde=True, ax=ax2, color="darkorange")
104
+ plt.tight_layout()
105
+ st.pyplot(fig2)
106
+
107
+ # --- VERİ TABLOSU (STATİK - DOKUNULMADI) ---
 
108
  st.write("---")
109
  st.subheader("📋 High-Calorie Products List / Yüksek Kalorili Ürün Listesi")
110
+ if df is not None:
111
+ top_10 = df.sort_values(by="Energy (kCal)", ascending=False).head(10)
112
+ st.table(top_10[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)"]])
 
113
 
114
  # --- DOWNLOAD ---
115
  st.write("---")
116
+ st.download_button("📥 Download Full Dataset / Tüm Veriyi İndir", df.to_csv(index=False), "data.csv", "text/csv")