Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +100 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,102 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 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 plotly.graph_objects as go
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Sayfa Genişliği ve Ayarlar
|
| 7 |
+
st.set_page_config(page_title="World Data Analysis", layout="wide")
|
| 8 |
+
|
| 9 |
+
# --- SIDEBAR (SOL TARAF) ---
|
| 10 |
+
st.sidebar.header("📊 Analysis Notes / Analiz Notları")
|
| 11 |
+
|
| 12 |
+
# İngilizce Notlar (Üstte)
|
| 13 |
+
st.sidebar.markdown("""
|
| 14 |
+
**EN:** Analysis shows that developed countries have high GDP and internet usage.
|
| 15 |
+
It has also been observed that CO2 emissions are high in these countries.
|
| 16 |
+
In low-income countries, energy and internet usage are found to be lower.
|
| 17 |
+
In some cases, an inverse relationship between forest rate and CO2 emissions has been seen.
|
| 18 |
+
|
| 19 |
+
**Examples:**
|
| 20 |
+
* **High GDP & CO2:** USA, China, Germany.
|
| 21 |
+
* **Low Income & Energy:** Afghanistan, Yemen, Zambia.
|
| 22 |
+
""")
|
| 23 |
+
|
| 24 |
+
st.sidebar.markdown("---") # Ayırıcı çizgi
|
| 25 |
+
|
| 26 |
+
# Türkçe Notlar (Altta)
|
| 27 |
+
st.sidebar.markdown("""
|
| 28 |
+
**TR:** Analiz sonucunda gelişmiş ülkelerde GDP ve internet kullanımının yüksek olduğu görülmüştür.
|
| 29 |
+
Aynı zamanda bu ülkelerde CO2 emisyonunun da yüksek olduğu tespit edilmiştir.
|
| 30 |
+
Düşük gelirli ülkelerde ise enerji ve internet kullanımının daha düşük olduğu gözlemlenmiştir.
|
| 31 |
+
Orman oranı ile CO2 emisyonu arasında bazı durumlarda ters ilişki olduğu görülmüştür.
|
| 32 |
+
|
| 33 |
+
**Örnekler:**
|
| 34 |
+
* **Yüksek GDP & CO2:** ABD (USA), Çin (China), Almanya.
|
| 35 |
+
* **Düşük Gelir & Enerji:** Afganistan, Yemen, Zambiya.
|
| 36 |
+
""")
|
| 37 |
+
|
| 38 |
+
# --- DATA LOAD ---
|
| 39 |
+
try:
|
| 40 |
+
df = pd.read_csv("us_pollution_cleaned.csv") # Dosya adını kontrol et!
|
| 41 |
+
except:
|
| 42 |
+
st.error("Dosya bulunamadı! / File not found!")
|
| 43 |
+
st.stop()
|
| 44 |
+
|
| 45 |
+
# GDP_LEVEL Sütununu Oluşturma (Emin olmak için)
|
| 46 |
+
if 'GDP' in df.columns and 'GDP_LEVEL' not in df.columns:
|
| 47 |
+
df['GDP_LEVEL'] = pd.cut(df['GDP'], bins=[0, 2000, 10000, 100000], labels=['Low', 'Medium', 'High'])
|
| 48 |
+
|
| 49 |
+
# --- ANA SAYFA BAŞLIK ---
|
| 50 |
+
st.title("🌍 World Data Analysis Dashboard / Dünya Veri Analizi Paneli")
|
| 51 |
+
st.write("Veri Analizi ve Görselleştirme / Data Analysis and Visualization")
|
| 52 |
+
st.divider()
|
| 53 |
+
|
| 54 |
+
# ==========================================
|
| 55 |
+
# --- 1. HARİTA (EN ÜSTTE VE GENİŞ) ---
|
| 56 |
+
# ==========================================
|
| 57 |
+
st.subheader("🗺️ World GDP Map / Dünya GSYİH Haritası")
|
| 58 |
+
fig_map = go.Figure(data=dict(
|
| 59 |
+
type="choropleth",
|
| 60 |
+
colorscale='Viridis',
|
| 61 |
+
locations=df["COUNTRY"],
|
| 62 |
+
locationmode="country names",
|
| 63 |
+
z=df["GDP"],
|
| 64 |
+
colorbar={'title': "GDP"}
|
| 65 |
+
))
|
| 66 |
+
# Haritayı biraz daha basık yapıyoruz (yüksekliği 350)
|
| 67 |
+
fig_map.update_layout(height=350, margin={"r":0,"t":0,"l":0,"b":0})
|
| 68 |
+
st.plotly_chart(fig_map, use_container_width=True)
|
| 69 |
+
|
| 70 |
+
st.divider()
|
| 71 |
+
|
| 72 |
+
# ==========================================
|
| 73 |
+
# --- 2. KÜÇÜK GRAFİKLER (ALTTAN VE YAN YANA) ---
|
| 74 |
+
# ==========================================
|
| 75 |
+
col1, col2 = st.columns(2)
|
| 76 |
+
|
| 77 |
+
with col1:
|
| 78 |
+
st.subheader("📊 GDP vs CO2")
|
| 79 |
+
# figsize=(4, 3) ile çok daha küçük bir ebat
|
| 80 |
+
fig1, ax1 = plt.subplots(figsize=(4, 3))
|
| 81 |
+
ax1.scatter(df['GDP'], df['CO2'], color='royalblue', alpha=0.6, s=15) # s=15 noktaları küçültür
|
| 82 |
+
ax1.set_xlabel("GDP", fontsize=10)
|
| 83 |
+
ax1.set_ylabel("CO2", fontsize=10)
|
| 84 |
+
# Eksen yazılarını küçültme
|
| 85 |
+
ax1.tick_params(axis='both', which='major', labelsize=8)
|
| 86 |
+
st.pyplot(fig1)
|
| 87 |
+
|
| 88 |
+
with col2:
|
| 89 |
+
st.subheader("Pie Chart / Gelir Seviyesi Dağılımı")
|
| 90 |
+
# figsize=(4, 3) ile çok daha küçük bir ebat
|
| 91 |
+
fig2, ax2 = plt.subplots(figsize=(4, 3))
|
| 92 |
+
df['GDP_LEVEL'].value_counts().plot.pie(
|
| 93 |
+
autopct='%1.1f%%',
|
| 94 |
+
ax=ax2,
|
| 95 |
+
colors=['#ff9999','#66b3ff','#99ff99'],
|
| 96 |
+
textprops={'fontsize': 8} # Yüzde yazılarını küçültür
|
| 97 |
+
)
|
| 98 |
+
ax2.set_ylabel("") # Yan taraftaki etiketi siler
|
| 99 |
+
st.pyplot(fig2)
|
| 100 |
|
| 101 |
+
st.divider()
|
| 102 |
+
st.write("✅ Proje tamamlandı / Project completed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|