4rtemi5 commited on
Commit
b4605c3
1 Parent(s): 3418bf2

Try to add progress bar to image download.

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import io
2
  import os
3
- import requests
 
4
  import zipfile
5
  import natsort
6
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
@@ -36,8 +37,14 @@ def download_images():
36
  photo_filename = "unsplash-25k-photos.zip"
37
  if not os.path.exists(photo_filename): # Download dataset if does not exist
38
  print(f"Downloading {photo_filename}...")
39
- r = requests.get("http://sbert.net/datasets/" + photo_filename, stream=True)
40
- z = zipfile.ZipFile(io.BytesIO(r.content))
 
 
 
 
 
 
41
  print("Extracting the dataset...")
42
  z.extractall(path=img_folder)
43
  print("Done.")
@@ -46,6 +53,10 @@ def download_images():
46
  @st.cache()
47
  def get_image_features():
48
  return jnp.load("static/features/features.npy")
 
 
 
 
49
 
50
 
51
  """
@@ -54,6 +65,8 @@ def get_image_features():
54
 
55
  # CLIP Italian Demo
56
  ## HF-Flax Community Week
 
 
57
 
58
  """
59
 
@@ -90,9 +103,5 @@ if query:
90
 
91
  st.image(image_paths)
92
 
93
-
94
- def read_markdown_file(markdown_file):
95
- return Path(markdown_file).read_text()
96
-
97
  intro_markdown = read_markdown_file("readme.md")
98
  st.markdown(intro_markdown, unsafe_allow_html=True)
 
1
  import io
2
  import os
3
+ # import requests
4
+ import urllib.request
5
  import zipfile
6
  import natsort
7
  os.environ["TOKENIZERS_PARALLELISM"] = "false"
 
37
  photo_filename = "unsplash-25k-photos.zip"
38
  if not os.path.exists(photo_filename): # Download dataset if does not exist
39
  print(f"Downloading {photo_filename}...")
40
+ response = requests.get(f"http://sbert.net/datasets/{photo_filename}", stream=True)
41
+ total_size_in_bytes= int(response.headers.get('content-length', 0))
42
+ block_size = 1024 #1 Kb
43
+ progress_bar = tqdm(total=total_size_in_bytes, unit='iB', unit_scale=True)
44
+ for data in response.iter_content(block_size):
45
+ progress_bar.update(len(data))
46
+ progress_bar.close()
47
+ z = zipfile.ZipFile(io.BytesIO(response.content))
48
  print("Extracting the dataset...")
49
  z.extractall(path=img_folder)
50
  print("Done.")
 
53
  @st.cache()
54
  def get_image_features():
55
  return jnp.load("static/features/features.npy")
56
+
57
+
58
+ def read_markdown_file(markdown_file):
59
+ return Path(markdown_file).read_text()
60
 
61
 
62
  """
 
65
 
66
  # CLIP Italian Demo
67
  ## HF-Flax Community Week
68
+
69
+ In this demo you can search for images in the
70
 
71
  """
72
 
 
103
 
104
  st.image(image_paths)
105
 
 
 
 
 
106
  intro_markdown = read_markdown_file("readme.md")
107
  st.markdown(intro_markdown, unsafe_allow_html=True)