Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +80 -29
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,91 @@
|
|
| 1 |
-
import
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
-
import
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
.
|
| 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 numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import pickle
|
| 6 |
+
from keras.models import load_model
|
| 7 |
|
| 8 |
+
# 1. Sayfa Ayarları / Page Settings
|
| 9 |
+
st.set_page_config(page_title="Weather Forecast", layout="wide")
|
| 10 |
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def modeli_getir():
|
| 13 |
+
# Model ismin .keras olduğu için böyle güncelledim
|
| 14 |
+
model = load_model("lstm_traffic_model.keras")
|
| 15 |
+
return model
|
| 16 |
|
| 17 |
+
@st.cache_resource
|
| 18 |
+
def scaler_getir():
|
| 19 |
+
with open("scaler.pkl", "rb") as f:
|
| 20 |
+
return pickle.load(f)
|
| 21 |
|
| 22 |
+
model = modeli_getir()
|
| 23 |
+
olcekleyici = scaler_getir()
|
| 24 |
|
| 25 |
+
# --- SIDEBAR / YAN PANEL ---
|
| 26 |
+
st.sidebar.header("📁 CSV Format Guide / Rehber")
|
| 27 |
+
st.sidebar.info("""
|
| 28 |
+
**English:** Your file must contain the following columns in order:
|
| 29 |
+
`date`, `meantemp`, `humidity`, `wind_speed`, `meanpressure`.
|
| 30 |
|
| 31 |
+
**Türkçe:** Dosyanız şu sütunları sırasıyla içermelidir:
|
| 32 |
+
`date`, `meantemp`, `humidity`, `wind_speed`, `meanpressure`.
|
| 33 |
+
""")
|
| 34 |
|
| 35 |
+
# Senin gerçek verinden bir kesit örnek olarak
|
| 36 |
+
ornek_data = pd.DataFrame({
|
| 37 |
+
'date': ['2015-08-21', '2015-08-22'],
|
| 38 |
+
'meantemp': [29.375, 30.25],
|
| 39 |
+
'humidity': [72, 65.37],
|
| 40 |
+
'wind_speed': [8.57, 5.8],
|
| 41 |
+
'meanpressure': [1002, 1000.8]
|
| 42 |
})
|
| 43 |
+
st.sidebar.write("Example Format / Örnek Format:", ornek_data)
|
| 44 |
+
|
| 45 |
+
# --- MAIN PAGE / ANA SAYFA ---
|
| 46 |
+
st.title("🌡️ Weather Forecasting System / Hava Durumu Tahmin Sistemi")
|
| 47 |
+
st.markdown("### LSTM Network Analysis / LSTM Ağ Analizi")
|
| 48 |
+
|
| 49 |
+
# Dosya Yükleme
|
| 50 |
+
dosya = st.file_uploader("Upload your CSV file / CSV Dosyanızı Yükleyin", type=["csv"])
|
| 51 |
+
|
| 52 |
+
if dosya is not None:
|
| 53 |
+
df = pd.read_csv(dosya)
|
| 54 |
+
|
| 55 |
+
col1, col2 = st.columns(2)
|
| 56 |
+
|
| 57 |
+
with col1:
|
| 58 |
+
st.subheader("📊 Data Preview / Veri Önizleme")
|
| 59 |
+
st.write(df.head())
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
# ÖNEMLİ: Senin verinde 'meantemp' 2. kolonda (index 1)
|
| 63 |
+
# Sadece bu kolonu tahmin için seçiyoruz
|
| 64 |
+
veriler = df.iloc[:, 1:2].values
|
| 65 |
+
|
| 66 |
+
# Scale işlemi
|
| 67 |
+
olcekli_veriler = olcekleyici.transform(veriler)
|
| 68 |
+
|
| 69 |
+
# Tahmin (LSTM tahmini)
|
| 70 |
+
tahminler_scaled = model.predict(olcekli_veriler)
|
| 71 |
+
tahminler = olcekleyici.inverse_transform(tahminler_scaled)
|
| 72 |
+
|
| 73 |
+
with col2:
|
| 74 |
+
st.subheader("📈 Prediction Result / Tahmin Sonucu")
|
| 75 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 76 |
+
ax.plot(veriler, label="Actual / Gerçek", color="#e74c3c", linewidth=2)
|
| 77 |
+
ax.plot(tahminler, label="Predicted / Tahmin", color="#3498db", linestyle="--", linewidth=2)
|
| 78 |
+
ax.set_title("Temperature Forecast")
|
| 79 |
+
ax.set_ylabel("Celsius (°C)")
|
| 80 |
+
ax.legend()
|
| 81 |
+
st.pyplot(fig)
|
| 82 |
+
|
| 83 |
+
# Kutlama Balonları
|
| 84 |
+
st.balloons()
|
| 85 |
+
st.success("✅ Process Completed! / İşlem Başarıyla Tamamlandı!")
|
| 86 |
+
|
| 87 |
+
except Exception as e:
|
| 88 |
+
st.error(f"Error / Hata: {e}. Please check your column order.")
|
| 89 |
|
| 90 |
+
else:
|
| 91 |
+
st.warning("👈 Please upload a CSV file to start / Başlamak için lütfen bir CSV dosyası yükleyin.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|