ESMATUGBA commited on
Commit
e460b03
·
verified ·
1 Parent(s): 8cc3ab9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -59
app.py CHANGED
@@ -6,115 +6,107 @@ import plotly.graph_objects as go
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])
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
 
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')
 
6
  # 1. SAYFA AYARLARI
7
  st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
8
 
9
+ # ÖZEL TASARIM (CSS) - Metrikleri büyütür ve sayfa ferahlığını sağlar
10
  st.markdown("""
11
  <style>
12
  .stApp { background-color: #FFFFFF; }
 
 
13
  [data-testid="stMetricValue"] {
14
+ font-size: 70px !important;
15
  font-weight: 900 !important;
16
  color: #B28F2D !important;
17
  }
 
 
18
  [data-testid="stMetricLabel"] p {
19
+ font-size: 20px !important;
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;
27
  padding: 10px;
28
  }
 
 
 
29
  </style>
30
  """, unsafe_allow_html=True)
31
 
32
  # 2. VERİ YÜKLEME
33
  @st.cache_data
34
  def load_data():
35
+ # Dosya ismini senin orijinal kodundaki gibi "gld_price_data.csv" yaptım
36
+ df = pd.read_csv("gld_price_data.csv")
37
+ df['Date'] = pd.to_datetime(df['Date'])
38
+ df['YEAR'] = df['Date'].dt.year
 
39
  return df
40
 
41
+ try:
42
+ df = load_data()
43
+ except:
44
+ st.error("Veri dosyası bulunamadı! Lütfen gld_price_data.csv dosyasının yüklü olduğundan emin olun.")
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 (Beğendiğin Kutular)
58
+ st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
59
+ info_col1, info_col2 = st.columns(2)
60
+
61
+ if year == 2008:
62
+ info_col1.warning("### 🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.")
63
+ info_col2.warning("### 🇺🇸 Gold is a safe haven in 2008; buying is beneficial.")
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 Fiyat (GLD)", f"{filtered_df['GLD'].iloc[-1]:.2f}")
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 (Titremeyi bitiren Plotly altyapısı)
79
+ st.markdown(f"## 📈 {year} Analizi / Analysis")
80
 
81
+ # ANA GRAFİK
82
  fig1 = go.Figure()
83
  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=400, margin=dict(l=20,r=20,t=20,b=20))
 
 
 
 
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
+ col_left, col_right = st.columns(2)
94
 
95
+ with col_left:
96
  st.markdown("### 🎯 Dağılım / Distribution")
97
  fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['#FFD700'], template="plotly_dark")
98
+ fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350)
 
 
 
 
99
  st.plotly_chart(fig2, use_container_width=True)
100
 
101
+ with col_right:
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=350)
 
 
 
 
 
106
  st.plotly_chart(fig3, use_container_width=True)
107
 
108
+ # 7. VERİ TABLOSU (Beğendiğin Kapalı Sistem)
109
+ with st.expander("📋 Verileri Gör / View Data"):
 
 
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')