import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# 1. SAYFA AYARLARI VE ÖZEL TASARIM (CSS)
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
st.markdown("""
""", unsafe_allow_html=True)
# 2. VERİ YÜKLEME
@st.cache_data(show_spinner=False)
def load_data():
df = pd.read_csv("gold_feature_engineered.csv")
date_col = next((col for col in df.columns if col.lower() == 'date'), df.columns[0])
df[date_col] = pd.to_datetime(df[date_col])
df['YEAR'] = df[date_col].dt.year
df = df.rename(columns={date_col: 'Date'})
return df
try:
df = load_data()
except Exception as e:
st.error(f"Veri yükleme hatası: {e}")
st.stop()
# 3. SIDEBAR
st.sidebar.markdown("
📅 Filtreler
", unsafe_allow_html=True)
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
year = st.sidebar.selectbox("Yıl Seçin", options=years_list, index=0)
filtered_df = df[df['YEAR'] == year].copy()
# 4. ANA BAŞLIK (Tam İstediğin Şekilde)
st.markdown("💰 Gold Price Intelligence / Altın Fiyat Analizi ve Stratejik Öngörü Paneli
", unsafe_allow_html=True)
st.divider()
# 📈 METRİK KARTLARI (DEVASA BOYUT)
m1, m2, m3 = st.columns(3)
with m1:
st.metric(label="Son Kapanış Fiyatı (GLD)", value=f"{filtered_df['GLD'].iloc[-1]:.2f}")
with m2:
st.metric(label=f"{year} Tepe Noktası", value=f"{filtered_df['GLD'].max():.2f}")
with m3:
st.metric(label=f"{year} Dip Noktası", value=f"{filtered_df['GLD'].min():.2f}")
st.divider()
# 5. YÖNETİCİ BİLGİ NOTU
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
info_col1, info_col2 = st.columns(2)
box_style = "padding: 20px; border-left: 8px solid #B28F2D; background-color: #F9F9F9; border-radius: 10px;"
with info_col1:
st.markdown(f"🇹🇷 {year} yılı verileri teknik analiz için uygundur.
", unsafe_allow_html=True)
with info_col2:
st.markdown(f"🇺🇸 Data for {year} is suitable for technical analysis.
", unsafe_allow_html=True)
st.divider()
# 6. GRAFİKLER (GENİŞ VE KOYU KUTULU)
st.markdown(f"## 📈 {year} Piyasa Analizi")
# ANA GRAFİK (TAM GENİŞLİK)
fig1 = go.Figure()
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
line=dict(color='#FFD700', width=3),
fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.1)'))
fig1.update_layout(template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black', height=500, margin=dict(l=20,r=20,t=20,b=20))
st.plotly_chart(fig1, use_container_width=True)
st.write("") # Boşluk
# YAN YANA GRAFİKLER (GENİŞLETİLMİŞ)
c1, c2 = st.columns(2)
with c1:
st.markdown("### 🎯 Dağılım / Distribution")
fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['#FFD700'], template="plotly_dark")
fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=450)
st.plotly_chart(fig2, use_container_width=True)
with c2:
st.markdown("### 🌡️ Korelasyon / Correlation")
num_df = filtered_df.select_dtypes(include=['number']).corr()
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd', template="plotly_dark")
fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=450)
st.plotly_chart(fig3, use_container_width=True)
st.divider()
# 7. DETAYLI VERİ SETİ (KAPALI - TIKLAYINCA AÇILIR)
with st.expander("📋 Detaylı Veri Seti / Detailed Dataset"):
st.dataframe(filtered_df, use_container_width=True)
csv = filtered_df.to_csv(index=False).encode('utf-8')
st.download_button("📥 Veriyi İndir (CSV)", data=csv, file_name=f'altin_verisi_{year}.csv')