Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +88 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,90 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|