ESMATUGBA commited on
Commit
cef78e9
·
verified ·
1 Parent(s): 4d91f33

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +55 -57
src/streamlit_app.py CHANGED
@@ -1,9 +1,23 @@
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)
@@ -21,74 +35,58 @@ 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')
 
 
 
 
 
1
  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 (Geniş Ekran ve Koyu Tema)
7
+ st.set_page_config(layout="wide", page_title="Gold Intelligence Dashboard")
8
+
9
+ # Streamlit Koyu Mod Ayarı
10
+ st.markdown("""
11
+ <style>
12
+ .reportview-container {
13
+ background-color: #0E1117;
14
+ color: #E0E0E0;
15
+ }
16
+ .stHeading1, .stHeading2, .stHeading3, .stHeading4 {
17
+ color: #F8F9FA !serializable !important;
18
+ }
19
+ </style>
20
+ """, unsafe_allow_html=True)
21
 
22
  # 2. VERİ YÜKLEME
23
  @st.cache_data(show_spinner=False)
 
35
  st.error(f"Veri yükleme hatası: {e}")
36
  st.stop()
37
 
38
+ # 3. SIDEBAR (SOL PANEL - OKUNAKLI)
39
+ st.sidebar.markdown("<h2 style='color: #FFD700;'>📅 Filtreler</h2>", unsafe_allow_html=True)
40
  years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
41
  year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=years_list, index=0)
42
 
43
  filtered_df = df[df['YEAR'] == year].copy()
44
 
45
+ # 4. ANA BAŞLIK VE KARTLAR
46
+ st.markdown("<h1 style='text-align: center; color: #FFD700;'>💰 Gold Price Analysis | Altın Fiyat Analizi Dashboard</h1>", unsafe_allow_html=True)
47
  st.divider()
48
 
49
+ # KARTLAR (Executive Summary'den önce)
50
+ st.markdown("### 📊 Temel Metrikler / Key Metrics")
51
+ k1, k2, k3 = st.columns(3)
52
+ with k1:
53
+ current_price = filtered_df['GLD'].iloc[-1]
54
+ st.metric(label=f"Son Fiyat ({filtered_df['Date'].dt.date.iloc[-1]})", value=f"{current_price:.2f}", help="Yılın son işlem fiyatı")
55
+ with k2:
56
+ peak_price = filtered_df['GLD'].max()
57
+ st.metric(label=f"{year} Tepe Fiyatı", value=f"{peak_price:.2f}", help="O yılın en yüksek fiyatı")
58
+ with k3:
59
+ floor_price = filtered_df['GLD'].min()
60
+ st.metric(label=f"{year} Taban Fiyatı", value=f"{floor_price:.2f}", help="O yılın en düşük fiyatı")
 
 
 
61
 
62
  st.divider()
63
 
64
+ # 5. YÖNETİCİ BİLGİ NOTU (OKUNAKLI VE KLAS)
65
+ st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
66
+ info_col1, info_col2 = st.columns(2)
67
 
68
+ # Uyarıları renkli kartlar yerine daha "temiz" markdown kutularına aldım.
69
+ 🇹🇷_msg = "<div style='background-color: #2E3137; padding: 20px; border-left: 5px solid #FFD700; border-radius: 5px;'> <h3 style='color: #F8F9FA;'>🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.</h3> </div>"
70
+ if year != 2008:
71
+ 🇹🇷_msg = f"<div style='background-color: #2E3137; padding: 20px; border-left: 5px solid #28A745; border-radius: 5px;'> <h3 style='color: #F8F9FA;'>🇹🇷 {year} yılı verileri istikrarlı görünüyor. Fiyat hareketleri takibe değer.</h3> </div>"
 
 
 
72
 
73
+ 🇺🇸_msg = "<div style='background-color: #2E3137; padding: 20px; border-left: 5px solid #FFD700; border-radius: 5px;'> <h3 style='color: #F8F9FA;'>🇺🇸 Gold is a safe haven in 2008; buying is beneficial.</h3> </div>"
74
+ if year != 2008:
75
+ 🇺🇸_msg = f"<div style='background-color: #2E3137; padding: 20px; border-left: 5px solid #28A745; border-radius: 5px;'> <h3 style='color: #F8F9FA;'>🇺🇸 Data for {year} appears stable. Price action warrants monitoring.</h3> </div>"
76
 
77
+ with info_col1:
78
+ st.markdown(🇹🇷_msg, unsafe_allow_html=True)
79
+ with info_col2:
80
+ st.markdown(🇺🇸_msg, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  st.divider()
83
 
84
+ # 6. GRAFİKLER (KLAS RENKLER VE TİTREMESİZ PLOTLY)
85
+ st.markdown(f"## 📈 {year} Analizi / Analysis")
 
 
86
 
87
+ # Ana Grafik (Plotly Go ile daha detaylı alan grafiği)
88
+ fig1 = go.Figure()
89
+ fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
90
+ mode='lines',
91
+ line=dict(color='#FFD700', width=3),
92
+ fill='tozeroy', fillcolor='rgba(255, 215, 0, 0.1)',