Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +73 -31
src/streamlit_app.py
CHANGED
|
@@ -3,18 +3,46 @@ import pandas as pd
|
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
|
| 6 |
-
# 1. SAYFA AYARLARI
|
| 7 |
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
st.markdown("""
|
| 11 |
<style>
|
|
|
|
| 12 |
.stApp {
|
| 13 |
-
background-color: #
|
| 14 |
}
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
</style>
|
| 19 |
""", unsafe_allow_html=True)
|
| 20 |
|
|
@@ -34,46 +62,47 @@ except Exception as e:
|
|
| 34 |
st.error(f"Veri yükleme hatası: {e}")
|
| 35 |
st.stop()
|
| 36 |
|
| 37 |
-
# 3. SIDEBAR
|
| 38 |
-
st.sidebar.markdown("<h2 style='color: #
|
| 39 |
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 40 |
year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=years_list, index=0)
|
| 41 |
|
| 42 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 43 |
|
| 44 |
# 4. ANA BAŞLIK
|
| 45 |
-
st.markdown("<h1 style='text-align: center;
|
| 46 |
-
st.markdown("<p style='text-align: center; color: #
|
| 47 |
st.divider()
|
| 48 |
|
| 49 |
# METRİK KARTLARI
|
| 50 |
-
|
| 51 |
-
with
|
| 52 |
current_price = filtered_df['GLD'].iloc[-1]
|
| 53 |
st.metric(label="Son Kapanış Fiyatı", value=f"{current_price:.2f}")
|
| 54 |
-
with
|
| 55 |
st.metric(label=f"{year} Tepe Noktası", value=f"{filtered_df['GLD'].max():.2f}")
|
| 56 |
-
with
|
| 57 |
st.metric(label=f"{year} Dip Noktası", value=f"{filtered_df['GLD'].min():.2f}")
|
| 58 |
|
| 59 |
st.divider()
|
| 60 |
|
| 61 |
-
# 5. YÖNETİCİ BİLGİ NOTU (
|
| 62 |
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 63 |
info_col1, info_col2 = st.columns(2)
|
| 64 |
|
| 65 |
-
# Değişken isimlerinde emoji kullanmıyoruz, sadece metin içinde kullanıyoruz
|
| 66 |
if year == 2008:
|
| 67 |
tr_text = "🇹🇷 2008'de altın güvenli limandır, alım faydalıdır."
|
| 68 |
us_text = "🇺🇸 Gold is a safe haven in 2008; buying is beneficial."
|
| 69 |
-
|
|
|
|
| 70 |
else:
|
| 71 |
tr_text = f"🇹🇷 {year} yılı verileri istikrarlı görünüyor. Teknik analiz önerilir."
|
| 72 |
us_text = f"🇺🇸 Data for {year} appears stable. Technical analysis recommended."
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
-
tr_msg = f"<div style='background-color:
|
| 76 |
-
us_msg = f"<div style='background-color:
|
| 77 |
|
| 78 |
with info_col1:
|
| 79 |
st.markdown(tr_msg, unsafe_allow_html=True)
|
|
@@ -82,39 +111,52 @@ with info_col2:
|
|
| 82 |
|
| 83 |
st.divider()
|
| 84 |
|
| 85 |
-
# 6. GRAFİKLER
|
| 86 |
st.markdown(f"## 📈 {year} Piyasa Hareketi / Market Action")
|
| 87 |
|
|
|
|
| 88 |
fig1 = go.Figure()
|
| 89 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 90 |
mode='lines',
|
| 91 |
-
line=dict(color='#
|
| 92 |
-
fill='tozeroy', fillcolor='rgba(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
fig1.update_layout(template="plotly_dark", height=450,
|
| 95 |
-
paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)',
|
| 96 |
-
margin=dict(l=20, r=20, t=20, b=20))
|
| 97 |
st.plotly_chart(fig1, use_container_width=True)
|
| 98 |
|
| 99 |
-
#
|
|
|
|
|
|
|
|
|
|
| 100 |
c1, c2 = st.columns(2)
|
| 101 |
with c1:
|
| 102 |
st.markdown("### 🎯 Dağılım / Distribution")
|
| 103 |
-
|
| 104 |
-
fig2.
|
|
|
|
|
|
|
| 105 |
st.plotly_chart(fig2, use_container_width=True)
|
| 106 |
|
| 107 |
with c2:
|
| 108 |
st.markdown("### 🌡️ Korelasyon / Correlation")
|
|
|
|
| 109 |
num_df = filtered_df.select_dtypes(include=['number']).corr()
|
| 110 |
-
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd', template="
|
| 111 |
-
fig3.update_layout(paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)')
|
| 112 |
st.plotly_chart(fig3, use_container_width=True)
|
| 113 |
|
| 114 |
st.divider()
|
| 115 |
|
| 116 |
-
# 7. VERİ TABLOSU
|
| 117 |
st.markdown("### 📋 Detaylı Veri Seti / Detailed Dataset")
|
|
|
|
| 118 |
st.dataframe(filtered_df.head(15), use_container_width=True)
|
| 119 |
|
| 120 |
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
|
|
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
|
| 6 |
+
# 1. SAYFA AYARLARI VE ÖZEL TASARIM (CSS)
|
| 7 |
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
|
| 8 |
|
| 9 |
+
# Beyaz Tema CSS Kodları - Siyahı Bitiren Kısım
|
| 10 |
st.markdown("""
|
| 11 |
<style>
|
| 12 |
+
/* Ana Arka Planı Bembeyaz Yapalım */
|
| 13 |
.stApp {
|
| 14 |
+
background-color: #FFFFFF;
|
| 15 |
}
|
| 16 |
+
|
| 17 |
+
/* Tüm Yazıların Siyah ve Net Olmasını Sağlayalım */
|
| 18 |
+
h1, h2, h3, h4, p, span, div {
|
| 19 |
+
color: #1A1A1A !important;
|
| 20 |
}
|
| 21 |
+
|
| 22 |
+
/* Ana Başlığı Altın Sarısı Yapalım */
|
| 23 |
+
h1.main-title {
|
| 24 |
+
color: #D4AF37 !important; /* Premium Gold */
|
| 25 |
+
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
/* Metrik Kartlarını Şıklaştıralım */
|
| 29 |
+
[data-testid="stMetricValue"] {
|
| 30 |
+
color: #B28F2D !important; /* Biraz daha koyu altın sarısı */
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/* Grafikleri Çevreleyen Beyaz Alanlar */
|
| 34 |
+
.plot-container {
|
| 35 |
+
background-color: #FDFDFD;
|
| 36 |
+
border-radius: 8px;
|
| 37 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
|
| 38 |
+
padding: 10px;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* Yan Panelin Beyazlığı */
|
| 42 |
+
.css-163utfM, .css-hxt7ib {
|
| 43 |
+
background-color: #F8F9FA !important;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
</style>
|
| 47 |
""", unsafe_allow_html=True)
|
| 48 |
|
|
|
|
| 62 |
st.error(f"Veri yükleme hatası: {e}")
|
| 63 |
st.stop()
|
| 64 |
|
| 65 |
+
# 3. SIDEBAR (SOL PANEL - BEYAZ)
|
| 66 |
+
st.sidebar.markdown("<h2 style='color: #D4AF37;'>📅 Filtreler</h2>", unsafe_allow_html=True)
|
| 67 |
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 68 |
year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=years_list, index=0)
|
| 69 |
|
| 70 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 71 |
|
| 72 |
# 4. ANA BAŞLIK
|
| 73 |
+
st.markdown("<h1 class='main-title' style='text-align: center; font-size: 48px;'>💰 Gold Price Intelligence</h1>", unsafe_allow_html=True)
|
| 74 |
+
st.markdown("<p style='text-align: center; color: #4A4A4A; font-size: 18px;'>Altın Fiyat Analizi ve Stratejik Öngörü Paneli</p>", unsafe_allow_html=True)
|
| 75 |
st.divider()
|
| 76 |
|
| 77 |
# METRİK KARTLARI
|
| 78 |
+
m1, m2, m3 = st.columns(3)
|
| 79 |
+
with m1:
|
| 80 |
current_price = filtered_df['GLD'].iloc[-1]
|
| 81 |
st.metric(label="Son Kapanış Fiyatı", value=f"{current_price:.2f}")
|
| 82 |
+
with m2:
|
| 83 |
st.metric(label=f"{year} Tepe Noktası", value=f"{filtered_df['GLD'].max():.2f}")
|
| 84 |
+
with m3:
|
| 85 |
st.metric(label=f"{year} Dip Noktası", value=f"{filtered_df['GLD'].min():.2f}")
|
| 86 |
|
| 87 |
st.divider()
|
| 88 |
|
| 89 |
+
# 5. YÖNETİCİ BİLGİ NOTU (BEYAZ TEMA İÇİN YUMUŞATILMIŞ)
|
| 90 |
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 91 |
info_col1, info_col2 = st.columns(2)
|
| 92 |
|
|
|
|
| 93 |
if year == 2008:
|
| 94 |
tr_text = "🇹🇷 2008'de altın güvenli limandır, alım faydalıdır."
|
| 95 |
us_text = "🇺🇸 Gold is a safe haven in 2008; buying is beneficial."
|
| 96 |
+
box_color = "#FFF8E1" # Çok açık altın sarısı kutu
|
| 97 |
+
border_color = "#D4AF37" # Altın sarısı çizgi
|
| 98 |
else:
|
| 99 |
tr_text = f"🇹🇷 {year} yılı verileri istikrarlı görünüyor. Teknik analiz önerilir."
|
| 100 |
us_text = f"🇺🇸 Data for {year} appears stable. Technical analysis recommended."
|
| 101 |
+
box_color = "#E8F5E9" # Çok açık yeşil kutu
|
| 102 |
+
border_color = "#28A745" # Yeşil çizgi
|
| 103 |
|
| 104 |
+
tr_msg = f"<div style='background-color: {box_color}; padding: 25px; border-left: 6px solid {border_color}; border-radius: 8px;'> <h3 style='margin:0;'>{tr_text}</h3> </div>"
|
| 105 |
+
us_msg = f"<div style='background-color: {box_color}; padding: 25px; border-left: 6px solid {border_color}; border-radius: 8px;'> <h3 style='margin:0;'>{us_text}</h3> </div>"
|
| 106 |
|
| 107 |
with info_col1:
|
| 108 |
st.markdown(tr_msg, unsafe_allow_html=True)
|
|
|
|
| 111 |
|
| 112 |
st.divider()
|
| 113 |
|
| 114 |
+
# 6. GRAFİKLER (PLOTLY - LIGHT TEMA İLE TİTREMESİZ VE NET)
|
| 115 |
st.markdown(f"## 📈 {year} Piyasa Hareketi / Market Action")
|
| 116 |
|
| 117 |
+
# Ana Grafik (Plotly Go ile Alan Grafiği - Beyaz Tema)
|
| 118 |
fig1 = go.Figure()
|
| 119 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 120 |
mode='lines',
|
| 121 |
+
line=dict(color='#B28F2D', width=3), # Biraz daha koyu altın
|
| 122 |
+
fill='tozeroy', fillcolor='rgba(212, 175, 55, 0.1)')) # Çok açık altın dolgu
|
| 123 |
+
|
| 124 |
+
fig1.update_layout(template="plotly_white", height=480, # Beyaz şablon
|
| 125 |
+
title=f"{year} Altın Fiyat Grafiği | Alan Analizi",
|
| 126 |
+
xaxis_title="Tarih / Date", yaxis_title="GLD Fiyatı / Price",
|
| 127 |
+
margin=dict(l=40, r=40, t=60, b=40),
|
| 128 |
+
paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)')
|
| 129 |
+
fig1.update_xaxes(showgrid=True, gridcolor='#F0F0F0') # Hafif ızgara
|
| 130 |
+
fig1.update_yaxes(showgrid=True, gridcolor='#F0F0F0')
|
| 131 |
|
|
|
|
|
|
|
|
|
|
| 132 |
st.plotly_chart(fig1, use_container_width=True)
|
| 133 |
|
| 134 |
+
st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir.")
|
| 135 |
+
st.divider()
|
| 136 |
+
|
| 137 |
+
# ALT GRAFİKLER (YAN YANA)
|
| 138 |
c1, c2 = st.columns(2)
|
| 139 |
with c1:
|
| 140 |
st.markdown("### 🎯 Dağılım / Distribution")
|
| 141 |
+
# Histogram - Beyaz Tema
|
| 142 |
+
fig2 = px.histogram(filtered_df, x="GLD", color_discrete_sequence=['#D4AF37'], template="plotly_white")
|
| 143 |
+
fig2.update_layout(title="Fiyat Yoğunluğu / Price Density", paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)')
|
| 144 |
+
fig2.update_xaxes(showgrid=True, gridcolor='#F0F0F0')
|
| 145 |
st.plotly_chart(fig2, use_container_width=True)
|
| 146 |
|
| 147 |
with c2:
|
| 148 |
st.markdown("### 🌡️ Korelasyon / Correlation")
|
| 149 |
+
# Korelasyon Heatmap - Beyaz Tema için Renk Skalası Değişti
|
| 150 |
num_df = filtered_df.select_dtypes(include=['number']).corr()
|
| 151 |
+
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd', template="plotly_white") # Sıcak renkler
|
| 152 |
+
fig3.update_layout(title="Varlık İlişkileri / Asset Correlation", paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)')
|
| 153 |
st.plotly_chart(fig3, use_container_width=True)
|
| 154 |
|
| 155 |
st.divider()
|
| 156 |
|
| 157 |
+
# 7. VERİ TABLOSU (Her Zaman Açık, Temiz ve Net)
|
| 158 |
st.markdown("### 📋 Detaylı Veri Seti / Detailed Dataset")
|
| 159 |
+
# Beyaz modda tablo otomatik net ve okunurdur.
|
| 160 |
st.dataframe(filtered_df.head(15), use_container_width=True)
|
| 161 |
|
| 162 |
csv = filtered_df.to_csv(index=False).encode('utf-8')
|