Update app.py
Browse files
app.py
CHANGED
|
@@ -1,121 +1,122 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import numpy as np
|
| 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
|
| 11 |
-
path = "Nutrition_Value_Dataset.csv"
|
| 12 |
-
try:
|
| 13 |
-
df = pd.read_csv(path).replace([np.inf, -np.inf], np.nan).dropna()
|
| 14 |
-
except:
|
| 15 |
-
st.error("CSV file not found! / Veri seti dosyası bulunamadı!")
|
| 16 |
-
st.stop()
|
| 17 |
-
|
| 18 |
-
# --- SIDEBAR (SAĞLIK REHBERİ) ---
|
| 19 |
-
st.sidebar.title("🏥 Health & Calorie Guide / Sağlık ve Kalori Rehberi")
|
| 20 |
-
|
| 21 |
-
st.sidebar.subheader("⚖️ Daily Calorie Needs / Günlük Kalori İhtiyacı")
|
| 22 |
-
st.sidebar.write("""
|
| 23 |
-
- **Women / Kadınlar:** 2,
|
| 24 |
-
- **Men / Erkekler:** 2,500 kcal
|
| 25 |
-
""")
|
| 26 |
-
|
| 27 |
-
st.sidebar.warning("""
|
| 28 |
-
⚠️ **Health Advice / Sağlık Öğüdü:**
|
| 29 |
-
Fast food meals are high in sodium and low in nutrients.
|
| 30 |
-
*Fast food öğünleri sodyum bakımından yüksek, besin değeri bakımından düşüktür.*
|
| 31 |
-
""")
|
| 32 |
-
|
| 33 |
-
st.sidebar.info("""
|
| 34 |
-
💡 **Quick Tip / Pratik Bilgi:**
|
| 35 |
-
Choosing water over soda can reduce your meal's sugar content by 40-60g.
|
| 36 |
-
*Asitli içecek yerine su seçmek, öğününüzdeki şeker miktarını 40-60 gr azaltabilir.*
|
| 37 |
-
""")
|
| 38 |
-
|
| 39 |
-
# --- ANA SAYFA BAŞLIK ---
|
| 40 |
-
st.title("🍔 Global Fast Food Nutrition Analysis / Küresel Fast Food Besin Analizi")
|
| 41 |
-
|
| 42 |
-
# --- TÜKETİCİYE KRİTİK NOT ---
|
| 43 |
-
st.error("### 📢 Important Notice for Consumers / Tüketiciler İçin Önemli Not")
|
| 44 |
-
|
| 45 |
-
col_note_tr, col_note_en = st.columns(2)
|
| 46 |
-
|
| 47 |
-
with col_note_tr:
|
| 48 |
-
st.markdown("""
|
| 49 |
-
**Aşağıdaki verilere istinaden, bu şirketlerden yemek tüketilmemesi sağlığınız için şu nedenlerle yararlı olacaktır:**
|
| 50 |
-
|
| 51 |
-
1. **Kalp Sağlığı:** Yüksek trans yağ ve sodyum içeriği damar sertliği ve tansiyona neden olur.
|
| 52 |
-
2. **Kan Şekeri Dengesi:** Aşırı şeker ve işlenmiş karbonhidratlar ani insülin direnci ve diyabet riskini tetikler.
|
| 53 |
-
3. **Besin Değeri Eksikliği:** Bu ürünler "boş kalori" kaynağıdır; vitamin, mineral ve lif açısından son derece fakirdir.
|
| 54 |
-
4. **Obezite Riski:** Pizza Hut
|
| 55 |
-
|
| 56 |
-
* **🥤 Su İçin:** Asitli içecekler yerine su tüketmek sağlığınız için kritiktir.
|
| 57 |
-
* **🥩 Protein Vurgusu:** Kas sağlığı ve metabolizma için **protein ağırlıklı** beslenmeye özen gösterilmelidir.
|
| 58 |
-
""")
|
| 59 |
-
|
| 60 |
-
with col_note_en:
|
| 61 |
-
st.markdown("""
|
| 62 |
-
**Based on the data below, avoiding these companies' meals will benefit your health for the following reasons:**
|
| 63 |
-
|
| 64 |
-
1. **Heart Health:** High trans fat and sodium content cause arteriosclerosis and high blood pressure.
|
| 65 |
-
2. **Blood Sugar Balance:** Excessive sugar and processed carbs trigger insulin resistance and diabetes risk.
|
| 66 |
-
3. **Lack of Nutrients:** These products are sources of "empty calories"; they are extremely poor in vitamins and minerals.
|
| 67 |
-
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.
|
| 68 |
-
|
| 69 |
-
* **🥤 Drink Water:** Choosing water instead of sugary drinks is critical for your health.
|
| 70 |
-
* **🥩 Focus on Protein:** Prioritize **protein-rich** nutrition for muscle health and metabolism.
|
| 71 |
-
""")
|
| 72 |
-
|
| 73 |
-
st.write("---")
|
| 74 |
-
|
| 75 |
-
# --- ÖDEV METNİ (BÜYÜTÜLMÜŞ VE KOYULTULMUŞ) ---
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
<
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
<
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
st.
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
"
|
|
|
|
| 121 |
)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 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
|
| 11 |
+
path = "Nutrition_Value_Dataset.csv"
|
| 12 |
+
try:
|
| 13 |
+
df = pd.read_csv(path).replace([np.inf, -np.inf], np.nan).dropna()
|
| 14 |
+
except:
|
| 15 |
+
st.error("CSV file not found! / Veri seti dosyası bulunamadı!")
|
| 16 |
+
st.stop()
|
| 17 |
+
|
| 18 |
+
# --- SIDEBAR (SAĞLIK REHBERİ) ---
|
| 19 |
+
st.sidebar.title("🏥 Health & Calorie Guide / Sağlık ve Kalori Rehberi")
|
| 20 |
+
|
| 21 |
+
st.sidebar.subheader("⚖️ Daily Calorie Needs / Günlük Kalori İhtiyacı")
|
| 22 |
+
st.sidebar.write("""
|
| 23 |
+
- **Women / Kadınlar:** 2,000 kcal
|
| 24 |
+
- **Men / Erkekler:** 2,500 kcal
|
| 25 |
+
""")
|
| 26 |
+
|
| 27 |
+
st.sidebar.warning("""
|
| 28 |
+
⚠️ **Health Advice / Sağlık Öğüdü:**
|
| 29 |
+
Fast food meals are high in sodium and low in nutrients.
|
| 30 |
+
*Fast food öğünleri sodyum bakımından yüksek, besin değeri bakımından düşüktür.*
|
| 31 |
+
""")
|
| 32 |
+
|
| 33 |
+
st.sidebar.info("""
|
| 34 |
+
💡 **Quick Tip / Pratik Bilgi:**
|
| 35 |
+
Choosing water over soda can reduce your meal's sugar content by 40-60g.
|
| 36 |
+
*Asitli içecek yerine su seçmek, öğününüzdeki şeker miktarını 40-60 gr azaltabilir.*
|
| 37 |
+
""")
|
| 38 |
+
|
| 39 |
+
# --- ANA SAYFA BAŞLIK ---
|
| 40 |
+
st.title("🍔 Global Fast Food Nutrition Analysis / Küresel Fast Food Besin Analizi")
|
| 41 |
+
|
| 42 |
+
# --- TÜKETİCİYE KRİTİK NOT ---
|
| 43 |
+
st.error("### 📢 Important Notice for Consumers / Tüketiciler İçin Önemli Not")
|
| 44 |
+
|
| 45 |
+
col_note_tr, col_note_en = st.columns(2)
|
| 46 |
+
|
| 47 |
+
with col_note_tr:
|
| 48 |
+
st.markdown("""
|
| 49 |
+
**Aşağıdaki verilere istinaden, bu şirketlerden yemek tüketilmemesi sağlığınız için şu nedenlerle yararlı olacaktır:**
|
| 50 |
+
|
| 51 |
+
1. **Kalp Sağlığı:** Yüksek trans yağ ve sodyum içeriği damar sertliği ve tansiyona neden olur.
|
| 52 |
+
2. **Kan Şekeri Dengesi:** Aşırı şeker ve işlenmiş karbonhidratlar ani insülin direnci ve diyabet riskini tetikler.
|
| 53 |
+
3. **Besin Değeri Eksikliği:** Bu ürünler "boş kalori" kaynağıdır; vitamin, mineral ve lif açısından son derece fakirdir.
|
| 54 |
+
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.
|
| 55 |
+
|
| 56 |
+
* **🥤 Su İçin:** Asitli içecekler yerine su tüketmek sağlığınız için kritiktir.
|
| 57 |
+
* **🥩 Protein Vurgusu:** Kas sağlığı ve metabolizma için **protein ağırlıklı** beslenmeye özen gösterilmelidir.
|
| 58 |
+
""")
|
| 59 |
+
|
| 60 |
+
with col_note_en:
|
| 61 |
+
st.markdown("""
|
| 62 |
+
**Based on the data below, avoiding these companies' meals will benefit your health for the following reasons:**
|
| 63 |
+
|
| 64 |
+
1. **Heart Health:** High trans fat and sodium content cause arteriosclerosis and high blood pressure.
|
| 65 |
+
2. **Blood Sugar Balance:** Excessive sugar and processed carbs trigger insulin resistance and diabetes risk.
|
| 66 |
+
3. **Lack of Nutrients:** These products are sources of "empty calories"; they are extremely poor in vitamins and minerals.
|
| 67 |
+
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.
|
| 68 |
+
|
| 69 |
+
* **🥤 Drink Water:** Choosing water instead of sugary drinks is critical for your health.
|
| 70 |
+
* **🥩 Focus on Protein:** Prioritize **protein-rich** nutrition for muscle health and metabolism.
|
| 71 |
+
""")
|
| 72 |
+
|
| 73 |
+
st.write("---")
|
| 74 |
+
|
| 75 |
+
# --- ÖDEV METNİ (BÜYÜTÜLMÜŞ VE KOYULTULMUŞ) ---
|
| 76 |
+
st.markdown("""
|
| 77 |
+
<div style="text-align: center;">
|
| 78 |
+
<h3 style="color: #1E1E1E; font-weight: bold;">
|
| 79 |
+
🔍 Bu çalışma, fast food ürünlerinin kalori ve şeker içeriklerini görselleştirerek genel bir sağlık tablosu sunmaktadır.
|
| 80 |
+
</h3>
|
| 81 |
+
<h4 style="color: #555555;">
|
| 82 |
+
This study provides a general health overview by visualizing the calorie and sugar content of fast food products.
|
| 83 |
+
</h4>
|
| 84 |
+
</div>
|
| 85 |
+
""", unsafe_allow_html=True)
|
| 86 |
+
|
| 87 |
+
st.write("---")
|
| 88 |
+
|
| 89 |
+
# --- GRAFİKLER ---
|
| 90 |
+
st.subheader("📊 General Visual Analysis / Genel Görsel Analiz")
|
| 91 |
+
|
| 92 |
+
c1, c2 = st.columns(2)
|
| 93 |
+
|
| 94 |
+
with c1:
|
| 95 |
+
st.write("🍭 **Average Sugar by Company / Şirketlere Göre Ort. Şeker**")
|
| 96 |
+
sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
|
| 97 |
+
fig, ax = plt.subplots(figsize=(6, 4))
|
| 98 |
+
sugar_means.plot(kind="bar", color="crimson", ax=ax)
|
| 99 |
+
plt.xticks(rotation=45, fontsize=8)
|
| 100 |
+
st.pyplot(fig)
|
| 101 |
+
|
| 102 |
+
with c2:
|
| 103 |
+
st.write("🔥 **Overall Calorie Distribution / Genel Kalori Dağılımı**")
|
| 104 |
+
fig2, ax2 = plt.subplots(figsize=(6, 4))
|
| 105 |
+
sns.histplot(df["Energy (kCal)"], bins=20, kde=True, ax=ax2, color="darkorange")
|
| 106 |
+
st.pyplot(fig2)
|
| 107 |
+
|
| 108 |
+
# --- VERİ TABLOSU (TITREME COZUMU UYGULANDI) ---
|
| 109 |
+
st.subheader("📋 High-Calorie Products List / Yüksek Kalorili Ürün Listesi")
|
| 110 |
+
top_20 = df.sort_values(by="Energy (kCal)", ascending=False).head(20)
|
| 111 |
+
|
| 112 |
+
# use_container_width yerine width='stretch' kullanılarak titreme sorunu giderildi
|
| 113 |
+
st.dataframe(top_20[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)", "Total Fat (g)"]], width='stretch')
|
| 114 |
+
|
| 115 |
+
# --- DOWNLOAD ---
|
| 116 |
+
st.write("---")
|
| 117 |
+
st.download_button(
|
| 118 |
+
"📥 Download Full Dataset / Tüm Veriyi İndir",
|
| 119 |
+
df.to_csv(index=False),
|
| 120 |
+
"fastfood_nutrition_final.csv",
|
| 121 |
+
"text/csv"
|
| 122 |
)
|