import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Sayfa Genişlik Ayarı
st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
plt.style.use('dark_background')
# 1. VERİ YÜKLEME
@st.cache_data
def load_data():
df = pd.read_csv("gld_price_data.csv")
df['Date'] = pd.to_datetime(df['Date'])
df['YEAR'] = df['Date'].dt.year
return df
df = load_data()
# 2. SOL PANEL (SIDEBAR) - TIKLAYARAK SEÇME
st.sidebar.markdown("# 📅 Filtreler / Filters")
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
year = st.sidebar.selectbox(
"Yıl Seçin / Select Year",
options=years_list,
index=0
)
filtered_df = df[df['YEAR'] == year]
# 3. ANA BAŞLIK (BÜYÜK BOYUT)
st.markdown("
Gold Price Analysis / Altın Fiyat Analizi
", unsafe_allow_html=True)
st.divider()
# 4. YÖNETİCİ BİLGİ NOTU (İSTEĞİN ÜZERİNE EN ÜSTTE)
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary") # ## ile başlık büyütüldü
info_col1, info_col2 = st.columns(2)
if year == 2008:
with info_col1:
st.warning("### 🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.") # Yazı boyutu büyütüldü
with info_col2:
st.warning("### 🇺🇸 Gold is a safe haven in 2008; buying is beneficial.")
else:
with info_col1:
st.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
with info_col2:
st.success(f"### 🇺🇸 Data for {year} appears stable.")
st.divider()
# 5. ANA GRAFİK: ZAMAN SERİSİ (KÜÇÜLTÜLMÜŞ)
st.markdown(f"## 📈 {year} Analizi / Analysis")
fig1, ax1 = plt.subplots(figsize=(8, 2.5))
ax1.plot(filtered_df['Date'], filtered_df['GLD'], color='gold', linewidth=1.5)
ax1.fill_between(filtered_df['Date'], filtered_df['GLD'], color='gold', alpha=0.1)
# Eksen ayarı
y_min, y_max = filtered_df['GLD'].min(), filtered_df['GLD'].max()
ax1.set_ylim(y_min * 0.98, y_max * 1.02)
st.pyplot(fig1)
# GRAFİK NOTU (DAHA BÜYÜK VE OKUNAKLI)
st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir. / Note: This chart shows daily price movements in {year}.")
st.divider()
# 6. DİĞER GRAFİKLER (YAN YANA)
col_left, col_right = st.columns(2)
with col_left:
st.markdown("### 🎯 Dağılım / Distribution")
fig2, ax2 = plt.subplots(figsize=(5, 3))
sns.kdeplot(x=filtered_df['GLD'], fill=True, color="orange", ax=ax2)
st.pyplot(fig2)
with col_right:
st.markdown("### 🌡️ Korelasyon / Correlation")
fig3, ax3 = plt.subplots(figsize=(5, 3))
sns.heatmap(filtered_df.corr(numeric_only=True), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 7})
st.pyplot(fig3)
# 7. VERİ TABLOSU
with st.expander("Verileri Gör / View Data"):
st.dataframe(filtered_df.head(), use_container_width=True)
csv = filtered_df.to_csv(index=False).encode('utf-8')
st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')