ESMATUGBA commited on
Commit
8d2ff50
·
verified ·
1 Parent(s): c2ff5aa

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +119 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,121 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
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,000kcal
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 -Mcdonalds -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
+ # HTML kullanarak yazıyı daha okunur hale getiriyoruz
77
+ st.markdown("""
78
+ <div style="text-align: center;">
79
+ <h3 style="color: #1E1E1E; font-weight: bold;">
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
+ <h4 style="color: #555555;">
83
+ This study provides a general health overview by visualizing the calorie and sugar content of fast food products.
84
+ </h4>
85
+ </div>
86
+ """, unsafe_allow_html=True)
87
+
88
+ st.write("---")
89
+
90
+ # --- GRAFİKLER ---
91
+ st.subheader("📊 General Visual Analysis / Genel Görsel Analiz")
92
+
93
+ c1, c2 = st.columns(2)
94
+
95
+ with c1:
96
+ st.write("🍭 **Average Sugar by Company / Şirketlere Göre Ort. Şeker**")
97
+ sugar_means = df.groupby("Company")["Sugar (g)"].mean().sort_values()
98
+ fig, ax = plt.subplots(figsize=(6, 4))
99
+ sugar_means.plot(kind="bar", color="crimson", ax=ax)
100
+ plt.xticks(rotation=45, fontsize=8)
101
+ st.pyplot(fig)
102
+
103
+ with c2:
104
+ st.write("🔥 **Overall Calorie Distribution / Genel Kalori Dağılımı**")
105
+ fig2, ax2 = plt.subplots(figsize=(6, 4))
106
+ sns.histplot(df["Energy (kCal)"], bins=20, kde=True, ax=ax2, color="darkorange")
107
+ st.pyplot(fig2)
108
+
109
+ # --- VERİ TABLOSU ---
110
+ st.subheader("📋 High-Calorie Products List / Yüksek Kalorili Ürün Listesi")
111
+ top_20 = df.sort_values(by="Energy (kCal)", ascending=False).head(20)
112
+ st.dataframe(top_20[["Company", "Product", "Energy (kCal)", "Sugar (g)", "Protein (g)", "Total Fat (g)"]], use_container_width=True)
113
 
114
+ # --- DOWNLOAD ---
115
+ st.write("---")
116
+ st.download_button(
117
+ "📥 Download Full Dataset / Tüm Veriyi İndir",
118
+ df.to_csv(index=False),
119
+ "fastfood_nutrition_final.csv",
120
+ "text/csv"
121
+ )