Update src/streamlit_app.py
Browse files- src/streamlit_app.py +64 -48
src/streamlit_app.py
CHANGED
|
@@ -8,14 +8,10 @@ import os
|
|
| 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(
|
| 13 |
-
|
| 14 |
-
|
| 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,11 +27,26 @@ if df is None:
|
|
| 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("
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# --- ANA SAYFA BAŞLIK ---
|
| 41 |
st.title("🍔 Global Fast Food Nutrition Analysis / Küresel Fast Food Besin Analizi")
|
|
@@ -43,34 +54,35 @@ st.title("🍔 Global Fast Food Nutrition Analysis / Küresel Fast Food Besin An
|
|
| 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 |
-
|
| 47 |
-
col_tr, col_en = st.columns(2)
|
| 48 |
|
| 49 |
-
with
|
| 50 |
st.markdown("""
|
| 51 |
-
**Aşağıdaki
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
* **🥤 Su İçin:**
|
| 58 |
""")
|
| 59 |
|
| 60 |
-
with
|
| 61 |
st.markdown("""
|
| 62 |
-
**
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
""")
|
| 70 |
|
| 71 |
st.write("---")
|
| 72 |
|
| 73 |
-
# --- ÖDEV METNİ (
|
| 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;">
|
|
@@ -84,32 +96,36 @@ st.markdown("""
|
|
| 84 |
|
| 85 |
st.write("---")
|
| 86 |
|
| 87 |
-
# --- GRAFİKLER
|
| 88 |
if df is not None:
|
| 89 |
st.subheader("📊 General Visual Analysis / Genel Görsel Analiz")
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 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 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
# --- DOWNLOAD ---
|
| 115 |
st.write("---")
|
|
|
|
| 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"
|
|
|
|
| 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ı")
|
| 34 |
+
st.sidebar.write("""
|
| 35 |
+
- **Women / Kadınlar:** 2,000kcal
|
| 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")
|
|
|
|
| 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;">
|
|
|
|
| 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("---")
|