ESMATUGBA commited on
Commit
b024aa7
·
verified ·
1 Parent(s): 29382a2

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +48 -57
src/streamlit_app.py CHANGED
@@ -3,49 +3,42 @@ import pandas as pd
3
  import plotly.express as px
4
  import plotly.graph_objects as go
5
 
6
- # 1. SAYFA AYARLARI VE ÖZEL TASARIM (CSS)
7
  st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
8
 
 
9
  st.markdown("""
10
  <style>
11
- /* 1. Aydınlık Arka Plan */
12
- .stApp {
13
- background-color: #FFFFFF;
14
- }
15
 
16
- /* 2. Metrik Değerlerini Kocaman ve Kalın Yap (İsteğin Üzerine) */
17
  [data-testid="stMetricValue"] {
18
- font-size: 70px !important;
19
  font-weight: 900 !important;
20
  color: #B28F2D !important;
21
- line-height: 1.2;
22
  }
23
 
24
- /* 3. Metrik Etiketleri */
25
  [data-testid="stMetricLabel"] p {
26
- font-size: 20px !important;
27
  color: #333333 !important;
28
  font-weight: bold !important;
29
  }
30
 
31
- /* 4. GRAFİK KUTULARI (Siyah Çerçeve ve Gölge) */
32
  .plot-container {
33
  background-color: #000000;
34
- border-radius: 15px;
35
- padding: 20px;
36
- box-shadow: 0 8px 16px rgba(0,0,0,0.2);
37
- border: 1px solid #333333;
38
- }
39
-
40
- /* 5. Yazı Renklerini Sabitle */
41
- h1, h2, h3, h4, p, span {
42
- color: #1A1A1A !important;
43
  }
 
 
 
44
  </style>
45
  """, unsafe_allow_html=True)
46
 
47
  # 2. VERİ YÜKLEME
48
- @st.cache_data(show_spinner=False)
49
  def load_data():
50
  df = pd.read_csv("gold_feature_engineered.csv")
51
  date_col = next((col for col in df.columns if col.lower() == 'date'), df.columns[0])
@@ -54,76 +47,74 @@ def load_data():
54
  df = df.rename(columns={date_col: 'Date'})
55
  return df
56
 
57
- try:
58
- df = load_data()
59
- except Exception as e:
60
- st.error(f"Veri yükleme hatası: {e}")
61
- st.stop()
62
 
63
  # 3. SIDEBAR
64
- st.sidebar.markdown("<h2 style='color: #B28F2D;'>📅 Filtreler</h2>", unsafe_allow_html=True)
65
- years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
66
- year = st.sidebar.selectbox("Yıl Seçin", options=years_list, index=0)
67
  filtered_df = df[df['YEAR'] == year].copy()
68
 
69
- # 4. ANA BAŞLIK (Tam İstediğin Şekilde)
70
- st.markdown("<h1 style='text-align: center; color: #B28F2D; font-size: 42px;'>💰 Gold Price Intelligence / Altın Fiyat Analizi ve Stratejik Öngörü Paneli</h1>", unsafe_allow_html=True)
71
  st.divider()
72
 
73
- # 📈 METRİK KARTLARI (DEVASA BOYUT)
74
  m1, m2, m3 = st.columns(3)
75
  with m1:
76
  st.metric(label="Son Kapanış Fiyatı (GLD)", value=f"{filtered_df['GLD'].iloc[-1]:.2f}")
77
  with m2:
78
- st.metric(label=f"{year} Tepe Noktası", value=f"{filtered_df['GLD'].max():.2f}")
79
  with m3:
80
- st.metric(label=f"{year} Dip Noktası", value=f"{filtered_df['GLD'].min():.2f}")
81
 
82
  st.divider()
83
 
84
- # 5. YÖNETİCİ BİLGİ NOTU
85
- st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
86
- info_col1, info_col2 = st.columns(2)
87
- box_style = "padding: 20px; border-left: 8px solid #B28F2D; background-color: #F9F9F9; border-radius: 10px;"
88
- with info_col1:
89
- st.markdown(f"<div style='{box_style}'><h3>🇹🇷 {year} yılı verileri teknik analiz için uygundur.</h3></div>", unsafe_allow_html=True)
90
- with info_col2:
91
- st.markdown(f"<div style='{box_style}'><h3>🇺🇸 Data for {year} is suitable for technical analysis.</h3></div>", unsafe_allow_html=True)
92
 
93
- st.divider()
94
-
95
- # 6. GRAFİKLER (GENİŞ VE KOYU KUTULU)
96
- st.markdown(f"## 📈 {year} Piyasa Analizi")
97
-
98
- # ANA GRAFİK (TAM GENİŞLİK)
99
  fig1 = go.Figure()
100
  fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
101
  line=dict(color='#FFD700', width=3),
102
  fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.1)'))
103
- fig1.update_layout(template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black', height=500, margin=dict(l=20,r=20,t=20,b=20))
 
 
 
 
 
104
  st.plotly_chart(fig1, use_container_width=True)
105
 
106
  st.write("") # Boşluk
107
 
108
- # YAN YANA GRAFİKLER (GENİŞLETİLMİŞ)
109
  c1, c2 = st.columns(2)
 
110
  with c1:
111
  st.markdown("### 🎯 Dağılım / Distribution")
112
  fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['#FFD700'], template="plotly_dark")
113
- fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=450)
 
 
 
 
114
  st.plotly_chart(fig2, use_container_width=True)
115
 
116
  with c2:
117
  st.markdown("### 🌡️ Korelasyon / Correlation")
118
- num_df = filtered_df.select_dtypes(include=['number']).corr()
119
- fig3 = px.imshow(num_df, text_auto=True, color_continuous_scale='YlOrRd', template="plotly_dark")
120
- fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=450)
 
 
 
 
 
