sree4411 commited on
Commit
dcb0a5b
·
verified ·
1 Parent(s): ad823d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -29
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
- pipeline = pickle.load(model_file) # ✅ This is already a trained model pipeline
 
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
- # Streamlit UI
15
- st.title("🌦 Weather Type Prediction")
16
-
17
- # User Inputs
18
- Temperature = st.number_input("Enter Temperature (°C)", value=25.0)
19
- Humidity = st.number_input("Enter Humidity (%)", value=50.0)
20
- Wind_Speed = st.number_input("Enter Wind Speed (km/h)", value=10.0)
21
- Precipitation = st.number_input("Enter Precipitation (%)", value=0.0)
22
- Cloud_Cover = st.selectbox("Select Cloud Cover", ['Clear', 'Partly Cloudy', 'Overcast'])
23
- UV_Index = st.number_input("Enter UV Index", value=3)
24
- Season = st.selectbox("Select Season", ['Spring', 'Summer', 'Autumn', 'Winter'])
25
- Visibility = st.number_input("Enter Visibility (km)", value=10.0)
26
- Location = st.text_input("Enter Location", "New York")
27
-
28
- # Convert input into DataFrame
29
- input_data = pd.DataFrame([[Temperature, Humidity, Wind_Speed, Precipitation, Cloud_Cover, UV_Index, Season, Visibility, Location]],
30
- columns=['Temperature', 'Humidity', 'Wind Speed', 'Precipitation (%)',
31
- 'Cloud Cover', 'UV Index', 'Season', 'Visibility (km)', 'Location'])
32
-
33
- # Make Prediction
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  if st.button("Predict Weather Type"):
35
- prediction_numeric = pipeline.predict(input_data) # ✅ Now uses the trained pipeline
36
- predicted_label = label_encoder.inverse_transform(prediction_numeric) # Convert numeric label to original category
37
- st.success(f"🌤️ Predicted Weather Type: **{predicted_label[0]}**")
 
 
 
 
 
 
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
+