Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +58 -66
src/streamlit_app.py
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
import
|
| 4 |
-
import seaborn as sns
|
| 5 |
|
| 6 |
-
#
|
| 7 |
st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
|
| 8 |
-
plt.style.use('dark_background')
|
| 9 |
|
| 10 |
-
#
|
| 11 |
@st.cache_data(show_spinner=False)
|
| 12 |
def load_data():
|
| 13 |
df = pd.read_csv("gold_feature_engineered.csv")
|
|
@@ -20,83 +18,77 @@ def load_data():
|
|
| 20 |
try:
|
| 21 |
df = load_data()
|
| 22 |
except Exception as e:
|
| 23 |
-
st.error(f"
|
| 24 |
st.stop()
|
| 25 |
|
| 26 |
-
#
|
| 27 |
st.sidebar.markdown("# 📅 Filtreler / Filters")
|
| 28 |
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 29 |
-
|
| 30 |
-
year = st.sidebar.selectbox(
|
| 31 |
-
"Yıl Seçin / Select Year",
|
| 32 |
-
options=years_list,
|
| 33 |
-
index=0
|
| 34 |
-
)
|
| 35 |
|
| 36 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 37 |
|
| 38 |
-
#
|
| 39 |
st.markdown("<h1 style='text-align: center;'>Gold Price Analysis / Altın Fiyat Analizi</h1>", unsafe_allow_html=True)
|
| 40 |
st.divider()
|
| 41 |
|
| 42 |
-
#
|
| 43 |
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 44 |
info_col1, info_col2 = st.columns(2)
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
st.warning("### 🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.")
|
| 49 |
-
|
| 50 |
-
st.warning("### 🇺🇸 Gold is a safe haven in 2008; buying is beneficial.")
|
| 51 |
-
else:
|
| 52 |
-
with info_col1:
|
| 53 |
st.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
st.success(f"### 🇺🇸 Data for {year} appears stable.")
|
| 56 |
|
| 57 |
st.divider()
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
# Fonksiyonu çağır
|
| 102 |
-
render_analysis(filtered_df, year)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
|
|
|
| 4 |
|
| 5 |
+
# 1. SAYFA AYARLARI
|
| 6 |
st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
|
|
|
|
| 7 |
|
| 8 |
+
# 2. VERİ YÜKLEME
|
| 9 |
@st.cache_data(show_spinner=False)
|
| 10 |
def load_data():
|
| 11 |
df = pd.read_csv("gold_feature_engineered.csv")
|
|
|
|
| 18 |
try:
|
| 19 |
df = load_data()
|
| 20 |
except Exception as e:
|
| 21 |
+
st.error(f"Veri yükleme hatası: {e}")
|
| 22 |
st.stop()
|
| 23 |
|
| 24 |
+
# 3. SIDEBAR (SOL PANEL)
|
| 25 |
st.sidebar.markdown("# 📅 Filtreler / Filters")
|
| 26 |
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 27 |
+
year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=years_list, index=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 30 |
|
| 31 |
+
# 4. ANA BAŞLIK
|
| 32 |
st.markdown("<h1 style='text-align: center;'>Gold Price Analysis / Altın Fiyat Analizi</h1>", unsafe_allow_html=True)
|
| 33 |
st.divider()
|
| 34 |
|
| 35 |
+
# 5. YÖNETİCİ BİLGİ NOTU
|
| 36 |
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 37 |
info_col1, info_col2 = st.columns(2)
|
| 38 |
|
| 39 |
+
with info_col1:
|
| 40 |
+
if year == 2008:
|
| 41 |
st.warning("### 🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.")
|
| 42 |
+
else:
|
|
|
|
|
|
|
|
|
|
| 43 |
st.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
|
| 44 |
+
|
| 45 |
+
with info_col2:
|
| 46 |
+
if year == 2008:
|
| 47 |
+
st.warning("### 🇺🇸 Gold is a safe haven in 2008; buying is beneficial.")
|
| 48 |
+
else:
|
| 49 |
st.success(f"### 🇺🇸 Data for {year} appears stable.")
|
| 50 |
|
| 51 |
st.divider()
|
| 52 |
|
| 53 |
+
# 6. GRAFİKLER (PLOTLY İLE TİTREMESİZ)
|
| 54 |
+
st.markdown(f"## 📈 {year} Analizi / Analysis")
|
| 55 |
+
|
| 56 |
+
# Ana Grafik (Plotly)
|
| 57 |
+
fig1 = px.line(filtered_df, x='Date', y='GLD',
|
| 58 |
+
title=f"{year} Altın Fiyat Hareketi",
|
| 59 |
+
color_discrete_sequence=['gold'],
|
| 60 |
+
template="plotly_dark")
|
| 61 |
+
fig1.update_layout(height=400, margin=dict(l=20, r=20, t=40, b=20))
|
| 62 |
+
st.plotly_chart(fig1, use_container_width=True)
|
| 63 |
+
|
| 64 |
+
st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir.")
|
| 65 |
+
st.divider()
|
| 66 |
+
|
| 67 |
+
# Yan Yana Grafikler
|
| 68 |
+
c1, c2 = st.columns(2)
|
| 69 |
+
|
| 70 |
+
with c1:
|
| 71 |
+
st.markdown("### 🎯 Dağılım / Distribution")
|
| 72 |
+
fig2 = px.histogram(filtered_df, x="GLD", nbins=30,
|
| 73 |
+
marginal="rug", color_discrete_sequence=['orange'],
|
| 74 |
+
template="plotly_dark")
|
| 75 |
+
fig2.update_layout(height=350)
|
| 76 |
+
st.plotly_chart(fig2, use_container_width=True)
|
| 77 |
+
|
| 78 |
+
with c2:
|
| 79 |
+
st.markdown("### 🌡️ Korelasyon / Correlation")
|
| 80 |
+
num_df = filtered_df.select_dtypes(include=['number']).corr()
|
| 81 |
+
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrBr',
|
| 82 |
+
template="plotly_dark")
|
| 83 |
+
fig3.update_layout(height=350)
|
| 84 |
+
st.plotly_chart(fig3, use_container_width=True)
|
| 85 |
+
|
| 86 |
+
st.divider()
|
| 87 |
+
|
| 88 |
+
# 7. VERİ TABLOSU (Her Zaman Açık ve Hatasız)
|
| 89 |
+
st.markdown("### 📋 Veri Tablosu / Data Table")
|
| 90 |
+
# Loglardaki width hatasını düzeltmek için width="stretch" yerine otomatik yapıya geçtik
|
| 91 |
+
st.dataframe(filtered_df.head(10), use_container_width=True)
|
| 92 |
+
|
| 93 |
+
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 94 |
+
st.download_button("📥 Veriyi İndir / Download CSV", data=csv, file_name=f'gold_{year}.csv')
|
|
|
|
|
|