Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,90 +1,95 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import matplotlib.pyplot as plt
|
| 4 |
-
import seaborn as sns
|
| 5 |
-
|
| 6 |
-
# Sayfa Genişlik Ayarı
|
| 7 |
-
st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
|
| 8 |
-
plt.style.use('dark_background')
|
| 9 |
-
|
| 10 |
-
# 1. VERİ YÜKLEME
|
| 11 |
-
@st.cache_data
|
| 12 |
-
def load_data():
|
| 13 |
-
|
| 14 |
-
df
|
| 15 |
-
df['
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
with info_col1:
|
| 47 |
-
st.
|
| 48 |
-
with info_col2:
|
| 49 |
-
st.
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
st.
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
ax1.
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
st.
|
| 70 |
-
|
| 71 |
-
#
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
#
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
|
| 6 |
+
# Sayfa Genişlik Ayarı
|
| 7 |
+
st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
|
| 8 |
+
plt.style.use('dark_background')
|
| 9 |
+
|
| 10 |
+
# 1. VERİ YÜKLEME (Dosya ismi düzeltildi)
|
| 11 |
+
@st.cache_data
|
| 12 |
+
def load_data():
|
| 13 |
+
# Hugging Face'teki dosya adın tam olarak bu:
|
| 14 |
+
df = pd.read_csv("gold_feature_engineered.csv")
|
| 15 |
+
df['Date'] = pd.to_datetime(df['Date'])
|
| 16 |
+
df['YEAR'] = df['Date'].dt.year
|
| 17 |
+
return df
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
df = load_data()
|
| 21 |
+
except Exception as e:
|
| 22 |
+
st.error(f"Dosya yükleme hatası: {e}")
|
| 23 |
+
st.stop()
|
| 24 |
+
|
| 25 |
+
# 2. SOL PANEL (SIDEBAR) - TIKLAYARAK SEÇME
|
| 26 |
+
st.sidebar.markdown("# 📅 Filtreler / Filters")
|
| 27 |
+
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 28 |
+
|
| 29 |
+
year = st.sidebar.selectbox(
|
| 30 |
+
"Yıl Seçin / Select Year",
|
| 31 |
+
options=years_list,
|
| 32 |
+
index=0
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
filtered_df = df[df['YEAR'] == year]
|
| 36 |
+
|
| 37 |
+
# 3. ANA BAŞLIK (BÜYÜK BOYUT)
|
| 38 |
+
st.markdown("<h1 style='text-align: center;'>Gold Price Analysis / Altın Fiyat Analizi</h1>", unsafe_allow_html=True)
|
| 39 |
+
st.divider()
|
| 40 |
+
|
| 41 |
+
# 4. YÖNETİCİ BİLGİ NOTU (EN ÜSTTE)
|
| 42 |
+
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 43 |
+
info_col1, info_col2 = st.columns(2)
|
| 44 |
+
|
| 45 |
+
if year == 2008:
|
| 46 |
+
with info_col1:
|
| 47 |
+
st.warning("### 🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.")
|
| 48 |
+
with info_col2:
|
| 49 |
+
st.warning("### 🇺🇸 Gold is a safe haven in 2008; buying is beneficial.")
|
| 50 |
+
else:
|
| 51 |
+
with info_col1:
|
| 52 |
+
st.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
|
| 53 |
+
with info_col2:
|
| 54 |
+
st.success(f"### 🇺🇸 Data for {year} appears stable.")
|
| 55 |
+
|
| 56 |
+
st.divider()
|
| 57 |
+
|
| 58 |
+
# 5. ANA GRAFİK: ZAMAN SERİSİ (KÜÇÜLTÜLMÜŞ)
|
| 59 |
+
st.markdown(f"## 📈 {year} Analizi / Analysis")
|
| 60 |
+
|
| 61 |
+
fig1, ax1 = plt.subplots(figsize=(8, 2.5))
|
| 62 |
+
ax1.plot(filtered_df['Date'], filtered_df['GLD'], color='gold', linewidth=1.5)
|
| 63 |
+
ax1.fill_between(filtered_df['Date'], filtered_df['GLD'], color='gold', alpha=0.1)
|
| 64 |
+
|
| 65 |
+
# Eksen ayarı (Basıklığı önlemek için veriye odaklanır)
|
| 66 |
+
y_min, y_max = filtered_df['GLD'].min(), filtered_df['GLD'].max()
|
| 67 |
+
ax1.set_ylim(y_min * 0.98, y_max * 1.02)
|
| 68 |
+
|
| 69 |
+
st.pyplot(fig1)
|
| 70 |
+
|
| 71 |
+
# GRAFİK NOTU
|
| 72 |
+
st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir. / Note: This chart shows daily price movements in {year}.")
|
| 73 |
+
|
| 74 |
+
st.divider()
|
| 75 |
+
|
| 76 |
+
# 6. DİĞER GRAFİKLER (YAN YANA)
|
| 77 |
+
col_left, col_right = st.columns(2)
|
| 78 |
+
|
| 79 |
+
with col_left:
|
| 80 |
+
st.markdown("### 🎯 Dağılım / Distribution")
|
| 81 |
+
fig2, ax2 = plt.subplots(figsize=(5, 3))
|
| 82 |
+
sns.kdeplot(x=filtered_df['GLD'], fill=True, color="orange", ax=ax2)
|
| 83 |
+
st.pyplot(fig2)
|
| 84 |
+
|
| 85 |
+
with col_right:
|
| 86 |
+
st.markdown("### 🌡️ Korelasyon / Correlation")
|
| 87 |
+
fig3, ax3 = plt.subplots(figsize=(5, 3))
|
| 88 |
+
sns.heatmap(filtered_df.corr(numeric_only=True), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 7})
|
| 89 |
+
st.pyplot(fig3)
|
| 90 |
+
|
| 91 |
+
# 7. VERİ TABLOSU
|
| 92 |
+
with st.expander("Verileri Gör / View Data"):
|
| 93 |
+
st.dataframe(filtered_df.head(), use_container_width=True)
|
| 94 |
+
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 95 |
st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')
|