Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,54 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pickle
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
# Load the trained model pipeline (includes preprocessing + classifier)
|
| 7 |
with open("weather_classification_model.pkl", "rb") as model_file:
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
# Load the Label Encoder
|
| 11 |
with open("label_encoder.pkl", "rb") as encoder_file:
|
| 12 |
label_encoder = pickle.load(encoder_file)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
if st.button("Predict Weather Type"):
|
| 35 |
-
prediction_numeric =
|
| 36 |
-
predicted_label = label_encoder.inverse_transform(prediction_numeric)
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
|
|
|
|
| 7 |
with open("weather_classification_model.pkl", "rb") as model_file:
|
| 8 |
+
model = pickle.load(model_file)
|
| 9 |
+
|
| 10 |
|
|
|
|
| 11 |
with open("label_encoder.pkl", "rb") as encoder_file:
|
| 12 |
label_encoder = pickle.load(encoder_file)
|
| 13 |
|
| 14 |
+
|
| 15 |
+
with open("scaler.pkl", "rb") as scaler_file:
|
| 16 |
+
scaler = pickle.load(scaler_file)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
st.title("🌦️ Weather Prediction App")
|
| 20 |
+
|
| 21 |
+
st.write("Enter weather details to predict the weather type.")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
Temperature = st.number_input("Temperature (°C)", min_value=-50, max_value=50, value=20)
|
| 25 |
+
Humidity = st.number_input("Humidity (%)", min_value=0, max_value=100, value=50)
|
| 26 |
+
Wind_Speed = st.number_input("Wind Speed (km/h)", min_value=0, max_value=150, value=10)
|
| 27 |
+
Precipitation = st.number_input("Precipitation (%)", min_value=0, max_value=100, value=10)
|
| 28 |
+
Cloud_Cover = st.selectbox("Cloud Cover", ["Clear", "Partial", "Overcast"])
|
| 29 |
+
UV_Index = st.number_input("UV Index", min_value=0, max_value=15, value=5)
|
| 30 |
+
Season = st.selectbox("Season", ["Winter", "Spring", "Summer", "Fall"])
|
| 31 |
+
Visibility = st.number_input("Visibility (km)", min_value=0, max_value=50, value=10)
|
| 32 |
+
Location = st.selectbox("Location", ["inland", "mountain", "coastal"])
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
categorical_features = {"Cloud Cover": Cloud_Cover, "Season": Season, "Location": Location}
|
| 36 |
+
for feature, value in categorical_features.items():
|
| 37 |
+
categorical_features[feature] = label_encoder.transform([value])[0]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
input_data = np.array([[Temperature, Humidity, Wind_Speed, Precipitation,
|
| 41 |
+
categorical_features["Cloud Cover"], UV_Index,
|
| 42 |
+
categorical_features["Season"], Visibility,
|
| 43 |
+
categorical_features["Location"]]])
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
input_data_scaled = scaler.transform(input_data)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
if st.button("Predict Weather Type"):
|
| 50 |
+
prediction_numeric = model.predict(input_data_scaled)[0]
|
| 51 |
+
predicted_label = label_encoder.inverse_transform([prediction_numeric])[0]
|
| 52 |
+
|
| 53 |
+
st.success(f"🌤️ Predicted Weather Type: **{predicted_label}**")
|
| 54 |
+
|