121
  st.plotly_chart(fig3, use_container_width=True)
122
 
123
  st.divider()
124
 
125
- # 7. DETAYLI VERİ SETİ (KAPALI - TIKLAYINCA AÇILIR)
126
- with st.expander("📋 Detaylı Veri Seti / Detailed Dataset"):
127
  st.dataframe(filtered_df, use_container_width=True)
128
  csv = filtered_df.to_csv(index=False).encode('utf-8')
129
- st.download_button("📥 Veriyi İndir (CSV)", data=csv, file_name=f'altin_verisi_{year}.csv')
 
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
+ # CSS: Rakamları devasa yapmak ve grafik kutularını netleştirmek için
10
  st.markdown("""
11
  <style>
12
+ .stApp { background-color: #FFFFFF; }
 
 
 
13
 
14
+ /* Metrik Değerleri: Kocaman ve Kalın */
15
  [data-testid="stMetricValue"] {
16
+ font-size: 75px !important;
17
  font-weight: 900 !important;
18
  color: #B28F2D !important;
 
19
  }
20
 
21
+ /* Metrik Başlıkları */
22
  [data-testid="stMetricLabel"] p {
23
+ font-size: 22px !important;
24
  color: #333333 !important;
25
  font-weight: bold !important;
26
  }
27
 
28
+ /* Grafik Kutuları: Siyah ve Net */
29
  .plot-container {
30
  background-color: #000000;
31
+ border-radius: 12px;
32
+ padding: 10px;
 
 
 
 
 
 
 
33
  }
34
+
35
+ /* Sidebar başlığı */
36
+ .css-163utfM h2 { color: #B28F2D !important; }
37
  </style>
38
  """, unsafe_allow_html=True)
39
 
40
  # 2. VERİ YÜKLEME
41
+ @st.cache_data
42
  def load_data():
43
  df = pd.read_csv("gold_feature_engineered.csv")
44
  date_col = next((col for col in df.columns if col.lower() == 'date'), df.columns[0])
 
47
  df = df.rename(columns={date_col: 'Date'})
48
  return df
49
 
50
+ df = load_data()
 
 
 
 
51
 
52
  # 3. SIDEBAR
53
+ year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=sorted(df['YEAR'].unique(), reverse=True))
 
 
54
  filtered_df = df[df['YEAR'] == year].copy()
55
 
56
+ # 4. ANA BAŞLIK
57
+ 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)
58
  st.divider()
59
 
60
+ # 5. METRİKLER (İSTEDİĞİN GİBİ BÜYÜK)
61
  m1, m2, m3 = st.columns(3)
62
  with m1:
63
  st.metric(label="Son Kapanış Fiyatı (GLD)", value=f"{filtered_df['GLD'].iloc[-1]:.2f}")
64
  with m2:
65
+ st.metric(label=f"{year} Max Fiyat", value=f"{filtered_df['GLD'].max():.2f}")
66
  with m3:
67
+ st.metric(label=f"{year} Min Fiyat", value=f"{filtered_df['GLD'].min():.2f}")
68
 
69
  st.divider()
70
 
71
+ # 6. GRAFİKLER (PAYLAŞTIĞIN GÖRSELLERLE AYNI TASARIM)
72
+ st.markdown(f"## 📈 {year} Grafik Analizleri")
 
 
 
 
 
 
73
 
74
+ # ANA GRAFİK (GENİŞ)
 
 
 
 
 
75
  fig1 = go.Figure()
76
  fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
77
  line=dict(color='#FFD700', width=3),
78
  fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.1)'))
79
+ fig1.update_layout(
80
+ template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
81
+ height=500, margin=dict(l=50, r=50, t=30, b=50),
82
+ xaxis=dict(showgrid=False, tickfont=dict(size=14, color='white')),
83
+ yaxis=dict(showgrid=True, gridcolor='#333333', tickfont=dict(size=14, color='white'))
84
+ )
85
  st.plotly_chart(fig1, use_container_width=True)
86
 
87
  st.write("") # Boşluk
88
 
89
+ # YAN YANA GRAFİKLER (OKUNABİLİR VE GENİŞ)
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=['#FFD700'], template="plotly_dark")
95
+ fig2.update_layout(
96
+ paper_bgcolor='black', plot_bgcolor='black', height=450,
97
+ xaxis=dict(tickfont=dict(color='white')),
98
+ yaxis=dict(tickfont=dict(color='white'))
99
+ )
100
  st.plotly_chart(fig2, use_container_width=True)
101
 
102
  with c2:
103
  st.markdown("### 🌡️ Korelasyon / Correlation")
104
+ # Sadece sayısal sütunlar
105
+ corr_df = filtered_df.select_dtypes(include=['number']).corr()
106
+ fig3 = px.imshow(corr_df, text_auto=".2f", color_continuous_scale='YlOrRd', template="plotly_dark")
107
+ fig3.update_layout(
108
+ paper_bgcolor='black', plot_bgcolor='black', height=450,
109
+ xaxis=dict(tickfont=dict(color='white')),
110
+ yaxis=dict(tickfont=dict(color='white'))
111
+ )
112
  st.plotly_chart(fig3, use_container_width=True)
113
 
114
  st.divider()
115
 
116
+ # 7. VERİ SETİ (KAPALI GELİR)
117
+ with st.expander("📋 Detaylı Veri Seti / Detailed Dataset (Tıkla Aç)"):
118
  st.dataframe(filtered_df, use_container_width=True)
119
  csv = filtered_df.to_csv(index=False).encode('utf-8')
120
+ st.download_button("📥 Veriyi İndir (CSV)", data=csv, file_name=f'altin_rapor_{year}.csv')