ESMATUGBA commited on
Commit
88b52c1
·
verified ·
1 Parent(s): 80795a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -89
app.py CHANGED
@@ -1,90 +1,95 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
- import seaborn as sns
5
-
6
- # Sayfa Genişlik Ayarı
7
- st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
8
- plt.style.use('dark_background')
9
-
10
- # 1. VERİ YÜKLEME
11
- @st.cache_data
12
- def load_data():
13
- df = pd.read_csv("gld_price_data.csv")
14
- df['Date'] = pd.to_datetime(df['Date'])
15
- df['YEAR'] = df['Date'].dt.year
16
- return df
17
-
18
- df = load_data()
19
-
20
- # 2. SOL PANEL (SIDEBAR) - TIKLAYARAK SEÇME
21
- st.sidebar.markdown("# 📅 Filtreler / Filters")
22
- years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
23
-
24
- year = st.sidebar.selectbox(
25
- "Yıl Seçin / Select Year",
26
- options=years_list,
27
- index=0
28
- )
29
-
30
- filtered_df = df[df['YEAR'] == year]
31
-
32
- # 3. ANA BAŞLIK (BÜYÜK BOYUT)
33
- st.markdown("<h1 style='text-align: center;'>Gold Price Analysis / Altın Fiyat Analizi</h1>", unsafe_allow_html=True)
34
- st.divider()
35
-
36
- # 4. YÖNETİCİ BİLGİ NOTU (İSTEĞİN ÜZERİNE EN ÜSTTE)
37
- st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary") # ## ile başlık büyütüldü
38
- info_col1, info_col2 = st.columns(2)
39
-
40
- if year == 2008:
41
- with info_col1:
42
- st.warning("### 🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.") # Yazı boyutu büyütüldü
43
- with info_col2:
44
- st.warning("### 🇺🇸 Gold is a safe haven in 2008; buying is beneficial.")
45
- else:
46
- with info_col1:
47
- st.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
48
- with info_col2:
49
- st.success(f"### 🇺🇸 Data for {year} appears stable.")
50
-
51
- st.divider()
52
-
53
- # 5. ANA GRAFİK: ZAMAN SERİSİ (KÜÇÜLTÜLMÜŞ)
54
- st.markdown(f"## 📈 {year} Analizi / Analysis")
55
-
56
- fig1, ax1 = plt.subplots(figsize=(8, 2.5))
57
- ax1.plot(filtered_df['Date'], filtered_df['GLD'], color='gold', linewidth=1.5)
58
- ax1.fill_between(filtered_df['Date'], filtered_df['GLD'], color='gold', alpha=0.1)
59
-
60
- # Eksen ayarı
61
- y_min, y_max = filtered_df['GLD'].min(), filtered_df['GLD'].max()
62
- ax1.set_ylim(y_min * 0.98, y_max * 1.02)
63
-
64
- st.pyplot(fig1)
65
-
66
- # GRAFİK NOTU (DAHA BÜYÜK VE OKUNAKLI)
67
- st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir. / Note: This chart shows daily price movements in {year}.")
68
-
69
- st.divider()
70
-
71
- # 6. DİĞER GRAFİKLER (YAN YANA)
72
- col_left, col_right = st.columns(2)
73
-
74
- with col_left:
75
- st.markdown("### 🎯 Dağılım / Distribution")
76
- fig2, ax2 = plt.subplots(figsize=(5, 3))
77
- sns.kdeplot(x=filtered_df['GLD'], fill=True, color="orange", ax=ax2)
78
- st.pyplot(fig2)
79
-
80
- with col_right:
81
- st.markdown("### 🌡️ Korelasyon / Correlation")
82
- fig3, ax3 = plt.subplots(figsize=(5, 3))
83
- sns.heatmap(filtered_df.corr(numeric_only=True), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 7})
84
- st.pyplot(fig3)
85
-
86
- # 7. VERİ TABLOSU
87
- with st.expander("Verileri Gör / View Data"):
88
- st.dataframe(filtered_df.head(), use_container_width=True)
89
- csv = filtered_df.to_csv(index=False).encode('utf-8')
 
 
 
 
 
90
  st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+
