ignaziogallo commited on
Commit
8e3e789
·
1 Parent(s): 5803fc9

added a button to download zip sample

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import streamlit as st
2
  import zipfile
3
  from utils import *
@@ -6,7 +8,6 @@ import matplotlib.pyplot as plt
6
  import matplotlib.animation as animation
7
  import streamlit.components.v1 as components
8
  from matplotlib import colors
9
- from huggingface_hub import hf_hub_url
10
 
11
  st.set_page_config(layout="wide")
12
 
@@ -287,19 +288,39 @@ if st.paths is not None:
287
  anim_src = load_src_images_as_animations(img_full_paths, pred_dates)
288
  components.html(anim_src.to_jshtml(), height=600)
289
 
290
- zip_url = hf_hub_url(repo_id="ARTeLab/DemoCropMapping", filename="demo_data/1509.zip")
 
 
 
 
 
 
 
 
 
 
 
 
291
  st.markdown(f"""
292
  ## Lombardia Dataset
293
  You can download other patches from the original dataset created and published on
294
  [Kaggle](https://www.kaggle.com/datasets/ignazio/sentinel2-crop-mapping) and used in our paper.
295
 
296
  ## How to build an input file for the Demo
297
- You can download this [example zip]({zip_url}) to understand
298
- how to create a new sample to feed as input to the model. A sample is a time series of sentinel-2 images,
 
 
 
 
 
 
 
 
299
  i.e. all images acquired by the satellite during a year.
300
  A zip file must contain
301
  - a geoTiff image of size _9 x 48 x 48_ for each date of the time series;
302
  - the name of each geoTif must show the date like this example "20221225.tif" which represents the date 25 December 2022;
303
  - each image must contain all sentinel-2 bands as reported in the [paper](https://www.sciencedirect.com/science/article/pii/S0924271622003203);
304
- - all the images inside the zip file must be placed inside a directory (see [example zip](demo_data/1509.zip)) where the name represents the name of the patch (for example "24"). )
305
  """)
 
1
+ import base64
2
+
3
  import streamlit as st
4
  import zipfile
5
  from utils import *
 
8
  import matplotlib.animation as animation
9
  import streamlit.components.v1 as components
10
  from matplotlib import colors
 
11
 
12
  st.set_page_config(layout="wide")
13
 
 
288
  anim_src = load_src_images_as_animations(img_full_paths, pred_dates)
289
  components.html(anim_src.to_jshtml(), height=600)
290
 
291
+ # zip_url = hf_hub_url(repo_id="ARTeLab/DemoCropMapping", filename="demo_data/1509.zip")
292
+ # with open("demo_data/1509.zip", "rb") as f:
293
+ # bytes = f.read()
294
+ # b64 = base64.b64encode(bytes).decode()
295
+ # href = f'<a href="data:file/zip;base64,{b64}" download=\'1509.zip\'>\
296
+ # Click to download\
297
+ # </a>'
298
+ # st.sidebar.markdown(href, unsafe_allow_html=True)
299
+ # download_button_str = download_button(s, filename, f'Click here to download {filename}')
300
+ # st.markdown(download_button_str, unsafe_allow_html=True)
301
+ # with open('demo_data/1509.zip') as f:
302
+ # st.download_button('Download 1509.zip', f, file_name="demo_data/1509.zip")
303
+
304
  st.markdown(f"""
305
  ## Lombardia Dataset
306
  You can download other patches from the original dataset created and published on
307
  [Kaggle](https://www.kaggle.com/datasets/ignazio/sentinel2-crop-mapping) and used in our paper.
308
 
309
  ## How to build an input file for the Demo
310
+ You can download the following zip example to better understand how to create a new sample to feed as input to the model. """)
311
+ with open("demo_data/1509.zip", "rb") as fp:
312
+ btn = st.download_button(
313
+ label="Download ZIP example",
314
+ data=fp,
315
+ file_name="1509.zip",
316
+ mime="application/octet-stream"
317
+ )
318
+ st.markdown(f"""
319
+ A sample is a time series of sentinel-2 images,
320
  i.e. all images acquired by the satellite during a year.
321
  A zip file must contain
322
  - a geoTiff image of size _9 x 48 x 48_ for each date of the time series;
323
  - the name of each geoTif must show the date like this example "20221225.tif" which represents the date 25 December 2022;
324
  - each image must contain all sentinel-2 bands as reported in the [paper](https://www.sciencedirect.com/science/article/pii/S0924271622003203);
325
+ - all the images inside the zip file must be placed inside a directory (see ZIP example) where the name represents the name of the patch (for example "24"). )
326
  """)