Update src/streamlit_app.py
Browse files- src/streamlit_app.py +78 -57
src/streamlit_app.py
CHANGED
|
@@ -4,36 +4,25 @@ 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ı")
|
|
@@ -43,85 +32,117 @@ st.sidebar.write("""
|
|
| 43 |
""")
|
| 44 |
|
| 45 |
st.sidebar.warning("""
|
| 46 |
-
⚠️ Health Advice:
|
| 47 |
-
Fast food meals are high in sodium.
|
|
|
|
| 48 |
""")
|
| 49 |
|
| 50 |
st.sidebar.info("""
|
| 51 |
-
💡
|
|
|
|
|
|
|
| 52 |
""")
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
# =========================
|
| 57 |
-
st.title("🍔 Global Fast Food Nutrition Analysis")
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
#
|
| 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("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
with col_note_en:
|
| 70 |
-
st.markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
st.write("---")
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
|
| 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.
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
|
| 104 |
|
| 105 |
-
#
|
| 106 |
-
|
| 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 |
-
|
| 115 |
)
|
| 116 |
|
| 117 |
-
#
|
| 118 |
-
# DOWNLOAD
|
| 119 |
-
# =========================
|
| 120 |
st.write("---")
|
| 121 |
|
| 122 |
st.download_button(
|
| 123 |
-
"📥 Download Dataset",
|
| 124 |
df.to_csv(index=False),
|
| 125 |
-
"
|
| 126 |
"text/csv"
|
| 127 |
)
|
|
|
|
| 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İ - TİTREMEYİ KESER)
|
|
|
|
|
|
|
| 11 |
@st.cache_data
|
| 12 |
+
def load_data(path):
|
|
|
|
| 13 |
df = pd.read_csv(path)
|
| 14 |
+
df = df.replace([np.inf, -np.inf], np.nan).dropna()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
return df
|
| 16 |
|
| 17 |
+
path = "Nutrition_Value_Dataset.csv"
|
| 18 |
+
|
| 19 |
try:
|
| 20 |
+
df = load_data(path)
|
| 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ı")
|
|
|
|
| 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İ ---
|
| 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 |
+
# SOL GRAFİK
|
| 102 |
with c1:
|
| 103 |
+
st.write("🍭 **Average Sugar by Company / Şirketlere Göre Ort. Şeker**")
|
| 104 |
+
|
| 105 |
sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
|
| 106 |
|
| 107 |
fig, ax = plt.subplots(figsize=(6, 4))
|
| 108 |
sugar_means.plot(kind="bar", color="crimson", ax=ax)
|
| 109 |
|
| 110 |
+
ax.set_xticklabels(ax.get_xticklabels(), rotation=45, fontsize=8)
|
| 111 |
|
| 112 |
+
st.pyplot(fig, clear_figure=True)
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
# SAĞ GRAFİK (TİTREME BURADA ÇÖZÜLDÜ)
|
| 115 |
with c2:
|
| 116 |
+
st.write("🔥 **Overall Calorie Distribution / Genel Kalori Dağılımı**")
|
| 117 |
+
|
| 118 |
fig2, ax2 = plt.subplots(figsize=(6, 4))
|
|
|
|
| 119 |
|
| 120 |
+
sns.histplot(
|
| 121 |
+
df["Energy (kCal)"],
|
| 122 |
+
bins=20,
|
| 123 |
+
kde=True,
|
| 124 |
+
ax=ax2,
|
| 125 |
+
color="darkorange"
|
| 126 |
+
)
|
| 127 |
|
| 128 |
+
st.pyplot(fig2, clear_figure=True)
|
| 129 |
|
| 130 |
+
# --- VERİ TABLOSU ---
|
| 131 |
+
st.subheader("📋 High-Calorie Products List / Yüksek Kalorili Ürün Listesi")
|
|
|
|
|
|
|
| 132 |
|
| 133 |
top_20 = df.sort_values(by="Energy (kCal)", ascending=False).head(20)
|
| 134 |
|
| 135 |
st.dataframe(
|
| 136 |
top_20[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)", "Total Fat (g)"]],
|
| 137 |
+
use_container_width=True
|
| 138 |
)
|
| 139 |
|
| 140 |
+
# --- DOWNLOAD ---
|
|
|
|
|
|
|
| 141 |
st.write("---")
|
| 142 |
|
| 143 |
st.download_button(
|
| 144 |
+
"📥 Download Full Dataset / Tüm Veriyi İndir",
|
| 145 |
df.to_csv(index=False),
|
| 146 |
+
"fastfood_nutrition_final.csv",
|
| 147 |
"text/csv"
|
| 148 |
)
|