6
+ # Sayfa Genişlik Ayarı
7
+ st.set_page_config(layout="wide", page_title="Gold Analysis Dashboard")
8
+ plt.style.use('dark_background')
9
+
10
+ # 1. VERİ YÜKLEME (Dosya ismi düzeltildi)
11
+ @st.cache_data
12
+ def load_data():
13
+ # Hugging Face'teki dosya adın tam olarak bu:
14
+ df = pd.read_csv("gold_feature_engineered.csv")
15
+ df['Date'] = pd.to_datetime(df['Date'])
16
+ df['YEAR'] = df['Date'].dt.year
17
+ return df
18
+
19
+ try:
20
+ df = load_data()
21
+ except Exception as e:
22
+ st.error(f"Dosya yükleme hatası: {e}")
23
+ st.stop()
24
+
25
+ # 2. SOL PANEL (SIDEBAR) - TIKLAYARAK SEÇME
26
+ st.sidebar.markdown("# 📅 Filtreler / Filters")
27
+ years_list = sorted([y for y in df['YEAR'].unique() if y >= 2008])
28
+
29
+ year = st.sidebar.selectbox(
30
+ "Yıl Seçin / Select Year",
31
+ options=years_list,
32
+ index=0
33
+ )
34
+
35
+ filtered_df = df[df['YEAR'] == year]
36
+
37
+ # 3. ANA BAŞLIK (BÜYÜK BOYUT)
38
+ st.markdown("<h1 style='text-align: center;'>Gold Price Analysis / Altın Fiyat Analizi</h1>", unsafe_allow_html=True)
39
+ st.divider()
40
+
41
+ # 4. YÖNETİCİ BİLGİ NOTU (EN ÜSTTE)
42
+ st.markdown("## 💼 Yönetici Bilgi Notu / Executive Summary")
43
+ info_col1, info_col2 = st.columns(2)
44
+
45
+ if year == 2008:
46
+ with info_col1:
47
+ st.warning("### 🇹🇷 2008'de altın güvenli limandır, alım faydalıdır.")
48
+ with info_col2:
49
+ st.warning("### 🇺🇸 Gold is a safe haven in 2008; buying is beneficial.")
50
+ else:
51
+ with info_col1:
52
+ st.success(f"### 🇹🇷 {year} yılı verileri istikrarlı görünüyor.")
53
+ with info_col2:
54
+ st.success(f"### 🇺🇸 Data for {year} appears stable.")
55
+
56
+ st.divider()
57
+
58
+ # 5. ANA GRAFİK: ZAMAN SERİSİ (KÜÇÜLTÜLMÜŞ)
59
+ st.markdown(f"## 📈 {year} Analizi / Analysis")
60
+
61
+ fig1, ax1 = plt.subplots(figsize=(8, 2.5))
62
+ ax1.plot(filtered_df['Date'], filtered_df['GLD'], color='gold', linewidth=1.5)
63
+ ax1.fill_between(filtered_df['Date'], filtered_df['GLD'], color='gold', alpha=0.1)
64
+
65
+ # Eksen ayarı (Basıklığı önlemek için veriye odaklanır)
66
+ y_min, y_max = filtered_df['GLD'].min(), filtered_df['GLD'].max()
67
+ ax1.set_ylim(y_min * 0.98, y_max * 1.02)
68
+
69
+ st.pyplot(fig1)
70
+
71
+ # GRAFİK NOTU
72
+ st.markdown(f"#### 📝 Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir. / Note: This chart shows daily price movements in {year}.")
73
+
74
+ st.divider()
75
+
76
+ # 6. DİĞER GRAFİKLER (YAN YANA)
77
+ col_left, col_right = st.columns(2)
78
+
79
+ with col_left:
80
+ st.markdown("### 🎯 Dağılım / Distribution")
81
+ fig2, ax2 = plt.subplots(figsize=(5, 3))
82
+ sns.kdeplot(x=filtered_df['GLD'], fill=True, color="orange", ax=ax2)
83
+ st.pyplot(fig2)
84
+
85
+ with col_right:
86
+ st.markdown("### 🌡️ Korelasyon / Correlation")
87
+ fig3, ax3 = plt.subplots(figsize=(5, 3))
88
+ sns.heatmap(filtered_df.corr(numeric_only=True), annot=True, cmap='YlOrBr', ax=ax3, annot_kws={"size": 7})
89
+ st.pyplot(fig3)
90
+
91
+ # 7. VERİ TABLOSU
92
+ with st.expander("Verileri Gör / View Data"):
93
+ st.dataframe(filtered_df.head(), use_container_width=True)
94
+ csv = filtered_df.to_csv(index=False).encode('utf-8')
95
  st.download_button("📥 İndir / Download", data=csv, file_name=f'gold_{year}.csv')