Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +46 -103
src/streamlit_app.py
CHANGED
|
@@ -2,65 +2,45 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
-
import numpy as np
|
| 6 |
|
| 7 |
# 1. SAYFA AYARLARI VE ÖZEL TASARIM (CSS)
|
| 8 |
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
|
| 9 |
|
| 10 |
-
# İstediğin "Aydınlık Arka Plan + Koyu Grafikler" Tasarımı için CSS
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
-
/* 1.
|
| 14 |
.stApp {
|
| 15 |
background-color: #FFFFFF;
|
| 16 |
-
color: #1A1A1A; /* Temel yazı rengi koyu */
|
| 17 |
}
|
| 18 |
|
| 19 |
-
/* 2.
|
| 20 |
-
h1.main-title {
|
| 21 |
-
color: #B28F2D !important; /* Premium Koyu Altın */
|
| 22 |
-
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
|
| 23 |
-
}
|
| 24 |
-
h2, h3, h4, p, span, div, li {
|
| 25 |
-
color: #1A1A1A !important;
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
/* 3. Metrik Değerlerini Kocaman ve Kalın Yapalım (Ferah Fondan Bağımsız) */
|
| 29 |
[data-testid="stMetricValue"] {
|
| 30 |
-
font-size:
|
| 31 |
-
font-weight: 900 !important;
|
| 32 |
-
color: #B28F2D !important;
|
| 33 |
-
|
| 34 |
}
|
| 35 |
|
| 36 |
-
/*
|
| 37 |
[data-testid="stMetricLabel"] p {
|
| 38 |
-
font-size:
|
| 39 |
-
color: #
|
| 40 |
-
|
| 41 |
}
|
| 42 |
|
| 43 |
-
/*
|
| 44 |
.plot-container {
|
| 45 |
-
background-color: #000000;
|
| 46 |
-
border-radius:
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
border:
|
| 50 |
-
margin-bottom: 20px;
|
| 51 |
}
|
| 52 |
-
|
| 53 |
-
/*
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
border-right: 1px solid #E0E0E0;
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
/* 7. Grafik İçindeki Yazıların Beyaz Kalmasını Garanti Altına Alalım */
|
| 60 |
-
.plot-container g.g-xtitle, .plot-container g.g-ytitle, .plot-container g.g-title {
|
| 61 |
-
fill: #F8F9FA !important;
|
| 62 |
}
|
| 63 |
-
|
| 64 |
</style>
|
| 65 |
""", unsafe_allow_html=True)
|
| 66 |
|
|
@@ -83,20 +63,17 @@ except Exception as e:
|
|
| 83 |
# 3. SIDEBAR
|
| 84 |
st.sidebar.markdown("<h2 style='color: #B28F2D;'>📅 Filtreler</h2>", unsafe_allow_html=True)
|
| 85 |
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 86 |
-
year = st.sidebar.selectbox("Yıl Seçin
|
| 87 |
-
|
| 88 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 89 |
|
| 90 |
-
# 4. ANA BAŞLIK
|
| 91 |
-
st.markdown("<h1
|
| 92 |
-
st.markdown("<p style='text-align: center; color: #4A4A4A;'>Altın Fiyat Analizi ve Stratejik Öngörü Paneli</p>", unsafe_allow_html=True)
|
| 93 |
st.divider()
|
| 94 |
|
| 95 |
-
# 📈 METRİK KARTLARI (
|
| 96 |
m1, m2, m3 = st.columns(3)
|
| 97 |
with m1:
|
| 98 |
-
|
| 99 |
-
st.metric(label="Son Kapanış Fiyatı (GLD)", value=f"{current_price:.2f}")
|
| 100 |
with m2:
|
| 101 |
st.metric(label=f"{year} Tepe Noktası", value=f"{filtered_df['GLD'].max():.2f}")
|
| 102 |
with m3:
|
|
@@ -104,83 +81,49 @@ with m3:
|
|
| 104 |
|
| 105 |
st.divider()
|
| 106 |
|
| 107 |
-
# 5. YÖNETİCİ BİLGİ NOTU
|
| 108 |
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 109 |
info_col1, info_col2 = st.columns(2)
|
| 110 |
-
|
| 111 |
-
if year == 2008:
|
| 112 |
-
tr_text = "🇹🇷 2008'de altın güvenli limandır, alım faydalıdır."
|
| 113 |
-
us_text = "🇺🇸 Gold is a safe haven in 2008; buying is beneficial."
|
| 114 |
-
box_color = "#FFF8E1" # Çok açık altın sarısı kutu
|
| 115 |
-
border_color = "#B28F2D" # Koyu Altın sarısı çizgi
|
| 116 |
-
else:
|
| 117 |
-
tr_text = f"🇹🇷 {year} yılı verileri istikrarlı görünüyor. Teknik analiz önerilir."
|
| 118 |
-
us_text = f"🇺🇸 Data for {year} appears stable. Technical analysis recommended."
|
| 119 |
-
box_color = "#E8F5E9" # Çok açık yeşil kutu
|
| 120 |
-
border_color = "#28A745" # Yeşil çizgi
|
| 121 |
-
|
| 122 |
-
tr_msg = f"<div style='background-color: {box_color}; padding: 25px; border-left: 6px solid {border_color}; border-radius: 8px;'> <h3 style='margin:0; color: #1A1A1A;'>{tr_text}</h3> </div>"
|
| 123 |
-
us_msg = f"<div style='background-color: {box_color}; padding: 25px; border-left: 6px solid {border_color}; border-radius: 8px;'> <h3 style='margin:0; color: #1A1A1A;'>{us_text}</h3> </div>"
|
| 124 |
-
|
| 125 |
with info_col1:
|
| 126 |
-
st.markdown(
|
| 127 |
with info_col2:
|
| 128 |
-
st.markdown(
|
| 129 |
|
| 130 |
st.divider()
|
| 131 |
|
| 132 |
-
# 6. GRAFİKLER (
|
| 133 |
-
st.markdown(f"## 📈 {year} Piyasa
|
| 134 |
|
| 135 |
-
#
|
| 136 |
fig1 = go.Figure()
|
| 137 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
fig1.update_layout(template="plotly_dark", height=480, # Koyu şablon
|
| 143 |
-
paper_bgcolor='#000000', plot_bgcolor='#000000', # Grafik içi tam siyah
|
| 144 |
-
title=f"{year} Altın Fiyat Hareketi | Alan Analizi",
|
| 145 |
-
xaxis_title="Tarih / Date", yaxis_title="GLD Fiyatı / Price",
|
| 146 |
-
margin=dict(l=40, r=40, t=60, b=40),
|
| 147 |
-
font=dict(color="#F8F9FA")) # Eksen yazıları beyaz
|
| 148 |
-
fig1.update_xaxes(showgrid=False)
|
| 149 |
-
fig1.update_yaxes(showgrid=True, gridcolor='#222222') # Çok hafif ızgara
|
| 150 |
-
|
| 151 |
st.plotly_chart(fig1, use_container_width=True)
|
| 152 |
|
| 153 |
-
st.
|
| 154 |
-
st.divider()
|
| 155 |
|
| 156 |
-
#
|
| 157 |
c1, c2 = st.columns(2)
|
| 158 |
-
|
| 159 |
with c1:
|
| 160 |
st.markdown("### 🎯 Dağılım / Distribution")
|
| 161 |
-
|
| 162 |
-
fig2
|
| 163 |
-
marginal="rug", color_discrete_sequence=['#FFD700'], # Siyah zemin üzerine sarı
|
| 164 |
-
template="plotly_dark")
|
| 165 |
-
fig2.update_layout(height=380, font=dict(color="#F8F9FA"), paper_bgcolor='#000000', plot_bgcolor='#000000')
|
| 166 |
-
fig2.update_xaxes(title="GLD Fiyatı", showgrid=False)
|
| 167 |
st.plotly_chart(fig2, use_container_width=True)
|
| 168 |
|
| 169 |
with c2:
|
| 170 |
st.markdown("### 🌡️ Korelasyon / Correlation")
|
| 171 |
-
# Heatmap (image_3.png Renkleri)
|
| 172 |
num_df = filtered_df.select_dtypes(include=['number']).corr()
|
| 173 |
-
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd',
|
| 174 |
-
|
| 175 |
-
fig3.update_layout(height=380, font=dict(color="#F8F9FA"), paper_bgcolor='#000000', plot_bgcolor='#000000')
|
| 176 |
st.plotly_chart(fig3, use_container_width=True)
|
| 177 |
|
| 178 |
st.divider()
|
| 179 |
|
| 180 |
-
# 7. VERİ
|
| 181 |
-
st.
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 186 |
-
st.download_button("📥 Raporu İndir (CSV)", data=csv, file_name=f'gold_report_{year}.csv')
|
|
|
|
| 2 |
import pandas as pd
|
| 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 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
+
/* 1. Aydınlık Arka Plan */
|
| 12 |
.stApp {
|
| 13 |
background-color: #FFFFFF;
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
+
/* 2. Metrik Değerlerini Kocaman ve Kalın Yap (İsteğin Üzerine) */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
[data-testid="stMetricValue"] {
|
| 18 |
+
font-size: 70px !important;
|
| 19 |
+
font-weight: 900 !important;
|
| 20 |
+
color: #B28F2D !important;
|
| 21 |
+
line-height: 1.2;
|
| 22 |
}
|
| 23 |
|
| 24 |
+
/* 3. Metrik Etiketleri */
|
| 25 |
[data-testid="stMetricLabel"] p {
|
| 26 |
+
font-size: 20px !important;
|
| 27 |
+
color: #333333 !important;
|
| 28 |
+
font-weight: bold !important;
|
| 29 |
}
|
| 30 |
|
| 31 |
+
/* 4. GRAFİK KUTULARI (Siyah Çerçeve ve Gölge) */
|
| 32 |
.plot-container {
|
| 33 |
+
background-color: #000000;
|
| 34 |
+
border-radius: 15px;
|
| 35 |
+
padding: 20px;
|
| 36 |
+
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
|
| 37 |
+
border: 1px solid #333333;
|
|
|
|
| 38 |
}
|
| 39 |
+
|
| 40 |
+
/* 5. Yazı Renklerini Sabitle */
|
| 41 |
+
h1, h2, h3, h4, p, span {
|
| 42 |
+
color: #1A1A1A !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
|
|
|
| 44 |
</style>
|
| 45 |
""", unsafe_allow_html=True)
|
| 46 |
|
|
|
|
| 63 |
# 3. SIDEBAR
|
| 64 |
st.sidebar.markdown("<h2 style='color: #B28F2D;'>📅 Filtreler</h2>", unsafe_allow_html=True)
|
| 65 |
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 66 |
+
year = st.sidebar.selectbox("Yıl Seçin", options=years_list, index=0)
|
|
|
|
| 67 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 68 |
|
| 69 |
+
# 4. ANA BAŞLIK (Tam İstediğin Şekilde)
|
| 70 |
+
st.markdown("<h1 style='text-align: center; color: #B28F2D; font-size: 42px;'>💰 Gold Price Intelligence / Altın Fiyat Analizi ve Stratejik Öngörü Paneli</h1>", unsafe_allow_html=True)
|
|
|
|
| 71 |
st.divider()
|
| 72 |
|
| 73 |
+
# 📈 METRİK KARTLARI (DEVASA BOYUT)
|
| 74 |
m1, m2, m3 = st.columns(3)
|
| 75 |
with m1:
|
| 76 |
+
st.metric(label="Son Kapanış Fiyatı (GLD)", value=f"{filtered_df['GLD'].iloc[-1]:.2f}")
|
|
|
|
| 77 |
with m2:
|
| 78 |
st.metric(label=f"{year} Tepe Noktası", value=f"{filtered_df['GLD'].max():.2f}")
|
| 79 |
with m3:
|
|
|
|
| 81 |
|
| 82 |
st.divider()
|
| 83 |
|
| 84 |
+
# 5. YÖNETİCİ BİLGİ NOTU
|
| 85 |
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 86 |
info_col1, info_col2 = st.columns(2)
|
| 87 |
+
box_style = "padding: 20px; border-left: 8px solid #B28F2D; background-color: #F9F9F9; border-radius: 10px;"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
with info_col1:
|
| 89 |
+
st.markdown(f"<div style='{box_style}'><h3>🇹🇷 {year} yılı verileri teknik analiz için uygundur.</h3></div>", unsafe_allow_html=True)
|
| 90 |
with info_col2:
|
| 91 |
+
st.markdown(f"<div style='{box_style}'><h3>🇺🇸 Data for {year} is suitable for technical analysis.</h3></div>", unsafe_allow_html=True)
|
| 92 |
|
| 93 |
st.divider()
|
| 94 |
|
| 95 |
+
# 6. GRAFİKLER (GENİŞ VE KOYU KUTULU)
|
| 96 |
+
st.markdown(f"## 📈 {year} Piyasa Analizi")
|
| 97 |
|
| 98 |
+
# ANA GRAFİK (TAM GENİŞLİK)
|
| 99 |
fig1 = go.Figure()
|
| 100 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 101 |
+
line=dict(color='#FFD700', width=3),
|
| 102 |
+
fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.1)'))
|
| 103 |
+
fig1.update_layout(template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black', height=500, margin=dict(l=20,r=20,t=20,b=20))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
st.plotly_chart(fig1, use_container_width=True)
|
| 105 |
|
| 106 |
+
st.write("") # Boşluk
|
|
|
|
| 107 |
|
| 108 |
+
# YAN YANA GRAFİKLER (GENİŞLETİLMİŞ)
|
| 109 |
c1, c2 = st.columns(2)
|
|
|
|
| 110 |
with c1:
|
| 111 |
st.markdown("### 🎯 Dağılım / Distribution")
|
| 112 |
+
fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['#FFD700'], template="plotly_dark")
|
| 113 |
+
fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=450)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
st.plotly_chart(fig2, use_container_width=True)
|
| 115 |
|
| 116 |
with c2:
|
| 117 |
st.markdown("### 🌡️ Korelasyon / Correlation")
|
|
|
|
| 118 |
num_df = filtered_df.select_dtypes(include=['number']).corr()
|
| 119 |
+
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd', template="plotly_dark")
|
| 120 |
+
fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=450)
|
|
|
|
| 121 |
st.plotly_chart(fig3, use_container_width=True)
|
| 122 |
|
| 123 |
st.divider()
|
| 124 |
|
| 125 |
+
# 7. DETAYLI VERİ SETİ (KAPALI - TIKLAYINCA AÇILIR)
|
| 126 |
+
with st.expander("📋 Detaylı Veri Seti / Detailed Dataset"):
|
| 127 |
+
st.dataframe(filtered_df, use_container_width=True)
|
| 128 |
+
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 129 |
+
st.download_button("📥 Veriyi İndir (CSV)", data=csv, file_name=f'altin_verisi_{year}.csv')
|
|
|
|
|
|