Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,24 +5,14 @@ import plotly.graph_objects as go
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
# 1. SAYFA AYARLARI
|
| 8 |
-
st.set_page_config(layout="wide", page_title="Gold
|
| 9 |
|
| 10 |
-
# CSS:
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
.stApp { background-color: #FFFFFF; }
|
| 14 |
-
[data-testid="stMetricValue"] {
|
| 15 |
-
|
| 16 |
-
font-weight: 900 !important;
|
| 17 |
-
color: #B28F2D !important;
|
| 18 |
-
}
|
| 19 |
-
/* Grafiklerin Siyah Kutusu */
|
| 20 |
-
.plot-container {
|
| 21 |
-
background-color: #000000 !important;
|
| 22 |
-
border-radius: 15px;
|
| 23 |
-
padding: 25px;
|
| 24 |
-
border: 2px solid #333333;
|
| 25 |
-
}
|
| 26 |
</style>
|
| 27 |
""", unsafe_allow_html=True)
|
| 28 |
|
|
@@ -41,76 +31,65 @@ def load_data():
|
|
| 41 |
|
| 42 |
df = load_data()
|
| 43 |
|
| 44 |
-
# 3. SIDEBAR
|
| 45 |
-
|
|
|
|
| 46 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
st.divider()
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
st.divider()
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
# --- ANA TREND GRAFİĞİ ---
|
| 62 |
-
st.markdown(f"### 📈 {year} Fiyat Trendi")
|
| 63 |
fig1 = go.Figure()
|
| 64 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 65 |
-
|
| 66 |
-
|
| 67 |
fig1.update_layout(
|
| 68 |
template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
|
| 69 |
-
height=
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
yaxis=dict(tickfont=dict(size=18, color='white', family="Arial Black"), title="Fiyat (USD)", gridcolor="#333333")
|
| 73 |
)
|
| 74 |
st.plotly_chart(fig1, use_container_width=True)
|
| 75 |
|
|
|
|
| 76 |
st.divider()
|
| 77 |
|
| 78 |
-
#
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
fig2.
|
| 84 |
-
paper_bgcolor='black', plot_bgcolor='black', height=
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
fig3 = px.imshow(corr_df,
|
| 99 |
-
text_auto=".2f",
|
| 100 |
-
color_continuous_scale='YlOrRd',
|
| 101 |
-
template="plotly_dark")
|
| 102 |
-
|
| 103 |
-
fig3.update_layout(
|
| 104 |
-
paper_bgcolor='black', plot_bgcolor='black', height=700,
|
| 105 |
-
margin=dict(l=100, r=100, t=100, b=100), # Yazıların kesilmemesi için pay bıraktık
|
| 106 |
-
xaxis=dict(tickfont=dict(size=16, color='white', family="Arial Black")),
|
| 107 |
-
yaxis=dict(tickfont=dict(size=16, color='white', family="Arial Black"))
|
| 108 |
-
)
|
| 109 |
-
# Kutuların içindeki rakamları dev gibi ve beyaz yapalım
|
| 110 |
-
fig3.update_traces(textfont=dict(size=20, color="white", family="Arial Black"))
|
| 111 |
-
|
| 112 |
-
st.plotly_chart(fig3, use_container_width=True)
|
| 113 |
-
|
| 114 |
-
# 6. VERİ SETİ
|
| 115 |
-
with st.expander("📋 Detaylı Verileri İncele"):
|
| 116 |
-
st.dataframe(filtered_df, use_container_width=True)
|
|
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
# 1. SAYFA AYARLARI
|
| 8 |
+
st.set_page_config(layout="wide", page_title="Gold Price Analysis")
|
| 9 |
|
| 10 |
+
# CSS: Sade ve Net Tasarım
|
| 11 |
st.markdown("""
|
| 12 |
<style>
|
| 13 |
.stApp { background-color: #FFFFFF; }
|
| 14 |
+
[data-testid="stMetricValue"] { font-size: 55px !important; font-weight: bold !important; color: #B28F2D !important; }
|
| 15 |
+
.plot-container { border-radius: 10px; padding: 5px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
</style>
|
| 17 |
""", unsafe_allow_html=True)
|
| 18 |
|
|
|
|
| 31 |
|
| 32 |
df = load_data()
|
| 33 |
|
| 34 |
+
# 3. SIDEBAR
|
| 35 |
+
st.sidebar.header("📅 Filtreler / Filters")
|
| 36 |
+
year = st.sidebar.selectbox("Yıl Seçin / Select Year", options=sorted(df['YEAR'].unique(), reverse=True))
|
| 37 |
filtered_df = df[df['YEAR'] == year].copy()
|
| 38 |
|
| 39 |
+
# 4. ANA BAŞLIK
|
| 40 |
+
st.markdown(f"<h1 style='text-align: center; color: #333;'>Gold Price Analysis / {year} Analizi</h1>", unsafe_allow_html=True)
|
| 41 |
st.divider()
|
| 42 |
|
| 43 |
+
# 5. YÖNETİCİ BİLGİ NOTU (Paylaştığın görseldeki gibi)
|
| 44 |
+
st.markdown("### 💼 Yönetici Bilgi Notu / Executive Summary")
|
| 45 |
+
col1, col2 = st.columns(2)
|
| 46 |
+
with col1:
|
| 47 |
+
if year == 2008:
|
| 48 |
+
st.warning("**TR:** 2008'de altın güvenli limandır, alım faydalıdır.")
|
| 49 |
+
else:
|
| 50 |
+
st.success(f"**TR:** {year} yılı verileri istikrarlı görünüyor.")
|
| 51 |
+
with col2:
|
| 52 |
+
if year == 2008:
|
| 53 |
+
st.warning("**US:** Gold is a safe haven in 2008; buying is beneficial.")
|
| 54 |
+
else:
|
| 55 |
+
st.success(f"**US:** Data for {year} appears stable.")
|
| 56 |
|
| 57 |
st.divider()
|
| 58 |
|
| 59 |
+
# 6. ANA GRAFİK (image_995583.png görselindeki gibi tek ince çizgi)
|
| 60 |
+
st.markdown(f"#### 📈 {year} Altın Fiyat Hareketi")
|
|
|
|
|
|
|
| 61 |
fig1 = go.Figure()
|
| 62 |
fig1.add_trace(go.Scatter(x=filtered_df['Date'], y=filtered_df['GLD'],
|
| 63 |
+
mode='lines',
|
| 64 |
+
line=dict(color='gold', width=2))) # İnce ve net tek çizgi
|
| 65 |
fig1.update_layout(
|
| 66 |
template="plotly_dark", paper_bgcolor='black', plot_bgcolor='black',
|
| 67 |
+
height=400, margin=dict(l=40, r=40, t=20, b=40),
|
| 68 |
+
xaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white')),
|
| 69 |
+
yaxis=dict(showgrid=True, gridcolor='#222', tickfont=dict(color='white'))
|
|
|
|
| 70 |
)
|
| 71 |
st.plotly_chart(fig1, use_container_width=True)
|
| 72 |
|
| 73 |
+
st.markdown(f"📝 *Not: Bu grafik {year} yılındaki günlük fiyat hareketlerini gösterir.*")
|
| 74 |
st.divider()
|
| 75 |
|
| 76 |
+
# 7. YAN YANA GRAFİKLER (image_98dcc5.png görselindeki gibi)
|
| 77 |
+
c1, c2 = st.columns(2)
|
| 78 |
+
|
| 79 |
+
with c1:
|
| 80 |
+
st.markdown("#### 🎯 Dağılım / Distribution")
|
| 81 |
+
fig2 = px.histogram(filtered_df, x="GLD", nbins=30, color_discrete_sequence=['gold'], template="plotly_dark")
|
| 82 |
+
fig2.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350, margin=dict(l=20,r=20,t=20,b=20))
|
| 83 |
+
st.plotly_chart(fig2, use_container_width=True)
|
| 84 |
+
|
| 85 |
+
with c2:
|
| 86 |
+
st.markdown("#### 🌡️ Korelasyon / Correlation")
|
| 87 |
+
num_df = filtered_df.select_dtypes(include=['number']).drop(columns=['YEAR'], errors='ignore')
|
| 88 |
+
fig3 = px.imshow(num_df.corr(), text_auto=".2f", color_continuous_scale='YlOrRd', template="plotly_dark")
|
| 89 |
+
fig3.update_layout(paper_bgcolor='black', plot_bgcolor='black', height=350, margin=dict(l=20,r=20,t=20,b=20))
|
| 90 |
+
st.plotly_chart(fig3, use_container_width=True)
|
| 91 |
+
|
| 92 |
+
# 8. VERİ TABLOSU (image_995886.png görselindeki gibi)
|
| 93 |
+
with st.expander("Verileri Gör / View Data"):
|
| 94 |
+
st.dataframe(filtered_df.head(), use_container_width=True)
|
| 95 |
+
st.download_button("📥 İndir / Download", data=filtered_df.to_csv(index=False), file_name=f'gold_{year}.csv')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|