sree4411 commited on
Commit
ab0f28a
·
verified ·
1 Parent(s): d1a4b9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -46
app.py CHANGED
@@ -1,52 +1,42 @@
 
 
1
  import streamlit as st
2
- import pickle
3
- import numpy as np
4
  import pandas as pd
5
- import seaborn
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
 
 
 
 
16
 
 
17
  st.title("🌦️ Weather Prediction App")
18
 
19
- st.write("Enter weather details to predict the weather type.")
20
-
21
-
22
- Temperature = st.number_input("Temperature (°C)", min_value=-50, max_value=50, value=20)
23
- Humidity = st.number_input("Humidity (%)", min_value=0, max_value=100, value=50)
24
- Wind_Speed = st.number_input("Wind Speed (km/h)", min_value=0, max_value=150, value=10)
25
- Precipitation = st.number_input("Precipitation (%)", min_value=0, max_value=100, value=10)
26
- Cloud_Cover = st.selectbox("Cloud Cover", ["Clear", "Partial", "Overcast"])
27
- UV_Index = st.number_input("UV Index", min_value=0, max_value=15, value=5)
28
- Season = st.selectbox("Season", ["Winter", "Spring", "Summer", "Fall"])
29
- Visibility = st.number_input("Visibility (km)", min_value=0, max_value=50, value=10)
30
- Location = st.selectbox("Location", ["inland", "mountain", "coastal"])
31
-
32
-
33
- categorical_features = {"Cloud Cover": Cloud_Cover, "Season": Season, "Location": Location}
34
- for feature, value in categorical_features.items():
35
- categorical_features[feature] = label_encoder.transform([value])[0]
36
-
37
-
38
- input_data = np.array([[Temperature, Humidity, Wind_Speed, Precipitation,
39
- categorical_features["Cloud Cover"], UV_Index,
40
- categorical_features["Season"], Visibility,
41
- categorical_features["Location"]]])
42
-
43
-
44
- input_data_scaled = scaler.transform(input_data)
45
-
46
-
47
- if st.button("Predict Weather Type"):
48
- prediction_numeric = model.predict(input_data_scaled)[0]
49
- predicted_label = label_encoder.inverse_transform([prediction_numeric])[0]
50
-
51
- st.success(f"🌤️ Predicted Weather Type: **{predicted_label}**")
52
-
 
1
+ !pip install streamlit
2
+
3
  import streamlit as st
 
 
4
  import pandas as pd
5
+ import pickle
 
 
 
 
 
 
 
 
 
6
 
7
+ # Load the saved model
8
+ with open('weather_classifier_model.pkl', 'rb') as file:
9
+ loaded_model = pickle.load(file)
10
 
11
+ # Streamlit app
12
  st.title("🌦️ Weather Prediction App")
13
 
14
+ # Input features
15
+ temperature = st.number_input("Temperature (°C)")
16
+ humidity = st.number_input("Humidity (%)")
17
+ wind_speed = st.number_input("Wind Speed (km/h)")
18
+ cloud_cover = st.selectbox("Cloud Cover", ["Clear", "Scattered Clouds", "Partly Cloudy", "Mostly Cloudy", "Overcast"])
19
+ precipitation = st.number_input("Precipitation (%)")
20
+ uv_index = st.number_input("UV Index")
21
+ visibility = st.number_input("Visibility (km)")
22
+ season = st.selectbox("Season", ["Spring", "Summer", "Autumn", "Winter"])
23
+ location = st.selectbox("Location", ["Sydney", "Melbourne", "Brisbane", "Perth", "Adelaide", "Canberra", "Darwin", "Hobart"]) # Update with your locations
24
+
25
+
26
+ # Create input DataFrame
27
+ input_data = pd.DataFrame({
28
+ "Temperature": [temperature],
29
+ "Humidity": [humidity],
30
+ "Wind Speed": [wind_speed],
31
+ "Cloud Cover": [cloud_cover],
32
+ "Precipitation (%)": [precipitation],
33
+ "UV Index": [uv_index],
34
+ "Visibility (km)": [visibility],
35
+ "Season": [season],
36
+ "Location": [location]
37
+ })
38
+
39
+ # Make prediction
40
+ if st.button("Predict"):
41
+ prediction = loaded_model.predict(input_data)[0]
42
+ st.success(f"Predicted Weather Type: {prediction}")