Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ st.markdown("""
|
|
| 16 |
</style>
|
| 17 |
""", unsafe_allow_html=True)
|
| 18 |
|
| 19 |
-
# 2. VERİ YÜKLEME
|
| 20 |
def load_data():
|
| 21 |
csv_files = [f for f in os.listdir('.') if f.endswith('.csv')]
|
| 22 |
if csv_files:
|
|
@@ -34,19 +34,19 @@ if df is None:
|
|
| 34 |
st.error("Veri dosyası bulunamadı!")
|
| 35 |
st.stop()
|
| 36 |
|
| 37 |
-
# 3. SIDEBAR (
|
| 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 (
|
| 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}
|
| 47 |
st.divider()
|
| 48 |
|
| 49 |
-
# 5. YÖNETİCİ BİLGİ NOTU
|
| 50 |
st.markdown("### 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 51 |
col_tr, col_en = st.columns(2)
|
| 52 |
with col_tr:
|
|
@@ -62,13 +62,13 @@ with col_en:
|
|
| 62 |
|
| 63 |
st.divider()
|
| 64 |
|
| 65 |
-
# 6. ÖZEL METRİKLER (
|
| 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}")
|
| 69 |
m3.metric(f"{year} Dip", f"{filtered_df['GLD'].min():.2f}")
|
| 70 |
|
| 71 |
-
# 7. ANA TREND GRAFİĞİ
|
| 72 |
st.markdown(f"#### 📈 {year} Altın Fiyat Trendi")
|
| 73 |
fig1 = go.Figure()
|
| 74 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
|
@@ -80,36 +80,37 @@ fig1.update_layout(
|
|
| 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"
|
| 84 |
|
| 85 |
-
# Dinamik Yorum
|
| 86 |
-
st.info(f"💡 **
|
| 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"
|
| 98 |
-
st.
|
| 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"
|
| 106 |
-
st.
|
| 107 |
|
| 108 |
st.divider()
|
| 109 |
|
| 110 |
-
# 9. VERİ TABLOSU (Her zaman açık
|
| 111 |
-
st.markdown(f"### 📋 {year} Veri
|
| 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}
|
|
|
|
| 16 |
</style>
|
| 17 |
""", unsafe_allow_html=True)
|
| 18 |
|
| 19 |
+
# 2. VERİ 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 (Yıl Seçimi)
|
| 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 (Her yıl seçildiğinde veriyi tamamen yeniler)
|
| 43 |
filtered_df = df[df['YEAR'] == year].copy().reset_index(drop=True)
|
| 44 |
|
| 45 |
+
# 4. ANA BAŞLIK (İstediğin Gibi Dinamik Yıl Eklendi)
|
| 46 |
+
st.markdown(f"<h1 style='text-align: center; color: #333;'>Gold Price Analysis / Altın Fiyat Analizi ({year})</h1>", unsafe_allow_html=True)
|
| 47 |
st.divider()
|
| 48 |
|
| 49 |
+
# 5. YÖNETİCİ BİLGİ NOTU
|
| 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 (Dinamik)
|
| 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}")
|
| 69 |
m3.metric(f"{year} Dip", f"{filtered_df['GLD'].min():.2f}")
|
| 70 |
|
| 71 |
+
# 7. ANA TREND GRAFİĞİ (Dinamik)
|
| 72 |
st.markdown(f"#### 📈 {year} Altın Fiyat Trendi")
|
| 73 |
fig1 = go.Figure()
|
| 74 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
|
|
|
| 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_graph_{year}")
|
| 84 |
|
| 85 |
+
# Grafik Altı Dinamik Yorum
|
| 86 |
+
st.info(f"💡 **Analiz Notu:** {year} yılı için en yüksek fiyat {filtered_df['GLD'].max():.2f} USD, en düşük fiyat ise {filtered_df['GLD'].min():.2f} USD olarak kaydedilmiştir.")
|
| 87 |
|
| 88 |
st.divider()
|
| 89 |
|
| 90 |
+
# 8. YAN YANA GRAFİKLER VE YORUMLARI
|
| 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_graph_{year}")
|
| 98 |
+
st.warning(f"📊 **Yorum:** {year} yılında altın fiyatlarının en yoğun olduğu bölgeler yukarıdaki histogramda gösterilmektedir.")
|
| 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_graph_{year}")
|
| 106 |
+
st.warning(f"🔗 **Yorum:** {year} yılında altının petrol, gümüş ve borsa ile olan korelasyon katsayıları hesaplanmıştır.")
|
| 107 |
|
| 108 |
st.divider()
|
| 109 |
|
| 110 |
+
# 9. VERİ TABLOSU (Her zaman açık)
|
| 111 |
+
st.markdown(f"### 📋 {year} Yılı Ham Veri Seti / View Data")
|
| 112 |
st.dataframe(filtered_df, use_container_width=True)
|
| 113 |
|
| 114 |
+
# İndirme Butonu
|
| 115 |
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 116 |
+
st.download_button(f"📥 {year} Verilerini CSV İndir", data=csv, file_name=f'gold_data_{year}.csv')
|