mailboxlab11 commited on
Commit
09099e0
Β·
verified Β·
1 Parent(s): 19b1e91

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
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.slider("🌑 Temperature (°C)", min_value=0.0, max_value=60.0, value=30.0)
48
- humidity = st.slider("πŸ’§ Humidity (%)", min_value=0, max_value=100, value=60)
49
- pressure = st.slider("πŸ”΅ Air Pressure (kPa)", min_value=0.0, max_value=5000.0, value=1000.0) # Custom scale
50
 
51
  with col2:
52
- wind_speed = st.slider("🌬 Wind Speed (m/s)", min_value=0.0, max_value=100.0, value=5.0)
53
- wind_dir = st.slider("🧭 Wind Direction (°)", min_value=0, max_value=360, value=180)
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: # Greater than 1mm equivalent
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
- # Check for duplicates and add new entry to the dataset if needed
107
- if str(next_day) in df["Date"].values:
 
 
 
 
108
  st.warning("⚠️ An entry for this date already exists. Skipping dataset update.")
109
  else:
110
- df_new = pd.read_csv(DATA_PATH)
111
- df_new = pd.concat([df_new, pd.DataFrame([input_row])], ignore_index=True)
112
- df_new.to_csv(DATA_PATH, index=False)
113
- st.success("βœ… Data added to dataset.")
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"):