Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +49 -40
src/streamlit_app.py
CHANGED
|
@@ -2,25 +2,25 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
|
|
|
| 5 |
|
| 6 |
# 1. SAYFA AYARLARI
|
| 7 |
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
|
| 8 |
|
| 9 |
-
# ÖZEL TASARIM (CSS)
|
| 10 |
st.markdown("""
|
| 11 |
<style>
|
| 12 |
.stApp { background-color: #FFFFFF; }
|
| 13 |
[data-testid="stMetricValue"] {
|
| 14 |
-
font-size:
|
| 15 |
font-weight: 900 !important;
|
| 16 |
color: #B28F2D !important;
|
| 17 |
}
|
| 18 |
[data-testid="stMetricLabel"] p {
|
| 19 |
-
font-size:
|
| 20 |
color: #333333 !important;
|
| 21 |
font-weight: bold !important;
|
| 22 |
}
|
| 23 |
-
/* Grafiklerin siyah kutu içinde parlaması */
|
| 24 |
.plot-container {
|
| 25 |
background-color: #000000;
|
| 26 |
border-radius: 12px;
|
|
@@ -29,53 +29,61 @@ st.markdown("""
|
|
| 29 |
</style>
|
| 30 |
""", unsafe_allow_html=True)
|
| 31 |
|
| 32 |
-
# 2. VERİ YÜKLEME
|
| 33 |
@st.cache_data
|
| 34 |
def load_data():
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
st.stop()
|
| 46 |
|
| 47 |
# 3. SIDEBAR
|
| 48 |
st.sidebar.markdown("# 📅 Filtreler / Filters")
|
| 49 |
-
years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
|
| 50 |
year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=years_list)
|
| 51 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 52 |
|
| 53 |
# 4. ANA BAŞLIK
|
| 54 |
-
st.markdown("<h1 style='text-align: center; color: #B28F2D;'>💰 Gold Price Intelligence / Altın Fiyat Analizi Paneli</h1>", unsafe_allow_html=True)
|
| 55 |
st.divider()
|
| 56 |
|
| 57 |
-
# 5. YÖNETİCİ BİLGİ NOTU
|
| 58 |
st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
else:
|
| 65 |
-
info_col1.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
|
| 66 |
-
info_col2.success(f"### 🇺🇸 Data for {year} appears stable.")
|
| 67 |
|
| 68 |
st.divider()
|
| 69 |
|
| 70 |
# 📈 DEV METRİKLER
|
| 71 |
m1, m2, m3 = st.columns(3)
|
| 72 |
-
m1.metric("Son
|
| 73 |
m2.metric(f"{year} Zirve", f"{filtered_df['GLD'].max():.2f}")
|
| 74 |
m3.metric(f"{year} Dip", f"{filtered_df['GLD'].min():.2f}")
|
| 75 |
|
| 76 |
st.divider()
|
| 77 |
|
| 78 |
-
# 6. GRAFİKLER
|
| 79 |
st.markdown(f"## 📈 {year} Analizi / Analysis")
|
| 80 |
|
| 81 |
# ANA GRAFİK
|
|
@@ -84,29 +92,30 @@ fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
|
| 84 |
line=dict(color='#FFD700', width=3),
|
| 85 |
fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.1)'))
|
| 86 |
fig1.update_layout(template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
|
| 87 |
-
height=
|
|
|
|
| 88 |
st.plotly_chart(fig1, use_container_width=True)
|
| 89 |
|
| 90 |
-
st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir.")
|
| 91 |
-
|
| 92 |
# YAN YANA GRAFİKLER
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
with col_left:
|
| 96 |
st.markdown("### 🎯 Dağılım / Distribution")
|
| 97 |
-
fig2 = px.histogram(filtered_df, x="GLD",
|
| 98 |
-
fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=
|
|
|
|
| 99 |
st.plotly_chart(fig2, use_container_width=True)
|
| 100 |
|
| 101 |
-
with
|
| 102 |
st.markdown("### 🌡️ Korelasyon / Correlation")
|
| 103 |
num_df = filtered_df.select_dtypes(include=['number']).corr()
|
| 104 |
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd', template="plotly_dark")
|
| 105 |
-
fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=
|
| 106 |
st.plotly_chart(fig3, use_container_width=True)
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
st.dataframe(filtered_df, use_container_width=True)
|
| 111 |
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 112 |
st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import plotly.express as px
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# 1. SAYFA AYARLARI
|
| 8 |
st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
|
| 9 |
|
| 10 |
+
# ÖZEL TASARIM (CSS)
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
.stApp { background-color: #FFFFFF; }
|
| 14 |
[data-testid="stMetricValue"] {
|
| 15 |
+
font-size: 75px !important;
|
| 16 |
font-weight: 900 !important;
|
| 17 |
color: #B28F2D !important;
|
| 18 |
}
|
| 19 |
[data-testid="stMetricLabel"] p {
|
| 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: 12px;
|
|
|
|
| 29 |
</style>
|
| 30 |
""", unsafe_allow_html=True)
|
| 31 |
|
| 32 |
+
# 2. VERİ YÜKLEME (DOSYA ADINI OTOMATİK BULAN SİSTEM)
|
| 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 |
+
target_file = csv_files[0]
|
| 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 |
+
else:
|
| 50 |
+
return None
|
| 51 |
+
|
| 52 |
+
df = load_data()
|
| 53 |
+
|
| 54 |
+
if df is None:
|
| 55 |
+
st.error("❌ CSV dosyası bulunamadı! Lütfen dosyanızın Hugging Face'e yüklendiğinden emin olun.")
|
| 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 |
# 4. ANA BAŞLIK
|
| 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 |
+
# 5. YÖNETİCİ BİLGİ NOTU
|
| 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ış Fiyatı (GLD)", f"{filtered_df['GLD'].iloc[-1]:.2f}")
|
| 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 |
+
# 6. GRAFİKLER
|
| 87 |
st.markdown(f"## 📈 {year} Analizi / Analysis")
|
| 88 |
|
| 89 |
# ANA GRAFİK
|
|
|
|
| 92 |
line=dict(color='#FFD700', width=3),
|
| 93 |
fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.1)'))
|
| 94 |
fig1.update_layout(template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
|
| 95 |
+
height=480, margin=dict(l=30,r=30,t=20,b=30),
|
| 96 |
+
xaxis=dict(tickfont=dict(color='white')), yaxis=dict(tickfont=dict(color='white')))
|
| 97 |
st.plotly_chart(fig1, use_container_width=True)
|
| 98 |
|
|
|
|
|
|
|
| 99 |
# YAN YANA GRAFİKLER
|
| 100 |
+
c1, c2 = st.columns(2)
|
| 101 |
+
with c1:
|
|
|
|
| 102 |
st.markdown("### 🎯 Dağılım / Distribution")
|
| 103 |
+
fig2 = px.histogram(filtered_df, x="GLD", color_discrete_sequence=['#FFD700'], template="plotly_dark")
|
| 104 |
+
fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=400,
|
| 105 |
+
xaxis=dict(tickfont=dict(color='white')), yaxis=dict(tickfont=dict(color='white')))
|
| 106 |
st.plotly_chart(fig2, use_container_width=True)
|
| 107 |
|
| 108 |
+
with c2:
|
| 109 |
st.markdown("### 🌡️ Korelasyon / Correlation")
|
| 110 |
num_df = filtered_df.select_dtypes(include=['number']).corr()
|
| 111 |
fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd', template="plotly_dark")
|
| 112 |
+
fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=400)
|
| 113 |
st.plotly_chart(fig3, use_container_width=True)
|
| 114 |
|
| 115 |
+
st.divider()
|
| 116 |
+
|
| 117 |
+
# 7. VERİ TABLOSU (KAPALI GELİR)
|
| 118 |
+
with st.expander("📋 Verileri Gör / View Data (Tıklayınca Açılır)"):
|
| 119 |
st.dataframe(filtered_df, use_container_width=True)
|
| 120 |
csv = filtered_df.to_csv(index=False).encode('utf-8')
|
| 121 |
st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')
|