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