ESMATUGBA commited on
Commit
33b3dfe
·
verified ·
1 Parent(s): 05eb341

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +80 -29
src/streamlit_app.py CHANGED
@@ -1,40 +1,91 @@
1
- import altair as alt
2
  import numpy as np
3
  import pandas as pd
4
- import streamlit as st
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
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 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.")