Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,115 +7,110 @@ import os
|
|
| 7 |
# 1. SAYFA AYARLARI
|
| 8 |
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
.stApp { background-color: #FFFFFF; }
|
| 14 |
[data-testid="stMetricValue"] {
|
| 15 |
-
font-size:
|
| 16 |
font-weight: 900 !important;
|
| 17 |
color: #B28F2D !important;
|
| 18 |
}
|
| 19 |
-
|
| 20 |
-
font-size: 22px !important;
|
| 21 |
-
color: #333333 !important;
|
| 22 |
-
font-weight: bold !important;
|
| 23 |
-
}
|
| 24 |
.plot-container {
|
| 25 |
-
background-color: #000000;
|
| 26 |
-
border-radius:
|
| 27 |
-
padding:
|
|
|
|
| 28 |
}
|
| 29 |
</style>
|
| 30 |
""", unsafe_allow_html=True)
|
| 31 |
|
| 32 |
-
# 2. VERİ YÜKLEME
|
| 33 |
@st.cache_data
|
| 34 |
def load_data():
|
| 35 |
-
# Klasördeki .csv uzantılı dosyaları kontrol et
|
| 36 |
csv_files = [f for f in os.listdir('.') if f.endswith('.csv')]
|
| 37 |
-
|
| 38 |
-
# Eğer dosya varsa, ilk bulduğunu yükle (Hata almamak için en güvenli yol)
|
| 39 |
if csv_files:
|
| 40 |
-
|
| 41 |
-
df = pd.read_csv(target_file)
|
| 42 |
-
|
| 43 |
-
# Tarih sütununu bul ve formatla
|
| 44 |
date_col = next((col for col in df.columns if 'date' in col.lower()), df.columns[0])
|
| 45 |
df[date_col] = pd.to_datetime(df[date_col])
|
| 46 |
df['YEAR'] = df[date_col].dt.year
|
| 47 |
df = df.rename(columns={date_col: 'Date'})
|
| 48 |
return df
|
| 49 |
-
|
| 50 |
-
return None
|
| 51 |
|
| 52 |
df = load_data()
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
st.stop()
|
| 57 |
-
|
| 58 |
-
# 3. SIDEBAR
|
| 59 |
-
st.sidebar.markdown("# 📅 Filtreler / Filters")
|
| 60 |
-
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008], reverse=True)
|
| 61 |
-
year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=years_list)
|
| 62 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
st.markdown("<h1 style='text-align: center; color: #B28F2D;'>💰 Gold Price Intelligence / Altın Fiyat Analizi ve Stratejik Öngörü Paneli</h1>", unsafe_allow_html=True)
|
| 66 |
st.divider()
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 70 |
-
col_tr, col_en = st.columns(2)
|
| 71 |
-
with col_tr:
|
| 72 |
-
st.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
|
| 73 |
-
with col_en:
|
| 74 |
-
st.success(f"### 🇺🇸 Data for {year} appears stable.")
|
| 75 |
-
|
| 76 |
-
st.divider()
|
| 77 |
-
|
| 78 |
-
# 📈 DEV METRİKLER
|
| 79 |
m1, m2, m3 = st.columns(3)
|
| 80 |
-
m1.metric("Son Kapanış
|
| 81 |
m2.metric(f"{year} Zirve", f"{filtered_df['GLD'].max():.2f}")
|
| 82 |
m3.metric(f"{year} Dip", f"{filtered_df['GLD'].min():.2f}")
|
| 83 |
|
| 84 |
st.divider()
|
| 85 |
|
| 86 |
-
#
|
| 87 |
-
st.markdown(f"## 📈 {year} Analizi / Analysis")
|
| 88 |
|
| 89 |
-
# ANA
|
|
|
|
| 90 |
fig1 = go.Figure()
|
| 91 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 92 |
-
line=dict(color='#FFD700', width=
|
| 93 |
-
fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.
|
| 94 |
-
fig1.update_layout(
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
st.plotly_chart(fig1, use_container_width=True)
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
st.plotly_chart(fig3, use_container_width=True)
|
| 114 |
|
| 115 |
st.divider()
|
| 116 |
|
| 117 |
-
#
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# 1. SAYFA AYARLARI
|
| 8 |
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
|
| 9 |
|
| 10 |
+
# CSS: Metrikler ve Konteynır Ayarları
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
.stApp { background-color: #FFFFFF; }
|
| 14 |
[data-testid="stMetricValue"] {
|
| 15 |
+
font-size: 80px !important;
|
| 16 |
font-weight: 900 !important;
|
| 17 |
color: #B28F2D !important;
|
| 18 |
}
|
| 19 |
+
/* Grafiklerin Siyah Kutusu */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
.plot-container {
|
| 21 |
+
background-color: #000000 !important;
|
| 22 |
+
border-radius: 15px;
|
| 23 |
+
padding: 25px;
|
| 24 |
+
border: 2px solid #333333;
|
| 25 |
}
|
| 26 |
</style>
|
| 27 |
""", unsafe_allow_html=True)
|
| 28 |
|
| 29 |
+
# 2. VERİ YÜKLEME
|
| 30 |
@st.cache_data
|
| 31 |
def load_data():
|
|
|
|
| 32 |
csv_files = [f for f in os.listdir('.') if f.endswith('.csv')]
|
|
|
|
|
|
|
| 33 |
if csv_files:
|
| 34 |
+
df = pd.read_csv(csv_files[0])
|
|
|
|
|
|
|
|
|
|
| 35 |
date_col = next((col for col in df.columns if 'date' in col.lower()), df.columns[0])
|
| 36 |
df[date_col] = pd.to_datetime(df[date_col])
|
| 37 |
df['YEAR'] = df[date_col].dt.year
|
| 38 |
df = df.rename(columns={date_col: 'Date'})
|
| 39 |
return df
|
| 40 |
+
return None
|
|
|
|
| 41 |
|
| 42 |
df = load_data()
|
| 43 |
|
| 44 |
+
# 3. SIDEBAR VE BAŞLIK
|
| 45 |
+
year = st.sidebar.selectbox("Yıl Seçin", options=sorted(df['YEAR'].unique(), reverse=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 47 |
|
| 48 |
+
st.markdown("<h1 style='text-align: center; color: #B28F2D;'>💰 Gold Price Intelligence / Analiz Paneli</h1>", unsafe_allow_html=True)
|
|
|
|
| 49 |
st.divider()
|
| 50 |
|
| 51 |
+
# 4. DEV METRİKLER
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
m1, m2, m3 = st.columns(3)
|
| 53 |
+
m1.metric("Son Kapanış", f"{filtered_df['GLD'].iloc[-1]:.2f}")
|
| 54 |
m2.metric(f"{year} Zirve", f"{filtered_df['GLD'].max():.2f}")
|
| 55 |
m3.metric(f"{year} Dip", f"{filtered_df['GLD'].min():.2f}")
|
| 56 |
|
| 57 |
st.divider()
|
| 58 |
|
| 59 |
+
# 5. GRAFİKLER (OKUNABİLİRLİK GARANTİLİ)
|
|
|
|
| 60 |
|
| 61 |
+
# --- ANA TREND GRAFİĞİ ---
|
| 62 |
+
st.markdown(f"### 📈 {year} Fiyat Trendi")
|
| 63 |
fig1 = go.Figure()
|
| 64 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 65 |
+
line=dict(color='#FFD700', width=5),
|
| 66 |
+
fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.15)'))
|
| 67 |
+
fig1.update_layout(
|
| 68 |
+
template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
|
| 69 |
+
height=550,
|
| 70 |
+
margin=dict(l=80, r=40, t=40, b=80),
|
| 71 |
+
xaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title=None),
|
| 72 |
+
yaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title="Fiyat (USD)", gridcolor="#333333")
|
| 73 |
+
)
|
| 74 |
st.plotly_chart(fig1, use_container_width=True)
|
| 75 |
|
| 76 |
+
st.divider()
|
| 77 |
+
|
| 78 |
+
# --- DAĞILIM GRAFİĞİ ---
|
| 79 |
+
st.markdown("### 🎯 Fiyat Dağılım Analizi")
|
| 80 |
+
fig2 = px.histogram(filtered_df, x="GLD", nbins=40,
|
| 81 |
+
color_discrete_sequence=['#FFD700'],
|
| 82 |
+
template="plotly_dark")
|
| 83 |
+
fig2.update_layout(
|
| 84 |
+
paper_bgcolor='black', plot_bgcolor='black', height=550,
|
| 85 |
+
margin=dict(l=80, r=40, t=40, b=80),
|
| 86 |
+
xaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title="GLD Fiyat Aralığı"),
|
| 87 |
+
yaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title="Gözlem Sayısı", gridcolor="#333333")
|
| 88 |
+
)
|
| 89 |
+
st.plotly_chart(fig2, use_container_width=True)
|
|
|
|
| 90 |
|
| 91 |
st.divider()
|
| 92 |
|
| 93 |
+
# --- KORELASYON MATRİSİ (ÖZEL OKUNABİLİRLİK AYARI) ---
|
| 94 |
+
st.markdown("### 🌡️ Değişken Korelasyon Matrisi")
|
| 95 |
+
numeric_cols = filtered_df.select_dtypes(include=['number']).drop(columns=['YEAR'], errors='ignore')
|
| 96 |
+
corr_df = numeric_cols.corr()
|
| 97 |
+
|
| 98 |
+
fig3 = px.imshow(corr_df,
|
| 99 |
+
text_auto=".2f",
|
| 100 |
+
color_continuous_scale='YlOrRd',
|
| 101 |
+
template="plotly_dark")
|
| 102 |
+
|
| 103 |
+
fig3.update_layout(
|
| 104 |
+
paper_bgcolor='black', plot_bgcolor='black', height=700,
|
| 105 |
+
margin=dict(l=100, r=100, t=100, b=100), # Yazıların kesilmemesi için pay bıraktık
|
| 106 |
+
xaxis=dict(tickfont=dict(size=16, color='white', family="Arial Black")),
|
| 107 |
+
yaxis=dict(tickfont=dict(size=16, color='white', family="Arial Black"))
|
| 108 |
+
)
|
| 109 |
+
# Kutuların içindeki rakamları dev gibi ve beyaz yapalım
|
| 110 |
+
fig3.update_traces(textfont=dict(size=20, color="white", family="Arial Black"))
|
| 111 |
+
|
| 112 |
+
st.plotly_chart(fig3, use_container_width=True)
|
| 113 |
+
|
| 114 |
+
# 6. VERİ SETİ
|
| 115 |
+
with st.expander("📋 Detaylı Verileri İncele"):
|
| 116 |
+
st.dataframe(filtered_df, use_container_width=True)
|