Zeel commited on
Commit
0fff812
·
1 Parent(s): a633cb2

cache data

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -12,12 +12,19 @@ file_url = st.query_params.get("file_url", None)
12
  print(f"{file_url=}")
13
 
14
  if file_url:
15
- if file_url.startswith("https://drive.google.com/file/d/"):
16
- ID = file_url.replace("https://drive.google.com/file/d/", "").split("/")[0]
17
- file_url = f"https://drive.google.com/uc?id={ID}"
 
 
 
 
18
 
19
- input_gdf = gpd.read_file(file_url)
20
- input_gdf = input_gdf.to_crs(epsg=7761) # Gujarat zone
 
 
 
21
 
22
  def format_fn(x):
23
  return input_gdf.drop(columns=["geometry"]).loc[x].to_dict()
 
12
  print(f"{file_url=}")
13
 
14
  if file_url:
15
+ if ("file_url" in st.session_state) and (st.session_state.file_url == file_url):
16
+ st.toast("Using cached data")
17
+ input_gdf = st.session_state.input_gdf
18
+ else:
19
+ if file_url.startswith("https://drive.google.com/file/d/"):
20
+ ID = file_url.replace("https://drive.google.com/file/d/", "").split("/")[0]
21
+ file_url = f"https://drive.google.com/uc?id={ID}"
22
 
23
+ input_gdf = gpd.read_file(file_url)
24
+ input_gdf = input_gdf.to_crs(epsg=7761) # Gujarat zone
25
+ st.session_state.file_url = file_url
26
+ st.session_state.input_gdf = input_gdf
27
+ st.toast("Data loaded and cached")
28
 
29
  def format_fn(x):
30
  return input_gdf.drop(columns=["geometry"]).loc[x].to_dict()