Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import pickle | |
| from keras.models import load_model | |
| # 1. Sayfa Ayarları / Page Settings | |
| st.set_page_config(page_title="Weather Forecast", layout="wide") | |
| def modeli_getir(): | |
| # Model ismin .keras olduğu için böyle güncelledim | |
| model = load_model("lstm_traffic_model.keras") | |
| return model | |
| def scaler_getir(): | |
| with open("scaler.pkl", "rb") as f: | |
| return pickle.load(f) | |
| model = modeli_getir() | |
| olcekleyici = scaler_getir() | |
| # --- SIDEBAR / YAN PANEL --- | |
| st.sidebar.header("📁 CSV Format Guide / Rehber") | |
| st.sidebar.info(""" | |
| **English:** Your file must contain the following columns in order: | |
| `date`, `meantemp`, `humidity`, `wind_speed`, `meanpressure`. | |
| **Türkçe:** Dosyanız şu sütunları sırasıyla içermelidir: | |
| `date`, `meantemp`, `humidity`, `wind_speed`, `meanpressure`. | |
| """) | |
| # Senin gerçek verinden bir kesit örnek olarak | |
| ornek_data = pd.DataFrame({ | |
| 'date': ['2015-08-21', '2015-08-22'], | |
| 'meantemp': [29.375, 30.25], | |
| 'humidity': [72, 65.37], | |
| 'wind_speed': [8.57, 5.8], | |
| 'meanpressure': [1002, 1000.8] | |
| }) | |
| st.sidebar.write("Example Format / Örnek Format:", ornek_data) | |
| # --- MAIN PAGE / ANA SAYFA --- | |
| st.title("🌡️ Weather Forecasting System / Hava Durumu Tahmin Sistemi") | |
| st.markdown("### LSTM Network Analysis / LSTM Ağ Analizi") | |
| # Dosya Yükleme | |
| dosya = st.file_uploader("Upload your CSV file / CSV Dosyanızı Yükleyin", type=["csv"]) | |
| if dosya is not None: | |
| df = pd.read_csv(dosya) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.subheader("📊 Data Preview / Veri Önizleme") | |
| st.write(df.head()) | |
| try: | |
| # ÖNEMLİ: Senin verinde 'meantemp' 2. kolonda (index 1) | |
| # Sadece bu kolonu tahmin için seçiyoruz | |
| veriler = df.iloc[:, 1:2].values | |
| # Scale işlemi | |
| olcekli_veriler = olcekleyici.transform(veriler) | |
| # Tahmin (LSTM tahmini) | |
| tahminler_scaled = model.predict(olcekli_veriler) | |
| tahminler = olcekleyici.inverse_transform(tahminler_scaled) | |
| with col2: | |
| st.subheader("📈 Prediction Result / Tahmin Sonucu") | |
| fig, ax = plt.subplots(figsize=(10, 6)) | |
| ax.plot(veriler, label="Actual / Gerçek", color="#e74c3c", linewidth=2) | |
| ax.plot(tahminler, label="Predicted / Tahmin", color="#3498db", linestyle="--", linewidth=2) | |
| ax.set_title("Temperature Forecast") | |
| ax.set_ylabel("Celsius (°C)") | |
| ax.legend() | |
| st.pyplot(fig) | |
| # Kutlama Balonları | |
| st.balloons() | |
| st.success("✅ Process Completed! / İşlem Başarıyla Tamamlandı!") | |
| except Exception as e: | |
| st.error(f"Error / Hata: {e}. Please check your column order.") | |
| else: | |
| st.warning("👈 Please upload a CSV file to start / Başlamak için lütfen bir CSV dosyası yükleyin.") |