Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -44,13 +44,13 @@ with st.form("weather_form"):
|
|
44 |
col1, col2 = st.columns(2)
|
45 |
|
46 |
with col1:
|
47 |
-
temp = st.
|
48 |
-
humidity = st.
|
49 |
-
pressure = st.
|
50 |
|
51 |
with col2:
|
52 |
-
wind_speed = st.
|
53 |
-
wind_dir = st.
|
54 |
entry_date = st.date_input("π Entry Date", value=date.today())
|
55 |
|
56 |
rain_label = st.selectbox("π¦ Did it rain?", ["No", "Yes"])
|
@@ -85,9 +85,8 @@ if submitted:
|
|
85 |
|
86 |
# Define logic to check the rainfall
|
87 |
def warning_label(rf_prob, cat_prob):
|
88 |
-
# If average predicted probability is greater than 1 mm (we consider the threshold to be >0.5 probability for rain)
|
89 |
avg_prob = (rf_prob + cat_prob) / 2
|
90 |
-
if avg_prob > 0.5:
|
91 |
return "π§ Rain"
|
92 |
else:
|
93 |
return "βοΈ No Rain"
|
@@ -100,18 +99,26 @@ if submitted:
|
|
100 |
with col2:
|
101 |
st.metric("CatBoost", "π§ Rain" if cat_pred else "βοΈ No Rain", f"{cat_prob:.2f} probability")
|
102 |
|
103 |
-
# Calculate and display early warning level
|
104 |
st.success(f"π’ Early Warning Level: **{warning_label(rf_prob, cat_prob)}**")
|
105 |
|
106 |
-
#
|
107 |
-
if
|
|
|
|
|
|
|
|
|
108 |
st.warning("β οΈ An entry for this date already exists. Skipping dataset update.")
|
109 |
else:
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
# --- Evaluation Report ---
|
117 |
with st.expander("π Model Evaluation"):
|
|
|
44 |
col1, col2 = st.columns(2)
|
45 |
|
46 |
with col1:
|
47 |
+
temp = st.number_input("π‘ Temperature (Β°C)", min_value=0.0, max_value=60.0, value=30.0, step=0.1)
|
48 |
+
humidity = st.number_input("π§ Humidity (%)", min_value=0.0, max_value=100.0, value=60.0, step=0.1)
|
49 |
+
pressure = st.number_input("π΅ Air Pressure (kPa)", min_value=0.0, max_value=5000.0, value=1000.0, step=0.1)
|
50 |
|
51 |
with col2:
|
52 |
+
wind_speed = st.number_input("π¬ Wind Speed (m/s)", min_value=0.0, max_value=100.0, value=5.0, step=0.1)
|
53 |
+
wind_dir = st.number_input("π§ Wind Direction (Β°)", min_value=0, max_value=360, value=180, step=1)
|
54 |
entry_date = st.date_input("π Entry Date", value=date.today())
|
55 |
|
56 |
rain_label = st.selectbox("π¦ Did it rain?", ["No", "Yes"])
|
|
|
85 |
|
86 |
# Define logic to check the rainfall
|
87 |
def warning_label(rf_prob, cat_prob):
|
|
|
88 |
avg_prob = (rf_prob + cat_prob) / 2
|
89 |
+
if avg_prob > 0.5:
|
90 |
return "π§ Rain"
|
91 |
else:
|
92 |
return "βοΈ No Rain"
|
|
|
99 |
with col2:
|
100 |
st.metric("CatBoost", "π§ Rain" if cat_pred else "βοΈ No Rain", f"{cat_prob:.2f} probability")
|
101 |
|
|
|
102 |
st.success(f"π’ Early Warning Level: **{warning_label(rf_prob, cat_prob)}**")
|
103 |
|
104 |
+
# Append to dataset in memory (only during session)
|
105 |
+
if 'dataset' not in st.session_state:
|
106 |
+
st.session_state['dataset'] = pd.read_csv(DATA_PATH)
|
107 |
+
|
108 |
+
# Check for duplicates
|
109 |
+
if str(next_day) in st.session_state['dataset']["Date"].values:
|
110 |
st.warning("β οΈ An entry for this date already exists. Skipping dataset update.")
|
111 |
else:
|
112 |
+
st.session_state['dataset'] = pd.concat(
|
113 |
+
[st.session_state['dataset'], pd.DataFrame([input_row])],
|
114 |
+
ignore_index=True
|
115 |
+
)
|
116 |
+
# Save updated file (only if running locally)
|
117 |
+
try:
|
118 |
+
st.session_state['dataset'].to_csv(DATA_PATH, index=False)
|
119 |
+
st.success("β
Data added to dataset and saved locally.")
|
120 |
+
except:
|
121 |
+
st.warning("β οΈ Cannot save to file system on this platform. Data saved in session only.")
|
122 |
|
123 |
# --- Evaluation Report ---
|
124 |
with st.expander("π Model Evaluation"):
|