UjjwalKGupta commited on
Commit
ec19192
·
verified ·
1 Parent(s): 487950f

Add submit button

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -140,7 +140,7 @@ st.markdown("""
140
  /* Center title */
141
  h1 {
142
  text-align: center;
143
- color: #2c3e50; /* Darker blue for headings */
144
  margin-bottom: 20px; /* Spacing below heading */
145
  }
146
 
@@ -196,6 +196,7 @@ st.markdown("""
196
 
197
  st.title("Zonal Average NDVI Trend Calculator")
198
 
 
199
  # Function to create dropdowns for date input
200
  def date_selector(label):
201
  day = st.selectbox(f"Select {label} day", list(range(1, 32)), key=f"{label}_day")
@@ -211,19 +212,21 @@ def date_selector(label):
211
  st.write("Invalid date and month !")
212
  st.stop()
213
 
214
- # Create date selectors for start date and end date
215
- (start_day, start_month), start_year = date_selector("start"), datetime.now().year
216
- (end_day, end_month), end_year = date_selector("end"), datetime.now().year
 
217
 
218
- start_date = datetime(day=start_day, month=start_month, year=start_year)
219
- end_date = datetime(day=end_day, month=end_month, year=end_year)
220
 
221
- max_cloud_cover = st.number_input("Max Cloud Cover", value=20)
222
 
223
- # Get the geojson file from the user
224
- uploaded_file = st.file_uploader("Upload KML/GeoJSON file", type=["geojson", "kml"])
 
225
 
226
- if uploaded_file is not None:
227
  try:
228
  if uploaded_file.name.endswith("kml"):
229
  gdf = gpd.read_file(BytesIO(uploaded_file.read()), driver='LIBKML')
@@ -357,14 +360,9 @@ if uploaded_file is not None:
357
  m.add_layer_control()
358
  return m
359
 
360
- # Cache the map to avoid recomputation on interaction (faster)
361
- @st.cache_resource
362
- def get_map():
363
- return create_map()
364
-
365
  # Create Folium Map object
366
- if "map" not in st.session_state:
367
- st.session_state["map"] = get_map()
368
 
369
  # Display the map and allow interactions without triggering reruns
370
  with st.container():
@@ -375,6 +373,3 @@ if uploaded_file is not None:
375
  st.write('ValueError: "Input must have single polygon geometry"')
376
  st.write(gdf)
377
  st.stop()
378
-
379
-
380
-
 
140
  /* Center title */
141
  h1 {
142
  text-align: center;
143
+ color: #FFFFFF; /* Darker blue for headings */
144
  margin-bottom: 20px; /* Spacing below heading */
145
  }
146
 
 
196
 
197
  st.title("Zonal Average NDVI Trend Calculator")
198
 
199
+ input_container = st.container()
200
  # Function to create dropdowns for date input
201
  def date_selector(label):
202
  day = st.selectbox(f"Select {label} day", list(range(1, 32)), key=f"{label}_day")
 
212
  st.write("Invalid date and month !")
213
  st.stop()
214
 
215
+ with input_container.form(key='input_form'):
216
+ # Create date selectors for start date and end date
217
+ (start_day, start_month), start_year = date_selector("start"), datetime.now().year
218
+ (end_day, end_month), end_year = date_selector("end"), datetime.now().year
219
 
220
+ start_date = datetime(day=start_day, month=start_month, year=start_year)
221
+ end_date = datetime(day=end_day, month=end_month, year=end_year)
222
 
223
+ max_cloud_cover = st.number_input("Max Cloud Cover", value=20)
224
 
225
+ # Get the geojson file from the user
226
+ uploaded_file = st.file_uploader("Upload KML/GeoJSON file", type=["geojson", "kml"])
227
+ submit_button = st.form_submit_button(label='Submit')
228
 
229
+ if uploaded_file is not None and submit_button:
230
  try:
231
  if uploaded_file.name.endswith("kml"):
232
  gdf = gpd.read_file(BytesIO(uploaded_file.read()), driver='LIBKML')
 
360
  m.add_layer_control()
361
  return m
362
 
 
 
 
 
 
363
  # Create Folium Map object
364
+ if "map" not in st.session_state or submit_button:
365
+ st.session_state["map"] = create_map()
366
 
367
  # Display the map and allow interactions without triggering reruns
368
  with st.container():
 
373
  st.write('ValueError: "Input must have single polygon geometry"')
374
  st.write(gdf)
375
  st.stop()