Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,18 +7,16 @@ import os
|
|
| 7 |
# 1. SAYFA AYARLARI
|
| 8 |
st.set_page_config(layout="wide", page_title="Gold Price Analysis")
|
| 9 |
|
| 10 |
-
# CSS:
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
.stApp { background-color: #FFFFFF; }
|
| 14 |
[data-testid="stMetricValue"] { font-size: 45px !important; font-weight: bold !important; color: #B28F2D !important; }
|
| 15 |
[data-testid="stMetricLabel"] { font-size: 18px !important; font-weight: bold !important; color: #333333 !important; }
|
| 16 |
-
.plot-container { border-radius: 10px; padding: 5px; }
|
| 17 |
</style>
|
| 18 |
""", unsafe_allow_html=True)
|
| 19 |
|
| 20 |
-
# 2. VERİ YÜKLEME
|
| 21 |
-
@st.cache_data
|
| 22 |
def load_data():
|
| 23 |
csv_files = [f for f in os.listdir('.') if f.endswith('.csv')]
|
| 24 |
if csv_files:
|
|
@@ -36,16 +34,19 @@ if df is None:
|
|
| 36 |
st.error("Veri dosyası bulunamadı!")
|
| 37 |
st.stop()
|
| 38 |
|
| 39 |
-
# 3. SIDEBAR
|
| 40 |
st.sidebar.header("📅 Filtreler / Filters")
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# 4. ANA BAŞLIK
|
| 45 |
-
st.markdown("<h1 style='text-align: center; color: #333;'>Gold Price Analysis /
|
| 46 |
st.divider()
|
| 47 |
|
| 48 |
-
# 5. YÖNETİCİ BİLGİ NOTU
|
| 49 |
st.markdown("### 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 50 |
col_tr, col_en = st.columns(2)
|
| 51 |
with col_tr:
|
|
@@ -61,7 +62,7 @@ with col_en:
|
|
| 61 |
|
| 62 |
st.divider()
|
| 63 |
|
| 64 |
-
# 6. ÖZEL METRİKLER (
|
| 65 |
m1, m2, m3 = st.columns(3)
|
| 66 |
m1.metric("Son Kapanış", f"{filtered_df['GLD'].iloc[-1]:.2f}")
|
| 67 |
m2.metric(f"{year} Zirve", f"{filtered_df['GLD'].max():.2f}")
|
|
@@ -79,37 +80,36 @@ fig1.update_layout(
|
|
| 79 |
xaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white')),
|
| 80 |
yaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white'))
|
| 81 |
)
|
| 82 |
-
st.plotly_chart(fig1, use_container_width=True)
|
| 83 |
|
| 84 |
-
#
|
| 85 |
-
st.info(f"💡 **Fiyat Trendi Analizi:** {year} yılındaki
|
| 86 |
|
| 87 |
st.divider()
|
| 88 |
|
| 89 |
-
# 8. YAN YANA GRAFİKLER
|
| 90 |
c1, c2 = st.columns(2)
|
| 91 |
|
| 92 |
with c1:
|
| 93 |
st.markdown("#### 🎯 Dağılım / Distribution")
|
| 94 |
fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['gold'], template="plotly_dark")
|
| 95 |
fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350)
|
| 96 |
-
st.plotly_chart(fig2, use_container_width=True)
|
| 97 |
-
st.
|
| 98 |
|
| 99 |
with c2:
|
| 100 |
st.markdown("#### 🌡️ Korelasyon / Correlation")
|
| 101 |
numeric_df = filtered_df.select_dtypes(include=['number']).drop(columns=['YEAR'], errors='ignore')
|
| 102 |
fig3 = px.imshow(numeric_df.corr(), text_auto=".2f", color_continuous_scale='YlOrRd', template="plotly_dark")
|
| 103 |
fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350)
|
| 104 |
-
st.plotly_chart(fig3, use_container_width=True)
|
| 105 |
-
st.
|
| 106 |
|
| 107 |
st.divider()
|
| 108 |
|
| 109 |
-
# 9. VERİ TABLOSU (Her zaman açık)
|
| 110 |
-
st.markdown("### 📋
|
| 111 |
st.dataframe(filtered_df, use_container_width=True)
|
| 112 |
|
| 113 |
-
# İndirme Butonu
|
| 114 |
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 115 |
-
st.download_button("📥
|
|
|
|
| 7 |
# 1. SAYFA AYARLARI
|
| 8 |
st.set_page_config(layout="wide", page_title="Gold Price Analysis")
|
| 9 |
|
| 10 |
+
# CSS: Tasarım Ayarları
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
.stApp { background-color: #FFFFFF; }
|
| 14 |
[data-testid="stMetricValue"] { font-size: 45px !important; font-weight: bold !important; color: #B28F2D !important; }
|
| 15 |
[data-testid="stMetricLabel"] { font-size: 18px !important; font-weight: bold !important; color: #333333 !important; }
|
|
|
|
| 16 |
</style>
|
| 17 |
""", unsafe_allow_html=True)
|
| 18 |
|
| 19 |
+
# 2. VERİ YÜKLEME (Garantili Yükleme)
|
|
|
|
| 20 |
def load_data():
|
| 21 |
csv_files = [f for f in os.listdir('.') if f.endswith('.csv')]
|
| 22 |
if csv_files:
|
|
|
|
| 34 |
st.error("Veri dosyası bulunamadı!")
|
| 35 |
st.stop()
|
| 36 |
|
| 37 |
+
# 3. SIDEBAR (Seçim Yapıldığında Sayfa Yenilenir)
|
| 38 |
st.sidebar.header("📅 Filtreler / Filters")
|
| 39 |
+
years_list = sorted(df['YEAR'].unique(), reverse=True)
|
| 40 |
+
year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=years_list, key="year_selector")
|
| 41 |
+
|
| 42 |
+
# FİLTRELEME (Grafiklerin değişmesini sağlayan kritik satır)
|
| 43 |
+
filtered_df = df[df['YEAR'] == year].copy().reset_index(drop=True)
|
| 44 |
|
| 45 |
# 4. ANA BAŞLIK
|
| 46 |
+
st.markdown(f"<h1 style='text-align: center; color: #333;'>Gold Price Analysis / {year} Analizi</h1>", unsafe_allow_html=True)
|
| 47 |
st.divider()
|
| 48 |
|
| 49 |
+
# 5. YÖNETİCİ BİLGİ NOTU (Dinamik)
|
| 50 |
st.markdown("### 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 51 |
col_tr, col_en = st.columns(2)
|
| 52 |
with col_tr:
|
|
|
|
| 62 |
|
| 63 |
st.divider()
|
| 64 |
|
| 65 |
+
# 6. ÖZEL METRİKLER (Seçilen yıla göre hesaplanır)
|
| 66 |
m1, m2, m3 = st.columns(3)
|
| 67 |
m1.metric("Son Kapanış", f"{filtered_df['GLD'].iloc[-1]:.2f}")
|
| 68 |
m2.metric(f"{year} Zirve", f"{filtered_df['GLD'].max():.2f}")
|
|
|
|
| 80 |
xaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white')),
|
| 81 |
yaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white'))
|
| 82 |
)
|
| 83 |
+
st.plotly_chart(fig1, use_container_width=True, key=f"trend_{year}")
|
| 84 |
|
| 85 |
+
# Dinamik Yorum
|
| 86 |
+
st.info(f"💡 **Fiyat Trendi Analizi:** {year} yılındaki veriler, GLD fiyatının {filtered_df['GLD'].min():.2f} ile {filtered_df['GLD'].max():.2f} bandında hareket ettiğini gösteriyor.")
|
| 87 |
|
| 88 |
st.divider()
|
| 89 |
|
| 90 |
+
# 8. YAN YANA GRAFİKLER
|
| 91 |
c1, c2 = st.columns(2)
|
| 92 |
|
| 93 |
with c1:
|
| 94 |
st.markdown("#### 🎯 Dağılım / Distribution")
|
| 95 |
fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['gold'], template="plotly_dark")
|
| 96 |
fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350)
|
| 97 |
+
st.plotly_chart(fig2, use_container_width=True, key=f"dist_{year}")
|
| 98 |
+
st.write(f"📍 **Dağılım Notu:** {year} yılındaki fiyat yoğunlaşması grafikte görülmektedir.")
|
| 99 |
|
| 100 |
with c2:
|
| 101 |
st.markdown("#### 🌡️ Korelasyon / Correlation")
|
| 102 |
numeric_df = filtered_df.select_dtypes(include=['number']).drop(columns=['YEAR'], errors='ignore')
|
| 103 |
fig3 = px.imshow(numeric_df.corr(), text_auto=".2f", color_continuous_scale='YlOrRd', template="plotly_dark")
|
| 104 |
fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350)
|
| 105 |
+
st.plotly_chart(fig3, use_container_width=True, key=f"corr_{year}")
|
| 106 |
+
st.write(f"📍 **Korelasyon Notu:** {year} yılı piyasa ilişkileri matrisi yukarıdadır.")
|
| 107 |
|
| 108 |
st.divider()
|
| 109 |
|
| 110 |
+
# 9. VERİ TABLOSU (Her zaman açık ve güncel)
|
| 111 |
+
st.markdown(f"### 📋 {year} Veri Detayları / View Data")
|
| 112 |
st.dataframe(filtered_df, use_container_width=True)
|
| 113 |
|
|
|
|
| 114 |
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 115 |
+
st.download_button(f"📥 {year} Verisini CSV Olarak İndir", data=csv, file_name=f'gold_{year}.csv')
|