Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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("
|
| 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
|
| 33 |
st.divider()
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
st.markdown("##
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 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 |
-
#
|
| 54 |
-
st.markdown(
|
|
|
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 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 |
-
|
| 65 |
-
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 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 |
-
#
|
| 89 |
-
st.markdown("##
|
| 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 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)',
|